diff options
author | John Glover <j@johnglover.net> | 2013-01-25 14:50:03 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2013-01-25 14:50:03 +0100 |
commit | 10bc63c13cf9a6195d6b19f832258ff8e1d84f78 (patch) | |
tree | 09f101412c47a485a6d2b623183354a9200db44c /tests | |
parent | 42381e2a704850cca13c74110813fa865727cef8 (diff) | |
download | simpl-10bc63c13cf9a6195d6b19f832258ff8e1d84f78.tar.gz simpl-10bc63c13cf9a6195d6b19f832258ff8e1d84f78.tar.bz2 simpl-10bc63c13cf9a6195d6b19f832258ff8e1d84f78.zip |
[tests] Add basic tests for SMS synthesis
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_synthesis.cpp | 52 | ||||
-rw-r--r-- | tests/test_synthesis.h | 25 | ||||
-rw-r--r-- | tests/tests.cpp | 1 |
3 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_synthesis.cpp b/tests/test_synthesis.cpp index 2675589..96b8f4d 100644 --- a/tests/test_synthesis.cpp +++ b/tests/test_synthesis.cpp @@ -8,6 +8,8 @@ using namespace simpl; static void test_basic(PeakDetection *pd, PartialTracking* pt, Synthesis* synth, SndfileHandle *sf) { int num_samples = 4096; + int hop_size = 256; + int frame_size = 512; std::vector<sample> audio(sf->frames(), 0.0); sf->read(&audio[0], (int)sf->frames()); @@ -16,6 +18,10 @@ static void test_basic(PeakDetection *pd, PartialTracking* pt, pt->reset(); synth->reset(); + pd->frame_size(frame_size); + pd->hop_size(hop_size); + synth->hop_size(hop_size); + Frames frames = pd->find_peaks(num_samples, &(audio[(int)sf->frames() / 2])); frames = pt->find_partials(frames); @@ -137,3 +143,49 @@ void TestLorisSynthesis::test_basic() { void TestLorisSynthesis::test_changing_frame_size() { ::test_changing_frame_size(&_pd, &_pt, &_synth, &_sf); } + +// --------------------------------------------------------------------------- +// TestSMSSynthesis +// --------------------------------------------------------------------------- +void TestSMSSynthesis::setUp() { + _sf = SndfileHandle(TEST_AUDIO_FILE); + + if(_sf.error() > 0) { + throw Exception(std::string("Could not open audio file: ") + + std::string(TEST_AUDIO_FILE)); + } + + _pd.clear(); + _pt.reset(); + _synth.reset(); + + // SMSPartialTracking has a delay of _pt.max_frame_delay(), + // so pass peak data to find_partials before calling the + // main test function + for(int i = 0; i < _pt.max_frame_delay(); i++) { + Peak* p = new Peak(); + p->amplitude = 0.4; + p->frequency = 220; + _peaks.push_back(p); + + Frame* f = new Frame(); + f->add_peak(p); + _frames.push_back(f); + } + _pt.find_partials(_frames); +} + +void TestSMSSynthesis::tearDown() { + for(int i = 0; i < _pt.max_frame_delay(); i++) { + delete _peaks[i]; + delete _frames[i]; + } +} + +void TestSMSSynthesis::test_basic() { + ::test_basic(&_pd, &_pt, &_synth, &_sf); +} + +void TestSMSSynthesis::test_changing_frame_size() { + ::test_changing_frame_size(&_pd, &_pt, &_synth, &_sf); +} diff --git a/tests/test_synthesis.h b/tests/test_synthesis.h index 5e818d9..15ba88b 100644 --- a/tests/test_synthesis.h +++ b/tests/test_synthesis.h @@ -56,6 +56,31 @@ protected: void test_changing_frame_size(); }; +// --------------------------------------------------------------------------- +// TestSMSSynthesis +// --------------------------------------------------------------------------- +class TestSMSSynthesis : public CPPUNIT_NS::TestCase { + CPPUNIT_TEST_SUITE(TestSMSSynthesis); + CPPUNIT_TEST(test_basic); + CPPUNIT_TEST(test_changing_frame_size); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + +protected: + SMSPeakDetection _pd; + SMSPartialTracking _pt; + SMSSynthesis _synth; + SndfileHandle _sf; + Peaks _peaks; + Frames _frames; + + void test_basic(); + void test_changing_frame_size(); +}; + } // end of namespace simpl #endif diff --git a/tests/tests.cpp b/tests/tests.cpp index d13b4f7..133c873 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -16,6 +16,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSPartialTracking); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis); +CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSSynthesis); int main(int arg, char **argv) { CppUnit::TextTestRunner runner; |