summaryrefslogtreecommitdiff
path: root/libs/audiographer/tests/general/sr_converter_test.cc
diff options
context:
space:
mode:
authorSakari Bergen <sakari.bergen@beatwaves.net>2010-03-15 19:11:48 +0000
committerSakari Bergen <sakari.bergen@beatwaves.net>2010-03-15 19:11:48 +0000
commit830911f6f9451d83a58043b3f9084d3caa164b7b (patch)
treef4ca4e3d86b51d66e7cecfb6b370cc4eb553e2d7 /libs/audiographer/tests/general/sr_converter_test.cc
parent44f4b84551d36ef4103d09452768f5ba53e0002c (diff)
Fix export, which has been broken since the boost::signals2 changes. Also update Audiographer, bacause of its incomplete sndfile handling. Audiographer is equal to revision 74
git-svn-id: svn://localhost/ardour2/branches/3.0@6760 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/audiographer/tests/general/sr_converter_test.cc')
-rw-r--r--libs/audiographer/tests/general/sr_converter_test.cc130
1 files changed, 130 insertions, 0 deletions
diff --git a/libs/audiographer/tests/general/sr_converter_test.cc b/libs/audiographer/tests/general/sr_converter_test.cc
new file mode 100644
index 0000000000..68e21d3558
--- /dev/null
+++ b/libs/audiographer/tests/general/sr_converter_test.cc
@@ -0,0 +1,130 @@
+#include "tests/utils.h"
+
+#include "audiographer/general/sr_converter.h"
+
+using namespace AudioGrapher;
+
+class SampleRateConverterTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE (SampleRateConverterTest);
+ CPPUNIT_TEST (testNoConversion);
+ CPPUNIT_TEST (testUpsampleLength);
+ CPPUNIT_TEST (testDownsampleLength);
+ CPPUNIT_TEST (testRespectsEndOfInput);
+ CPPUNIT_TEST_SUITE_END ();
+
+ public:
+ void setUp()
+ {
+ frames = 128;
+ random_data = TestUtils::init_random_data(frames);
+ sink.reset (new AppendingVectorSink<float>());
+ grabber.reset (new ProcessContextGrabber<float>());
+ converter.reset (new SampleRateConverter (1));
+ }
+
+ void tearDown()
+ {
+ delete [] random_data;
+ }
+
+ void testNoConversion()
+ {
+ assert (frames % 2 == 0);
+ nframes_t const half_frames = frames / 2;
+ nframes_t frames_output = 0;
+
+ converter->init (44100, 44100);
+ converter->add_output (sink);
+
+ ProcessContext<float> c (random_data, half_frames, 1);
+ converter->process (c);
+ ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1);
+ c2.set_flag (ProcessContext<float>::EndOfInput);
+ converter->process (c2);
+
+ frames_output = sink->get_data().size();
+ CPPUNIT_ASSERT_EQUAL (frames, frames_output);
+
+ CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames));
+ }
+
+ void testUpsampleLength()
+ {
+ assert (frames % 2 == 0);
+ nframes_t const half_frames = frames / 2;
+ nframes_t frames_output = 0;
+
+ converter->init (44100, 88200);
+ converter->allocate_buffers (half_frames);
+ converter->add_output (sink);
+
+ ProcessContext<float> c (random_data, half_frames, 1);
+ converter->process (c);
+ ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1);
+ c2.set_flag (ProcessContext<float>::EndOfInput);
+ converter->process (c2);
+
+ frames_output = sink->get_data().size();
+ nframes_t tolerance = 3;
+ CPPUNIT_ASSERT (2 * frames - tolerance < frames_output && frames_output < 2 * frames + tolerance);
+ }
+
+ void testDownsampleLength()
+ {
+ assert (frames % 2 == 0);
+ nframes_t const half_frames = frames / 2;
+ nframes_t frames_output = 0;
+
+ converter->init (88200, 44100);
+ converter->allocate_buffers (half_frames);
+ converter->add_output (sink);
+
+ ProcessContext<float> c (random_data, half_frames, 1);
+ converter->process (c);
+ ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1);
+ c2.set_flag (ProcessContext<float>::EndOfInput);
+ converter->process (c2);
+
+ frames_output = sink->get_data().size();
+ nframes_t tolerance = 3;
+ CPPUNIT_ASSERT (half_frames - tolerance < frames_output && frames_output < half_frames + tolerance);
+ }
+
+ void testRespectsEndOfInput()
+ {
+ assert (frames % 2 == 0);
+ nframes_t const half_frames = frames / 2;
+
+ converter->init (44100, 48000);
+ converter->allocate_buffers (half_frames);
+ converter->add_output (grabber);
+
+ ProcessContext<float> c (random_data, half_frames, 1);
+ converter->process (c);
+ ProcessContext<float> c2 (&random_data[half_frames], half_frames / 2, 1);
+ c2.set_flag (ProcessContext<float>::EndOfInput);
+ converter->process (c2);
+
+ for (std::list<ProcessContext<float> >::iterator it = grabber->contexts.begin(); it != grabber->contexts.end(); ++it) {
+ std::list<ProcessContext<float> >::iterator next = it; ++next;
+ if (next == grabber->contexts.end()) {
+ CPPUNIT_ASSERT (it->has_flag (ProcessContext<float>::EndOfInput));
+ } else {
+ CPPUNIT_ASSERT (!it->has_flag (ProcessContext<float>::EndOfInput));
+ }
+ }
+ }
+
+
+ private:
+ boost::shared_ptr<SampleRateConverter > converter;
+ boost::shared_ptr<AppendingVectorSink<float> > sink;
+ boost::shared_ptr<ProcessContextGrabber<float> > grabber;
+
+ float * random_data;
+ nframes_t frames;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION (SampleRateConverterTest);
+