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
 
@@ -159,6 +159,14 @@ 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;
src/stream.h
Show inline comments
 
@@ -85,6 +85,9 @@ public slots:
 
    /// When paused data feed is ignored
 
    void pause(bool paused);
 

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

	
 
private:
 
    unsigned _numSamples;
 
    bool _paused;
tests/test_stream.cpp
Show inline comments
 
@@ -179,7 +179,7 @@ TEST_CASE("adding data to a stream with 
 
    }
 
}
 

	
 
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);
 

	
 
@@ -211,3 +211,36 @@ TEST_CASE("paused stream shoulnd't store
 
        }
 
    }
 
}
 

	
 
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)