diff options
author | John Glover <j@johnglover.net> | 2013-06-14 11:47:06 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2013-06-14 11:47:06 +0200 |
commit | 364d1a9352cf1adcf08fbd4f0e793f24540d7402 (patch) | |
tree | b001aadeb38c96104c6fbd026519c7161486cc28 /tests | |
parent | 2114ea951d728527ff5e833030d717c635b51821 (diff) | |
download | simpl-364d1a9352cf1adcf08fbd4f0e793f24540d7402.tar.gz simpl-364d1a9352cf1adcf08fbd4f0e793f24540d7402.tar.bz2 simpl-364d1a9352cf1adcf08fbd4f0e793f24540d7402.zip |
Add basic SndObjPeakDetection tests. Fix memory leaks.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_peak_detection.cpp | 69 | ||||
-rw-r--r-- | tests/test_peak_detection.h | 25 | ||||
-rw-r--r-- | tests/tests.cpp | 1 |
3 files changed, 95 insertions, 0 deletions
diff --git a/tests/test_peak_detection.cpp b/tests/test_peak_detection.cpp index 5aeca75..23480ba 100644 --- a/tests/test_peak_detection.cpp +++ b/tests/test_peak_detection.cpp @@ -160,3 +160,72 @@ void TestLorisPeakDetection::test_find_peaks_change_hop_frame_size() { CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); } } + + +// --------------------------------------------------------------------------- +// TestSndObjPeakDetection +// --------------------------------------------------------------------------- +void TestSndObjPeakDetection::setUp() { + _sf = SndfileHandle(TEST_AUDIO_FILE); + + if(_sf.error() > 0) { + throw Exception(std::string("Could not open audio file: ") + + std::string(TEST_AUDIO_FILE)); + } +} + +void TestSndObjPeakDetection::test_find_peaks_in_frame_basic() { + int frame_size = 2048; + + _pd.clear(); + _pd.frame_size(frame_size); + + Frame f = Frame(frame_size, true); + _pd.find_peaks_in_frame(&f); + CPPUNIT_ASSERT(f.num_peaks() == 0); +} + +void TestSndObjPeakDetection::test_find_peaks_basic() { + int frame_size = 512; + std::vector<sample> audio(frame_size * 2, 0.0); + + _pd.clear(); + _pd.frame_size(frame_size); + + Frames frames = _pd.find_peaks(audio.size(), &audio[0]); + + CPPUNIT_ASSERT(frames.size() == 2); + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); + } +} + +void TestSndObjPeakDetection::test_find_peaks_audio() { + int num_frames = 5; + int num_samples = _pd.frame_size() + (_pd.hop_size() * num_frames); + + std::vector<sample> audio(_sf.frames(), 0.0); + _sf.read(&audio[0], (int)_sf.frames()); + + _pd.clear(); + 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); + } +} + +void TestSndObjPeakDetection::test_find_peaks_change_hop_frame_size() { + int num_samples = 1024; + std::vector<sample> audio(num_samples, 0.0); + + _pd.clear(); + _pd.frame_size(256); + _pd.hop_size(256); + + Frames frames = _pd.find_peaks(num_samples, &audio[0]); + CPPUNIT_ASSERT(frames.size() == 4); + for(int i = 0; i < frames.size(); i++) { + CPPUNIT_ASSERT(frames[i]->num_peaks() == 0); + } +} diff --git a/tests/test_peak_detection.h b/tests/test_peak_detection.h index 2b574cb..a107ee8 100644 --- a/tests/test_peak_detection.h +++ b/tests/test_peak_detection.h @@ -73,6 +73,31 @@ protected: void test_find_peaks_change_hop_frame_size(); }; + +// --------------------------------------------------------------------------- +// TestSndObjPeakDetection +// --------------------------------------------------------------------------- +class TestSndObjPeakDetection : public CPPUNIT_NS::TestCase { + CPPUNIT_TEST_SUITE(TestSndObjPeakDetection); + CPPUNIT_TEST(test_find_peaks_in_frame_basic); + CPPUNIT_TEST(test_find_peaks_basic); + CPPUNIT_TEST(test_find_peaks_audio); + CPPUNIT_TEST(test_find_peaks_change_hop_frame_size); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + +protected: + SndObjPeakDetection _pd; + SndfileHandle _sf; + + void test_find_peaks_in_frame_basic(); + void test_find_peaks_basic(); + void test_find_peaks_audio(); + void test_find_peaks_change_hop_frame_size(); +}; + } // end of namespace simpl #endif diff --git a/tests/tests.cpp b/tests/tests.cpp index d185923..e52653d 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -10,6 +10,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestPeak); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestFrame); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPeakDetection); +CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSndObjPeakDetection); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestTWM); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPartialTracking); |