2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
|
|
|
|
|
|
|
#include "audiographer/general/peak_reader.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class PeakReaderTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (PeakReaderTest);
|
|
|
|
CPPUNIT_TEST (testProcess);
|
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samples = 128;
|
|
|
|
random_data = TestUtils::init_random_data(samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testProcess()
|
|
|
|
{
|
|
|
|
reader.reset (new PeakReader());
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
float peak = 1.5;
|
|
|
|
random_data[10] = peak;
|
|
|
|
reader->process (c);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
peak = 2.0;
|
|
|
|
random_data[10] = peak;
|
|
|
|
reader->process (c);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
peak = -2.1;
|
|
|
|
random_data[10] = peak;
|
|
|
|
reader->process (c);
|
|
|
|
float expected = fabs(peak);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(expected, reader->get_peak());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<PeakReader> reader;
|
|
|
|
|
|
|
|
float * random_data;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples;
|
2009-12-27 09:46:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (PeakReaderTest);
|