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;
|
|
|
|
frames_per_channel = 128;
|
|
|
|
total_frames = channels * frames_per_channel;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
random_data_a = TestUtils::init_random_data (total_frames, 1.0);
|
|
|
|
random_data_b = TestUtils::init_random_data (frames_per_channel, 1.0);
|
|
|
|
random_data_c = TestUtils::init_random_data (frames_per_channel, 1.0);
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
deinterleaver->init (channels, frames_per_channel);
|
|
|
|
interleaver->init (channels, frames_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
|
|
|
|
ProcessContext<float> c (random_data_a, total_frames, channels);
|
|
|
|
deinterleaver->process (c);
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_frames));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// And a second round...
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t less_frames = (frames_per_channel / 10) * channels;
|
2010-03-15 15:11:48 -04:00
|
|
|
deinterleaver->process (c.beginning (less_frames));
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames));
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
void testDeInterleavedInput()
|
|
|
|
{
|
|
|
|
deinterleaver->init (channels, frames_per_channel);
|
|
|
|
interleaver->init (channels, frames_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
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
ProcessContext<float> c_a (random_data_a, frames_per_channel, 1);
|
|
|
|
ProcessContext<float> c_b (random_data_b, frames_per_channel, 1);
|
|
|
|
ProcessContext<float> c_c (random_data_c, frames_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
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), frames_per_channel));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), frames_per_channel));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), frames_per_channel));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// And a second round...
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t less_frames = frames_per_channel / 5;
|
2010-03-15 15:11:48 -04:00
|
|
|
interleaver->input (0)->process (c_a.beginning (less_frames));
|
|
|
|
interleaver->input (1)->process (c_b.beginning (less_frames));
|
|
|
|
interleaver->input (2)->process (c_c.beginning (less_frames));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), less_frames));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), less_frames));
|
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
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t frames_per_channel;
|
|
|
|
framecnt_t total_frames;
|
2009-12-27 09:46:23 -05:00
|
|
|
unsigned int channels;
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (InterleaverDeInterleaverTest);
|
|
|
|
|