Changeset - cd99f9b81da2
[Not reviewed]
gain-offset
0 3 0
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-07-08 05:50:12
hy@ozderya.net
preliminary implementation of gain and offset
3 files changed with 40 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -109,24 +109,44 @@ QString ChannelInfoModel::name(unsigned 
 
}
 

	
 
QColor ChannelInfoModel::color(unsigned i) const
 
{
 
    return infos[i].color;
 
}
 

	
 
bool ChannelInfoModel::isVisible(unsigned i) const
 
{
 
    return infos[i].visibility;
 
}
 

	
 
bool ChannelInfoModel::gainEn (unsigned i) const
 
{
 
    return infos[i].gainEn;
 
}
 

	
 
double ChannelInfoModel::gain (unsigned i) const
 
{
 
    return infos[i].gain;
 
}
 

	
 
bool ChannelInfoModel::offsetEn (unsigned i) const
 
{
 
    return infos[i].offsetEn;
 
}
 

	
 
double ChannelInfoModel::offset (unsigned i) const
 
{
 
    return infos[i].offset;
 
}
 

	
 
QStringList ChannelInfoModel::channelNames() const
 
{
 
    QStringList r;
 
    for (unsigned ci = 0; ci < _numOfChannels; ci++)
 
    {
 
        r << name(ci);
 
    }
 
    return r;
 
}
 

	
 
int ChannelInfoModel::rowCount(const QModelIndex &parent) const
 
{
src/channelinfomodel.h
Show inline comments
 
@@ -37,24 +37,28 @@ public:
 
        COLUMN_GAIN,
 
        COLUMN_OFFSET,
 
        COLUMN_COUNT            // MUST be last
 
    };
 

	
 
    explicit ChannelInfoModel(unsigned numberOfChannels, QObject *parent = 0);
 
    ChannelInfoModel(const ChannelInfoModel& other);
 
    explicit ChannelInfoModel(const QStringList& channelNames);
 

	
 
    QString name     (unsigned i) const;
 
    QColor  color    (unsigned i) const;
 
    bool    isVisible(unsigned i) const;
 
    bool    gainEn   (unsigned i) const;
 
    double  gain     (unsigned i) const;
 
    bool    offsetEn (unsigned i) const;
 
    double  offset   (unsigned i) const;
 
    /// Returns a list of channel names
 
    QStringList channelNames() const;
 

	
 
    // implemented from QAbstractItemModel
 
    int           rowCount(const QModelIndex &parent = QModelIndex()) const;
 
    int           columnCount(const QModelIndex &parent = QModelIndex()) const;
 
    QVariant      data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
    bool          setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
 
    Qt::ItemFlags flags(const QModelIndex &index) const;
 
    QVariant      headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 

	
 
    void setNumOfChannels(unsigned number);
src/stream.cpp
Show inline comments
 
@@ -145,29 +145,43 @@ void Stream::setNumChannels(unsigned nc,
 
void Stream::feedIn(const SamplePack& data)
 
{
 
    Q_ASSERT(data.numChannels() == numChannels() &&
 
             data.hasX() == hasX());
 

	
 
    if (_paused) return;
 

	
 
    unsigned ns = data.numSamples();
 
    if (_hasx)
 
    {
 
        static_cast<RingBuffer*>(xData)->addSamples(data.xData(), ns);
 
    }
 
    for (unsigned i = 0; i < numChannels(); i++)
 
    for (unsigned ci = 0; ci < numChannels(); ci++)
 
    {
 
        static_cast<RingBuffer*>(channels[i]->yData())->addSamples(data.data(i), ns);
 
        // TODO: check for gainEn and offsetEn
 
        // apply gain and offset
 
        auto rdata = data.data(ci);
 
        auto mdata = new double[sizeof(double) * ns];
 
        // TODO: add gain&offset access methods to `StreamChannel`
 
        double gain = channels[ci]->info()->gain(ci);
 
        double offset = channels[ci]->info()->offset(ci);
 
        for (int i = 0; i < ns; i++)
 
        {
 
            mdata[i] = rdata[i] * gain + offset;
 
        }
 

	
 
        static_cast<RingBuffer*>(channels[ci]->yData())->addSamples(mdata, ns);
 
        delete[] mdata;
 
    }
 

	
 
    // TODO: emit modified (gain&offset) data
 
    Sink::feedIn(data);
 

	
 
    emit dataAdded();
 
}
 

	
 
void Stream::pause(bool paused)
 
{
 
    _paused = paused;
 
}
 

	
 
void Stream::clear()
 
{
0 comments (0 inline, 0 general)