2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
|
|
|
|
|
|
|
#include "audiographer/general/interleaver.h"
|
|
|
|
#include "audiographer/general/deinterleaver.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class InterleaverDeInterleaverTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (InterleaverDeInterleaverTest);
|
|
|
|
CPPUNIT_TEST (testInterleavedInput);
|
|
|
|
CPPUNIT_TEST (testDeInterleavedInput);
|
|
|
|
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;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
random_data_a = TestUtils::init_random_data (total_samples, 1.0);
|
|
|
|
random_data_b = TestUtils::init_random_data (samples_per_channel, 1.0);
|
|
|
|
random_data_c = TestUtils::init_random_data (samples_per_channel, 1.0);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
deinterleaver.reset (new DeInterleaver<float>());
|
|
|
|
interleaver.reset (new Interleaver<float>());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
sink_a.reset (new VectorSink<float>());
|
|
|
|
sink_b.reset (new VectorSink<float>());
|
|
|
|
sink_c.reset (new VectorSink<float>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data_a;
|
|
|
|
delete [] random_data_b;
|
|
|
|
delete [] random_data_c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInterleavedInput()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (channels, samples_per_channel);
|
|
|
|
interleaver->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 (interleaver->input (0));
|
|
|
|
deinterleaver->output (1)->add_output (interleaver->input (1));
|
|
|
|
deinterleaver->output (2)->add_output (interleaver->input (2));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
interleaver->add_output (sink_a);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// Process and assert
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data_a, total_samples, channels);
|
2009-12-27 09:46:23 -05:00
|
|
|
deinterleaver->process (c);
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_samples));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// And a second round...
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t less_samples = (samples_per_channel / 10) * channels;
|
|
|
|
deinterleaver->process (c.beginning (less_samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), 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 testDeInterleavedInput()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
deinterleaver->init (channels, samples_per_channel);
|
|
|
|
interleaver->init (channels, samples_per_channel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
interleaver->add_output (deinterleaver);
|
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
|
|
|
ProcessContext<float> c_a (random_data_a, samples_per_channel, 1);
|
|
|
|
ProcessContext<float> c_b (random_data_b, samples_per_channel, 1);
|
|
|
|
ProcessContext<float> c_c (random_data_c, samples_per_channel, 1);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// Process and assert
|
|
|
|
interleaver->input (0)->process (c_a);
|
|
|
|
interleaver->input (1)->process (c_b);
|
|
|
|
interleaver->input (2)->process (c_c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), samples_per_channel));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), samples_per_channel));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), samples_per_channel));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// And a second round...
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t less_samples = samples_per_channel / 5;
|
|
|
|
interleaver->input (0)->process (c_a.beginning (less_samples));
|
|
|
|
interleaver->input (1)->process (c_b.beginning (less_samples));
|
|
|
|
interleaver->input (2)->process (c_c.beginning (less_samples));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), less_samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), less_samples));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<Interleaver<float> > interleaver;
|
|
|
|
boost::shared_ptr<DeInterleaver<float> > deinterleaver;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
boost::shared_ptr<VectorSink<float> > sink_a;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_b;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_c;
|
|
|
|
|
|
|
|
float * random_data_a;
|
|
|
|
float * random_data_b;
|
|
|
|
float * random_data_c;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
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 (InterleaverDeInterleaverTest);
|
|
|
|
|