diff options
author | John Glover <j@johnglover.net> | 2012-10-24 17:34:07 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-10-24 17:34:07 +0200 |
commit | 4c9d241754b134d7704bdea04ec90be758eb47c1 (patch) | |
tree | 602b602f683e2c29bf22fcfbff41c7b5ab54b2cb /tests | |
parent | ed811c93657b9cdc20c8203966881de5141fe5c4 (diff) | |
download | simpl-4c9d241754b134d7704bdea04ec90be758eb47c1.tar.gz simpl-4c9d241754b134d7704bdea04ec90be758eb47c1.tar.bz2 simpl-4c9d241754b134d7704bdea04ec90be758eb47c1.zip |
Add MQ peak detection C++ basic test file
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_peak_detection.cpp | 87 |
1 files changed, 84 insertions, 3 deletions
diff --git a/tests/test_peak_detection.cpp b/tests/test_peak_detection.cpp index 4c09dbd..4a8fab8 100644 --- a/tests/test_peak_detection.cpp +++ b/tests/test_peak_detection.cpp @@ -14,6 +14,86 @@ namespace simpl { // --------------------------------------------------------------------------- +// TestMQPeakDetection +// --------------------------------------------------------------------------- +class TestMQPeakDetection : public CPPUNIT_NS::TestCase { + CPPUNIT_TEST_SUITE(TestMQPeakDetection); + CPPUNIT_TEST(test_find_peaks_in_frame_basic); + CPPUNIT_TEST(test_find_peaks_basic); + CPPUNIT_TEST(test_find_peaks_change_hop_frame_size); + CPPUNIT_TEST(test_find_peaks_audio); + CPPUNIT_TEST_SUITE_END(); + +protected: + static const double PRECISION = 0.001; + MQPeakDetection* pd; + SndfileHandle sf; + int num_samples; + + void test_find_peaks_in_frame_basic() { + pd->clear(); + pd->frame_size(2048); + + Frame* f = new Frame(2048, true); + Peaks p = pd->find_peaks_in_frame(f); + CPPUNIT_ASSERT(p.size() == 0); + + delete f; + pd->clear(); + } + + void test_find_peaks_basic() { + sample* audio = new sample[1024]; + pd->frame_size(512); + + Frames frames = pd->find_peaks(1024, audio); + CPPUNIT_ASSERT(frames.size() == 2); + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); + } + + delete [] audio; + } + + void test_find_peaks_change_hop_frame_size() { + sample* audio = new sample[1024]; + pd->frame_size(256); + pd->hop_size(256); + + Frames frames = pd->find_peaks(1024, audio); + CPPUNIT_ASSERT(frames.size() == 4); + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); + } + + delete [] audio; + } + + void test_find_peaks_audio() { + sample* audio = new sample[(int)sf.frames()]; + sf.read(audio, (int)sf.frames()); + + Frames frames = pd->find_peaks(num_samples, &(audio[(int)sf.frames() / 2])); + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); + } + + delete [] audio; + } + +public: + void setUp() { + pd = new MQPeakDetection(); + sf = SndfileHandle("../tests/audio/flute.wav"); + num_samples = 4096; + } + + void tearDown() { + delete pd; + } +}; + +// --------------------------------------------------------------------------- // TestLorisPeakDetection // --------------------------------------------------------------------------- class TestLorisPeakDetection : public CPPUNIT_NS::TestCase { @@ -52,7 +132,7 @@ protected: CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); } - delete audio; + delete [] audio; } void test_find_peaks_change_hop_frame_size() { @@ -66,7 +146,7 @@ protected: CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); } - delete audio; + delete [] audio; } void test_find_peaks_audio() { @@ -78,7 +158,7 @@ protected: CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); } - delete audio; + delete [] audio; } public: @@ -95,6 +175,7 @@ public: } // end of namespace simpl +CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPeakDetection); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection); int main(int arg, char **argv) { |