2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
|
|
|
|
|
|
|
#include "audiographer/general/deinterleaver.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class DeInterleaverTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (DeInterleaverTest);
|
|
|
|
CPPUNIT_TEST (testUninitialized);
|
|
|
|
CPPUNIT_TEST (testInvalidOutputIndex);
|
|
|
|
CPPUNIT_TEST (testInvalidInputSize);
|
|
|
|
CPPUNIT_TEST (testOutputSize);
|
|
|
|
CPPUNIT_TEST (testZeroInput);
|
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
channels = 3;
|
2017-09-18 12:39:17 -04:00
|
|
|
samples_per_channel = 128;
|
|
|
|
total_samples = channels * samples_per_channel;
|
|
|
|
random_data = TestUtils::init_random_data (total_samples, 1.0);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
deinterleaver.reset (new DeInterleaver<float>());
|
|
|
|
sink_a.reset (new VectorSink<float>());
|
|
|
|
sink_b.reset (new VectorSink<float>());
|
|
|
|
sink_c.reset (new VectorSink<float>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testUninitialized()
|
|
|
|
{
|
|
|
|
deinterleaver.reset (new DeInterleaver<float>());
|
|
|
|
CPPUNIT_ASSERT_THROW (deinterleaver->output(0)->add_output (sink_a), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidOutputIndex()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (3, samples_per_channel);
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT_THROW (deinterleaver->output(3)->add_output (sink_a), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidInputSize()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (channels, samples_per_channel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, 2 * total_samples, channels);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Too many, samples % channels == 0
|
|
|
|
CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples + channels)), Exception);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Too many, samples % channels != 0
|
|
|
|
CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples + 1)), Exception);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Too few, samples % channels != 0
|
|
|
|
CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_samples - 1)), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
void assert_outputs (samplecnt_t expected_samples)
|
2009-12-27 09:46:23 -05:00
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t generated_samples = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
generated_samples = sink_a->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
generated_samples = sink_b->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
generated_samples = sink_c->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testOutputSize()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (channels, samples_per_channel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
deinterleaver->output (0)->add_output (sink_a);
|
|
|
|
deinterleaver->output (1)->add_output (sink_b);
|
|
|
|
deinterleaver->output (2)->add_output (sink_c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Test maximum sample input
|
|
|
|
ProcessContext<float> c (random_data, total_samples, channels);
|
2009-12-27 09:46:23 -05:00
|
|
|
deinterleaver->process (c);
|
2017-09-18 12:39:17 -04:00
|
|
|
assert_outputs (samples_per_channel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Now with less samples
|
|
|
|
samplecnt_t const less_samples = samples_per_channel / 4;
|
|
|
|
deinterleaver->process (c.beginning (less_samples * channels));
|
|
|
|
assert_outputs (less_samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
void testZeroInput()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (channels, samples_per_channel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
deinterleaver->output (0)->add_output (sink_a);
|
|
|
|
deinterleaver->output (1)->add_output (sink_b);
|
|
|
|
deinterleaver->output (2)->add_output (sink_c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// Input zero samples
|
|
|
|
ProcessContext<float> c (random_data, total_samples, channels);
|
2010-03-15 15:11:48 -04:00
|
|
|
deinterleaver->process (c.beginning (0));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// ...and now test regular input
|
|
|
|
deinterleaver->process (c);
|
2017-09-18 12:39:17 -04:00
|
|
|
assert_outputs (samples_per_channel);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<DeInterleaver<float> > deinterleaver;
|
|
|
|
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_a;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_b;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_c;
|
|
|
|
|
|
|
|
float * random_data;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples_per_channel;
|
|
|
|
samplecnt_t total_samples;
|
2009-12-27 09:46:23 -05:00
|
|
|
unsigned int channels;
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (DeInterleaverTest);
|
|
|
|
|