diff options
author | John Glover <j@johnglover.net> | 2013-06-15 23:38:39 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2013-06-15 23:38:39 +0200 |
commit | c357d6caf3eb64d3fc2604868b696c1e34e8d16e (patch) | |
tree | b1b595dfa7790a8a9520413ce133850e79713ec0 /tests | |
parent | 60ed1e8252e6e4f0cbc8c0a5c9aea124bdd2a01b (diff) | |
download | simpl-c357d6caf3eb64d3fc2604868b696c1e34e8d16e.tar.gz simpl-c357d6caf3eb64d3fc2604868b696c1e34e8d16e.tar.bz2 simpl-c357d6caf3eb64d3fc2604868b696c1e34e8d16e.zip |
Add basic tests for SndObjPartialTracking.
Fix reading invalid memory address when looping over partials.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_partial_tracking.cpp | 129 | ||||
-rw-r--r-- | tests/test_partial_tracking.h | 26 | ||||
-rw-r--r-- | tests/tests.cpp | 1 |
3 files changed, 156 insertions, 0 deletions
diff --git a/tests/test_partial_tracking.cpp b/tests/test_partial_tracking.cpp index 31e0473..0c835fd 100644 --- a/tests/test_partial_tracking.cpp +++ b/tests/test_partial_tracking.cpp @@ -204,6 +204,135 @@ void TestSMSPartialTracking::test_streaming() { // --------------------------------------------------------------------------- +// TestSndObjPartialTracking +// --------------------------------------------------------------------------- +void TestSndObjPartialTracking::setUp() { + _sf = SndfileHandle(TEST_AUDIO_FILE); + + if(_sf.error() > 0) { + throw Exception(std::string("Could not open audio file: ") + + std::string(TEST_AUDIO_FILE)); + } + + _pt.max_partials(5); +} + +void TestSndObjPartialTracking::test_basic() { + int hop_size = 256; + int frame_size = 2048; + int num_samples = 4096; + + _pd.clear(); + _pt.reset(); + + _pd.hop_size(hop_size); + _pd.frame_size(frame_size); + + std::vector<sample> audio(_sf.frames(), 0.0); + _sf.read(&audio[0], (int)_sf.frames()); + + Frames frames = _pd.find_peaks(num_samples, + &(audio[(int)_sf.frames() / 2])); + frames = _pt.find_partials(frames); + + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); + CPPUNIT_ASSERT(frames[i]->num_partials() > 0); + } +} + +void TestSndObjPartialTracking::test_change_num_partials() { + int hop_size = 256; + int frame_size = 2048; + int num_samples = 4096; + int max_partials = 10; + + _pd.clear(); + _pt.reset(); + + _pd.hop_size(hop_size); + _pd.frame_size(frame_size); + + _pd.max_peaks(max_partials); + _pt.max_partials(max_partials); + + std::vector<sample> audio(_sf.frames(), 0.0); + _sf.read(&audio[0], (int)_sf.frames()); + + Frames frames = _pd.find_peaks(num_samples, + &(audio[(int)_sf.frames() / 2])); + frames = _pt.find_partials(frames); + + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() == max_partials); + CPPUNIT_ASSERT(frames[i]->num_partials() == max_partials); + } +} + +void TestSndObjPartialTracking::test_peaks() { + int num_frames = 8; + Frames frames; + + _pd.clear(); + _pt.reset(); + + for(int i = 0; i < num_frames; i++) { + Frame* f = new Frame(); + f->add_peak(0.4, 220, 0, 0); + f->add_peak(0.2, 440, 0, 0); + frames.push_back(f); + } + + _pt.find_partials(frames); + for(int i = 1; i < num_frames; i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); + CPPUNIT_ASSERT(frames[i]->num_partials() > 0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.4, frames[i]->partial(0)->amplitude, + PRECISION); + CPPUNIT_ASSERT_DOUBLES_EQUAL(220, frames[i]->partial(0)->frequency, + PRECISION); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, frames[i]->partial(1)->amplitude, + PRECISION); + CPPUNIT_ASSERT_DOUBLES_EQUAL(440, frames[i]->partial(1)->frequency, + PRECISION); + } + + for(int i = 0; i < num_frames; i++) { + delete frames[i]; + } +} + +void TestSndObjPartialTracking::test_streaming() { + int hop_size = 256; + int frame_size = 2048; + int num_frames = 10; + int max_partials = 10; + + _pd.clear(); + _pt.reset(); + + _pd.hop_size(hop_size); + _pd.frame_size(frame_size); + + _pd.max_peaks(max_partials); + _pt.max_partials(max_partials); + + std::vector<sample> audio(_sf.frames(), 0.0); + _sf.read(&audio[0], (int)_sf.frames()); + + for(int i = 0, n = (int)_sf.frames() / 2; i < num_frames; i++, n += hop_size) { + Frame f(frame_size, true); + f.audio(&(audio[n]), frame_size); + + _pd.find_peaks_in_frame(&f); + _pt.update_partials(&f); + + CPPUNIT_ASSERT(f.num_partials() > 0); + } +} + + +// --------------------------------------------------------------------------- // TestLorisPartialTracking // --------------------------------------------------------------------------- void TestLorisPartialTracking::setUp() { diff --git a/tests/test_partial_tracking.h b/tests/test_partial_tracking.h index c548984..e5715de 100644 --- a/tests/test_partial_tracking.h +++ b/tests/test_partial_tracking.h @@ -58,6 +58,32 @@ protected: void test_streaming(); }; + +// --------------------------------------------------------------------------- +// TestSndObjPartialTracking +// --------------------------------------------------------------------------- +class TestSndObjPartialTracking : public CPPUNIT_NS::TestCase { + CPPUNIT_TEST_SUITE(TestSndObjPartialTracking); + CPPUNIT_TEST(test_basic); + CPPUNIT_TEST(test_change_num_partials); + CPPUNIT_TEST(test_peaks); + CPPUNIT_TEST(test_streaming); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + +protected: + SndObjPeakDetection _pd; + SndObjPartialTracking _pt; + SndfileHandle _sf; + + void test_basic(); + void test_change_num_partials(); + void test_peaks(); + void test_streaming(); +}; + // --------------------------------------------------------------------------- // TestLorisPartialTracking // --------------------------------------------------------------------------- diff --git a/tests/tests.cpp b/tests/tests.cpp index e52653d..11fbebf 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -15,6 +15,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestTWM); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPartialTracking); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSPartialTracking); +CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSndObjPartialTracking); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis); |