diff options
author | John Glover <j@johnglover.net> | 2013-06-07 13:00:55 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2013-06-07 13:00:55 +0200 |
commit | d60bbc935a1c7137c766792bf569ea7d6800fba9 (patch) | |
tree | 2247eb781e2b2f28a1f13253517b2c5eed11a3ae /tests | |
parent | d91fc3a5b7b9d7a4ca85882b029fefe2c8daa156 (diff) | |
download | simpl-d60bbc935a1c7137c766792bf569ea7d6800fba9.tar.gz simpl-d60bbc935a1c7137c766792bf569ea7d6800fba9.tar.bz2 simpl-d60bbc935a1c7137c766792bf569ea7d6800fba9.zip |
Fix memory leaks in peak detection processes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_base.cpp | 12 | ||||
-rw-r--r-- | tests/test_partial_tracking.cpp | 60 | ||||
-rw-r--r-- | tests/test_peak_detection.cpp | 8 | ||||
-rw-r--r-- | tests/test_synthesis.cpp | 8 | ||||
-rw-r--r-- | tests/test_synthesis.h | 1 |
5 files changed, 14 insertions, 75 deletions
diff --git a/tests/test_base.cpp b/tests/test_base.cpp index b5f3acf..1a0816f 100644 --- a/tests/test_base.cpp +++ b/tests/test_base.cpp @@ -47,16 +47,12 @@ void TestFrame::test_max_partials() { } void TestFrame::test_add_peak() { - Peak p = Peak(); - p.amplitude = 1.5; - frame->add_peak(&p); + frame->add_peak(1.5, 220, 0, 0); CPPUNIT_ASSERT(frame->max_peaks() == 100); CPPUNIT_ASSERT(frame->num_peaks() == 1); CPPUNIT_ASSERT_DOUBLES_EQUAL(1.5, frame->peak(0)->amplitude, PRECISION); - Peak p2 = Peak(); - p2.amplitude = 2.0; - frame->add_peak(&p2); + frame->add_peak(2.0, 440, 0, 0); CPPUNIT_ASSERT(frame->max_peaks() == 100); CPPUNIT_ASSERT(frame->num_peaks() == 2); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, frame->peak(1)->amplitude, PRECISION); @@ -65,9 +61,7 @@ void TestFrame::test_add_peak() { } void TestFrame::test_clear() { - Peak p = Peak(); - p.amplitude = 1.5; - frame->add_peak(&p); + frame->add_peak(1.5, 220, 0, 0); CPPUNIT_ASSERT(frame->num_peaks() == 1); frame->clear(); CPPUNIT_ASSERT(frame->num_peaks() == 0); diff --git a/tests/test_partial_tracking.cpp b/tests/test_partial_tracking.cpp index b4872cd..2363c9d 100644 --- a/tests/test_partial_tracking.cpp +++ b/tests/test_partial_tracking.cpp @@ -41,27 +41,15 @@ void TestMQPartialTracking::test_basic() { void TestMQPartialTracking::test_peaks() { int num_frames = 8; Frames frames; - Peaks peaks; _pd.clear(); _pt.reset(); for(int i = 0; i < num_frames; i++) { - Peak* p = new Peak(); - p->amplitude = 0.4; - p->frequency = 220; - - Peak* p2 = new Peak(); - p2->amplitude = 0.2; - p2->frequency = 440; - Frame* f = new Frame(); - f->add_peak(p); - f->add_peak(p2); - + f->add_peak(0.4, 220, 0, 0); + f->add_peak(0.2, 440, 0, 0); frames.push_back(f); - peaks.push_back(p); - peaks.push_back(p2); } _pt.find_partials(frames); @@ -78,10 +66,6 @@ void TestMQPartialTracking::test_peaks() { PRECISION); } - for(int i = 0; i < num_frames * 2; i++) { - delete peaks[i]; - } - for(int i = 0; i < num_frames; i++) { delete frames[i]; } @@ -131,27 +115,15 @@ void TestSMSPartialTracking::test_basic() { void TestSMSPartialTracking::test_peaks() { int num_frames = 8; Frames frames; - Peaks peaks; _pd.clear(); _pt.reset(); for(int i = 0; i < num_frames; i++) { - Peak* p = new Peak(); - p->amplitude = 0.4; - p->frequency = 220; - - Peak* p2 = new Peak(); - p2->amplitude = 0.2; - p2->frequency = 440; - Frame* f = new Frame(); - f->add_peak(p); - f->add_peak(p2); - + f->add_peak(0.4, 220, 0, 0); + f->add_peak(0.2, 440, 0, 0); frames.push_back(f); - peaks.push_back(p); - peaks.push_back(p2); } _pt.find_partials(frames); @@ -168,10 +140,6 @@ void TestSMSPartialTracking::test_peaks() { PRECISION); } - for(int i = 0; i < num_frames * 2; i++) { - delete peaks[i]; - } - for(int i = 0; i < num_frames; i++) { delete frames[i]; } @@ -217,27 +185,15 @@ void TestLorisPartialTracking::test_basic() { void TestLorisPartialTracking::test_peaks() { int num_frames = 8; Frames frames; - Peaks peaks; _pd.clear(); _pt.reset(); for(int i = 0; i < num_frames; i++) { - Peak* p = new Peak(); - p->amplitude = 0.4; - p->frequency = 220; - - Peak* p2 = new Peak(); - p2->amplitude = 0.2; - p2->frequency = 440; - Frame* f = new Frame(); - f->add_peak(p); - f->add_peak(p2); - + f->add_peak(0.4, 220, 0, 0); + f->add_peak(0.2, 440, 0, 0); frames.push_back(f); - peaks.push_back(p); - peaks.push_back(p2); } _pt.find_partials(frames); @@ -254,10 +210,6 @@ void TestLorisPartialTracking::test_peaks() { PRECISION); } - for(int i = 0; i < num_frames * 2; i++) { - delete peaks[i]; - } - for(int i = 0; i < num_frames; i++) { delete frames[i]; } diff --git a/tests/test_peak_detection.cpp b/tests/test_peak_detection.cpp index e0eba9e..5aeca75 100644 --- a/tests/test_peak_detection.cpp +++ b/tests/test_peak_detection.cpp @@ -21,8 +21,8 @@ void TestMQPeakDetection::test_find_peaks_in_frame_basic() { _pd.frame_size(frame_size); Frame f = Frame(frame_size, true); - Peaks p = _pd.find_peaks_in_frame(&f); - CPPUNIT_ASSERT(p.size() == 0); + _pd.find_peaks_in_frame(&f); + CPPUNIT_ASSERT(f.num_peaks() == 0); } void TestMQPeakDetection::test_find_peaks_basic() { @@ -112,8 +112,8 @@ void TestLorisPeakDetection::test_find_peaks_in_frame_basic() { _pd.frame_size(frame_size); Frame f = Frame(frame_size, true); - Peaks p = _pd.find_peaks_in_frame(&f); - CPPUNIT_ASSERT(p.size() == 0); + _pd.find_peaks_in_frame(&f); + CPPUNIT_ASSERT(f.num_peaks() == 0); } void TestLorisPeakDetection::test_find_peaks_basic() { diff --git a/tests/test_synthesis.cpp b/tests/test_synthesis.cpp index 96b8f4d..c861be0 100644 --- a/tests/test_synthesis.cpp +++ b/tests/test_synthesis.cpp @@ -163,13 +163,8 @@ void TestSMSSynthesis::setUp() { // 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); + f->add_peak(0.4, 220.0, 0.0, 0.0); _frames.push_back(f); } _pt.find_partials(_frames); @@ -177,7 +172,6 @@ void TestSMSSynthesis::setUp() { void TestSMSSynthesis::tearDown() { for(int i = 0; i < _pt.max_frame_delay(); i++) { - delete _peaks[i]; delete _frames[i]; } } diff --git a/tests/test_synthesis.h b/tests/test_synthesis.h index 15ba88b..8f9ec77 100644 --- a/tests/test_synthesis.h +++ b/tests/test_synthesis.h @@ -74,7 +74,6 @@ protected: SMSPartialTracking _pt; SMSSynthesis _synth; SndfileHandle _sf; - Peaks _peaks; Frames _frames; void test_basic(); |