Changeset - 8554454db965
[Not reviewed]
stream
0 3 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2018-03-26 15:52:23
hy@ozderya.net
added stream clear method to zero the buffers
3 files changed with 45 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/stream.cpp
Show inline comments
 
@@ -150,24 +150,32 @@ void Stream::feedIn(const SamplePack& da
 
    {
 
        static_cast<RingBuffer*>(channels[i]->yData())->addSamples(data.data(i), ns);
 
    }
 

	
 
    Sink::feedIn(data);
 
}
 

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

	
 
void Stream::clear()
 
{
 
    for (auto c : channels)
 
    {
 
        static_cast<RingBuffer*>(c->yData())->clear();
 
    }
 
}
 

	
 
void Stream::setNumSamples(unsigned value)
 
{
 
    if (value == _numSamples) return;
 
    _numSamples = value;
 

	
 
    xData->resize(value);
 
    for (auto c : channels)
 
    {
 
        static_cast<RingBuffer*>(c->yData())->resize(value);
 
    }
 
}
 

	
src/stream.h
Show inline comments
 
@@ -76,24 +76,27 @@ signals:
 
    void channelAdded(const StreamChannel* chan);
 
    void channelNameChanged(unsigned channel, QString name); // TODO: does it stay?
 
    void dataAdded(); ///< emitted when data added to channel man.
 

	
 
public slots:
 
    // TODO: these won't be public
 
    // void setNumChannels(unsigned number);
 
    void setNumSamples(unsigned value);
 

	
 
    /// When paused data feed is ignored
 
    void pause(bool paused);
 

	
 
    /// Clears buffer data (fills with 0)
 
    void clear();
 

	
 
private:
 
    unsigned _numSamples;
 
    bool _paused;
 

	
 
    bool _hasx;
 
    ResizableBuffer* xData;
 
    QList<StreamChannel*> channels;
 

	
 
    ChannelInfoModel _infoModel;
 
};
 

	
 

	
tests/test_stream.cpp
Show inline comments
 
@@ -170,25 +170,25 @@ TEST_CASE("adding data to a stream with 
 
    // check x
 
    const FrameBuffer* x = s.channel(0)->xData();
 
    for (unsigned i = 0; i < 5; i++)
 
    {
 
        REQUIRE(x->sample(i) == 0);
 
    }
 
    for (unsigned i = 5; i < 10; i++)
 
    {
 
        REQUIRE(x->sample(i) == (i-5)+10);
 
    }
 
}
 

	
 
TEST_CASE("paused stream shoulnd't store data", "[memory, stream, pause]")
 
TEST_CASE("paused stream shouldn't store data", "[memory, stream, pause]")
 
{
 
    Stream s(3, false, 10);
 

	
 
    // prepare data
 
    SamplePack pack(5, 3, false);
 
    for (unsigned ci = 0; ci < 3; ci++)
 
    {
 
        for (unsigned i = 0; i < 5; i++)
 
        {
 
            pack.data(ci)[i] = i;
 
        }
 
    }
 
@@ -202,12 +202,45 @@ TEST_CASE("paused stream shoulnd't store
 

	
 
    for (unsigned ci = 0; ci < 3; ci++)
 
    {
 
        const StreamChannel* c = s.channel(ci);
 
        const FrameBuffer* y = c->yData();
 

	
 
        for (unsigned i = 0; i < 10; i++)
 
        {
 
            REQUIRE(y->sample(i) == 0);
 
        }
 
    }
 
}
 

	
 
TEST_CASE("clear stream data", "[memory, stream, pause]")
 
{
 
    Stream s(3, false, 10);
 

	
 
    // prepare data
 
    SamplePack pack(5, 3, false);
 
    for (unsigned ci = 0; ci < 3; ci++)
 
    {
 
        for (unsigned i = 0; i < 5; i++)
 
        {
 
            pack.data(ci)[i] = i;
 
        }
 
    }
 

	
 
    TestSource so(3, false);
 
    so.connect(&s);
 

	
 
    // test
 
    so._feed(pack);
 
    s.clear();
 

	
 
    for (unsigned ci = 0; ci < 3; ci++)
 
    {
 
        const StreamChannel* c = s.channel(ci);
 
        const FrameBuffer* y = c->yData();
 

	
 
        for (unsigned i = 0; i < 10; i++)
 
        {
 
            REQUIRE(y->sample(i) == 0);
 
        }
 
    }
 
}
0 comments (0 inline, 0 general)