summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2013-01-11 17:44:05 +0100
committerJohn Glover <j@johnglover.net>2013-01-11 17:44:05 +0100
commitad704b5e9c985765e14eb38a0922e702b8bfc25a (patch)
treea1aa9e55e4df46c1f30ec33d301370ae44b7f1af /tests
parent971a93d0676914837cdef22afa26f020b7be9041 (diff)
downloadsimpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.tar.gz
simpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.tar.bz2
simpl-ad704b5e9c985765e14eb38a0922e702b8bfc25a.zip
[tests] Tidy up test C++ tests.
All tests can now be run from a single executable called 'tests' (created in the build directory).
Diffstat (limited to 'tests')
-rw-r--r--tests/test_base.cpp153
-rw-r--r--tests/test_base.h63
-rw-r--r--tests/test_common.h15
-rw-r--r--tests/test_partial_tracking.cpp496
-rw-r--r--tests/test_partial_tracking.h80
-rw-r--r--tests/test_peak_detection.cpp247
-rw-r--r--tests/test_peak_detection.h65
-rw-r--r--tests/test_synthesis.cpp177
-rw-r--r--tests/test_synthesis.h57
-rw-r--r--tests/tests.cpp24
10 files changed, 749 insertions, 628 deletions
diff --git a/tests/test_base.cpp b/tests/test_base.cpp
index 2f7b5c4..b5f3acf 100644
--- a/tests/test_base.cpp
+++ b/tests/test_base.cpp
@@ -1,117 +1,74 @@
-#include <iostream>
-#include <cppunit/ui/text/TextTestRunner.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/TestResultCollector.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/BriefTestProgressListener.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
+#include "test_base.h"
-#include "../src/simpl/base.h"
-
-namespace simpl
-{
+using namespace simpl;
// ---------------------------------------------------------------------------
// TestPeak
// ---------------------------------------------------------------------------
-class TestPeak : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestPeak);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- Peak* peak;
+void TestPeak::setUp() {
+ peak = new Peak();
+}
-public:
- void setUp() {
- peak = new Peak();
- }
+void TestPeak::tearDown() {
+ delete peak;
+}
- void tearDown() {
- delete peak;
- }
-};
// ---------------------------------------------------------------------------
// TestFrame
// ---------------------------------------------------------------------------
-class TestFrame : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestFrame);
- CPPUNIT_TEST(test_size);
- CPPUNIT_TEST(test_max_peaks);
- CPPUNIT_TEST(test_max_partials);
- CPPUNIT_TEST(test_add_peak);
- CPPUNIT_TEST(test_clear);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- Frame* frame;
-
- void test_size() {
- frame->size(1024);
- CPPUNIT_ASSERT(frame->size() == 1024);
- frame->size(512);
- }
-
- void test_max_peaks() {
- frame->max_peaks(200);
- CPPUNIT_ASSERT(frame->max_peaks() == 200);
- CPPUNIT_ASSERT(frame->num_peaks() == 0);
- frame->max_peaks(100);
- }
-
- void test_max_partials() {
- frame->max_partials(200);
- CPPUNIT_ASSERT(frame->max_partials() == 200);
- CPPUNIT_ASSERT(frame->num_partials() == 0);
- frame->max_partials(100);
- }
- void test_add_peak() {
- Peak p = Peak();
- p.amplitude = 1.5;
- frame->add_peak(&p);
- 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);
- CPPUNIT_ASSERT(frame->max_peaks() == 100);
- CPPUNIT_ASSERT(frame->num_peaks() == 2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, frame->peak(1)->amplitude, PRECISION);
-
- frame->clear();
- }
+void TestFrame::setUp() {
+ frame = new Frame();
+}
- void test_clear() {
- Peak p = Peak();
- p.amplitude = 1.5;
- frame->add_peak(&p);
- CPPUNIT_ASSERT(frame->num_peaks() == 1);
- frame->clear();
- CPPUNIT_ASSERT(frame->num_peaks() == 0);
- }
+void TestFrame::tearDown() {
+ delete frame;
+}
-public:
- void setUp() {
- frame = new Frame();
- }
+void TestFrame::test_size() {
+ frame->size(1024);
+ CPPUNIT_ASSERT(frame->size() == 1024);
+ frame->size(512);
+}
- void tearDown() {
- delete frame;
- }
-};
+void TestFrame::test_max_peaks() {
+ frame->max_peaks(200);
+ CPPUNIT_ASSERT(frame->max_peaks() == 200);
+ CPPUNIT_ASSERT(frame->num_peaks() == 0);
+ frame->max_peaks(100);
+}
-} // end of namespace simpl
+void TestFrame::test_max_partials() {
+ frame->max_partials(200);
+ CPPUNIT_ASSERT(frame->max_partials() == 200);
+ CPPUNIT_ASSERT(frame->num_partials() == 0);
+ frame->max_partials(100);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestPeak);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestFrame);
+void TestFrame::test_add_peak() {
+ Peak p = Peak();
+ p.amplitude = 1.5;
+ frame->add_peak(&p);
+ 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);
+ CPPUNIT_ASSERT(frame->max_peaks() == 100);
+ CPPUNIT_ASSERT(frame->num_peaks() == 2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, frame->peak(1)->amplitude, PRECISION);
+
+ frame->clear();
+}
-int main(int arg, char **argv) {
- CppUnit::TextTestRunner runner;
- runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
- return runner.run("", false);
+void TestFrame::test_clear() {
+ Peak p = Peak();
+ p.amplitude = 1.5;
+ frame->add_peak(&p);
+ CPPUNIT_ASSERT(frame->num_peaks() == 1);
+ frame->clear();
+ CPPUNIT_ASSERT(frame->num_peaks() == 0);
}
diff --git a/tests/test_base.h b/tests/test_base.h
new file mode 100644
index 0000000..2ab20a4
--- /dev/null
+++ b/tests/test_base.h
@@ -0,0 +1,63 @@
+#ifndef TEST_BASE_H
+#define TEST_BASE_H
+
+#include <iostream>
+#include <cppunit/ui/text/TextTestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "../src/simpl/base.h"
+
+namespace simpl
+{
+
+// ---------------------------------------------------------------------------
+// TestPeak
+// ---------------------------------------------------------------------------
+class TestPeak : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestPeak);
+ CPPUNIT_TEST_SUITE_END();
+
+protected:
+ static const double PRECISION = 0.001;
+ Peak* peak;
+
+public:
+ void setUp();
+ void tearDown();
+};
+
+
+// ---------------------------------------------------------------------------
+// TestFrame
+// ---------------------------------------------------------------------------
+class TestFrame : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestFrame);
+ CPPUNIT_TEST(test_size);
+ CPPUNIT_TEST(test_max_peaks);
+ CPPUNIT_TEST(test_max_partials);
+ CPPUNIT_TEST(test_add_peak);
+ CPPUNIT_TEST(test_clear);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+ void tearDown();
+
+protected:
+ static const double PRECISION = 0.001;
+ Frame* frame;
+
+ void test_size();
+ void test_max_peaks();
+ void test_max_partials();
+ void test_add_peak();
+ void test_clear();
+};
+
+} // end of namespace simpl
+
+#endif
diff --git a/tests/test_common.h b/tests/test_common.h
new file mode 100644
index 0000000..59bab11
--- /dev/null
+++ b/tests/test_common.h
@@ -0,0 +1,15 @@
+#ifndef TEST_COMMON_H
+#define TEST_COMMON_H
+
+#include <iostream>
+#include <sndfile.hh>
+
+namespace simpl
+{
+
+static const double PRECISION = 0.001;
+static const char* TEST_AUDIO_FILE = "../tests/audio/flute.wav";
+
+} // end of namespace simpl
+
+#endif
diff --git a/tests/test_partial_tracking.cpp b/tests/test_partial_tracking.cpp
index 86cc878..4d7d7f6 100644
--- a/tests/test_partial_tracking.cpp
+++ b/tests/test_partial_tracking.cpp
@@ -1,308 +1,262 @@
-#include <iostream>
-#include <cppunit/ui/text/TextTestRunner.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/TestResultCollector.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/BriefTestProgressListener.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <sndfile.hh>
-
-#include "../src/simpl/base.h"
-#include "../src/simpl/peak_detection.h"
-#include "../src/simpl/partial_tracking.h"
-
-namespace simpl
-{
+#include "test_partial_tracking.h"
+
+using namespace simpl;
// ---------------------------------------------------------------------------
// TestMQPartialTracking
// ---------------------------------------------------------------------------
-class TestMQPartialTracking : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestMQPartialTracking);
- CPPUNIT_TEST(test_basic);
- CPPUNIT_TEST(test_peaks);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- MQPeakDetection* pd;
- MQPartialTracking* pt;
- SndfileHandle sf;
- int num_samples;
-
- void test_basic() {
- pt->reset();
- pd->hop_size(256);
- pd->frame_size(2048);
-
- 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])
- );
- 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 TestMQPartialTracking::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 TestMQPartialTracking::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 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.2;
+ 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);
+
+ frames.push_back(f);
+ peaks.push_back(p);
+ peaks.push_back(p2);
}
- void test_peaks() {
- pt->reset();
-
- Frames frames;
- Peaks peaks;
- int num_frames = 8;
-
- for(int i = 0; i < num_frames; i++) {
- Peak* p = new Peak();
- p->amplitude = 0.2;
- 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);
-
- frames.push_back(f);
- peaks.push_back(p);
- peaks.push_back(p2);
- }
-
- pt->find_partials(frames);
- for(int i = 0; i < num_frames; i++) {
- CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
- CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
- CPPUNIT_ASSERT(frames[i]->partial(0)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(0)->frequency == 220);
- CPPUNIT_ASSERT(frames[i]->partial(1)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(1)->frequency == 440);
- }
-
- for(int i = 0; i < num_frames * 2; i++) {
- delete peaks[i];
- }
-
- for(int i = 0; i < num_frames; i++) {
- delete frames[i];
- }
+ _pt.find_partials(frames);
+ for(int i = 0; i < num_frames; i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, 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);
}
-public:
- void setUp() {
- pd = new MQPeakDetection();
- pt = new MQPartialTracking();
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
+ for(int i = 0; i < num_frames * 2; i++) {
+ delete peaks[i];
}
- void tearDown() {
- delete pd;
- delete pt;
+ for(int i = 0; i < num_frames; i++) {
+ delete frames[i];
}
-};
+}
// ---------------------------------------------------------------------------
// TestSMSPartialTracking
// ---------------------------------------------------------------------------
-class TestSMSPartialTracking : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestSMSPartialTracking);
- CPPUNIT_TEST(test_basic);
- CPPUNIT_TEST(test_peaks);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- SMSPeakDetection* pd;
- SMSPartialTracking* pt;
- SndfileHandle sf;
- int num_samples;
-
- void test_basic() {
- pt->reset();
- pd->hop_size(256);
- pd->frame_size(2048);
-
- 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])
- );
- 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 TestSMSPartialTracking::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 test_peaks() {
- pt->reset();
-
- Frames frames;
- Peaks peaks;
- int num_frames = 8;
-
- for(int i = 0; i < num_frames; i++) {
- Peak* p = new Peak();
- p->amplitude = 0.2;
- 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);
-
- frames.push_back(f);
- peaks.push_back(p);
- peaks.push_back(p2);
- }
-
- pt->find_partials(frames);
- for(int i = 0; i < num_frames; i++) {
- CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
- CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
- CPPUNIT_ASSERT(frames[i]->partial(0)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(0)->frequency == 220);
- CPPUNIT_ASSERT(frames[i]->partial(1)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(1)->frequency == 440);
- }
-
- for(int i = 0; i < num_frames * 2; i++) {
- delete peaks[i];
- }
-
- for(int i = 0; i < num_frames; i++) {
- delete frames[i];
- }
+ _pt.realtime(1);
+}
+
+void TestSMSPartialTracking::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);
}
+}
-public:
- void setUp() {
- pd = new SMSPeakDetection();
- pt = new SMSPartialTracking();
- pt->realtime(1);
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
+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.2;
+ 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);
+
+ frames.push_back(f);
+ peaks.push_back(p);
+ peaks.push_back(p2);
+ }
+
+ _pt.find_partials(frames);
+ for(int i = 0; i < num_frames; i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, 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);
}
- void tearDown() {
- delete pd;
- delete pt;
+ for(int i = 0; i < num_frames * 2; i++) {
+ delete peaks[i];
}
-};
+
+ for(int i = 0; i < num_frames; i++) {
+ delete frames[i];
+ }
+}
+
// ---------------------------------------------------------------------------
// TestLorisPartialTracking
// ---------------------------------------------------------------------------
-class TestLorisPartialTracking : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestLorisPartialTracking);
- CPPUNIT_TEST(test_basic);
- CPPUNIT_TEST(test_peaks);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- LorisPeakDetection* pd;
- LorisPartialTracking* pt;
- SndfileHandle sf;
- int num_samples;
-
- void test_basic() {
- pt->reset();
- pd->hop_size(256);
- pd->frame_size(2048);
-
- 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])
- );
- 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 TestLorisPartialTracking::setUp() {
+ _sf = SndfileHandle(TEST_AUDIO_FILE);
- void test_peaks() {
- pt->reset();
-
- Frames frames;
- Peaks peaks;
- int num_frames = 8;
-
- for(int i = 0; i < num_frames; i++) {
- Peak* p = new Peak();
- p->amplitude = 0.2;
- 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);
-
- frames.push_back(f);
- peaks.push_back(p);
- peaks.push_back(p2);
- }
-
- pt->find_partials(frames);
- for(int i = 0; i < num_frames; i++) {
- CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
- CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
- CPPUNIT_ASSERT(frames[i]->partial(0)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(0)->frequency == 220);
- CPPUNIT_ASSERT(frames[i]->partial(1)->amplitude == 0.2);
- CPPUNIT_ASSERT(frames[i]->partial(1)->frequency == 440);
- }
-
- for(int i = 0; i < num_frames * 2; i++) {
- delete peaks[i];
- }
-
- for(int i = 0; i < num_frames; i++) {
- delete frames[i];
- }
+ if(_sf.error() > 0) {
+ throw Exception(std::string("Could not open audio file: ") +
+ std::string(TEST_AUDIO_FILE));
}
+}
+
+void TestLorisPartialTracking::test_basic() {
+ int hop_size = 256;
+ int frame_size = 2048;
+ int num_samples = 4096;
-public:
- void setUp() {
- pd = new LorisPeakDetection();
- pt = new LorisPartialTracking();
- sf = SndfileHandle("../tests/audio/flute.wav");
- 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 TestLorisPartialTracking::test_peaks() {
+ int num_frames = 8;
+ Frames frames;
+ Peaks peaks;
+
+ _pd.clear();
+ _pt.reset();
- void tearDown() {
- delete pd;
- delete pt;
+ for(int i = 0; i < num_frames; i++) {
+ Peak* p = new Peak();
+ p->amplitude = 0.2;
+ 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);
+
+ frames.push_back(f);
+ peaks.push_back(p);
+ peaks.push_back(p2);
}
-};
-} // end of namespace simpl
+ _pt.find_partials(frames);
+ for(int i = 0; i < num_frames; i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, 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);
+ }
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPartialTracking);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSPartialTracking);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking);
+ for(int i = 0; i < num_frames * 2; i++) {
+ delete peaks[i];
+ }
-int main(int arg, char **argv) {
- CppUnit::TextTestRunner runner;
- runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
- return runner.run("", false);
+ for(int i = 0; i < num_frames; i++) {
+ delete frames[i];
+ }
}
diff --git a/tests/test_partial_tracking.h b/tests/test_partial_tracking.h
new file mode 100644
index 0000000..bd59b7f
--- /dev/null
+++ b/tests/test_partial_tracking.h
@@ -0,0 +1,80 @@
+#ifndef TEST_PARTIAL_TRACKING_H
+#define TEST_PARTIAL_TRACKING_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "../src/simpl/base.h"
+#include "../src/simpl/peak_detection.h"
+#include "../src/simpl/partial_tracking.h"
+#include "test_common.h"
+
+namespace simpl
+{
+
+// ---------------------------------------------------------------------------
+// TestMQPartialTracking
+// ---------------------------------------------------------------------------
+class TestMQPartialTracking : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestMQPartialTracking);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST(test_peaks);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ MQPeakDetection _pd;
+ MQPartialTracking _pt;
+ SndfileHandle _sf;
+
+ void test_basic();
+ void test_peaks();
+};
+
+
+// ---------------------------------------------------------------------------
+// TestSMSPartialTracking
+// ---------------------------------------------------------------------------
+class TestSMSPartialTracking : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestSMSPartialTracking);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST(test_peaks);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ SMSPeakDetection _pd;
+ SMSPartialTracking _pt;
+ SndfileHandle _sf;
+
+ void test_basic();
+ void test_peaks();
+};
+
+// ---------------------------------------------------------------------------
+// TestLorisPartialTracking
+// ---------------------------------------------------------------------------
+class TestLorisPartialTracking : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestLorisPartialTracking);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST(test_peaks);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ LorisPeakDetection _pd;
+ LorisPartialTracking _pt;
+ SndfileHandle _sf;
+
+ void test_basic();
+ void test_peaks();
+};
+
+} // end of namespace simpl
+
+#endif
diff --git a/tests/test_peak_detection.cpp b/tests/test_peak_detection.cpp
index 4a8fab8..2f668bc 100644
--- a/tests/test_peak_detection.cpp
+++ b/tests/test_peak_detection.cpp
@@ -1,185 +1,142 @@
-#include <iostream>
-#include <cppunit/ui/text/TextTestRunner.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/TestResultCollector.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/BriefTestProgressListener.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <sndfile.hh>
+#include "test_peak_detection.h"
-#include "../src/simpl/base.h"
-#include "../src/simpl/peak_detection.h"
-
-namespace simpl
-{
+using 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 TestMQPeakDetection::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 test_find_peaks_basic() {
- sample* audio = new sample[1024];
- pd->frame_size(512);
+void TestMQPeakDetection::test_find_peaks_in_frame_basic() {
+ int frame_size = 2048;
- 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);
- }
+ _pd.clear();
+ _pd.frame_size(frame_size);
- delete [] audio;
- }
+ Frame f = Frame(frame_size, true);
+ Peaks p = _pd.find_peaks_in_frame(&f);
+ CPPUNIT_ASSERT(p.size() == 0);
+}
+
+void TestMQPeakDetection::test_find_peaks_basic() {
+ int frame_size = 512;
+ std::vector<sample> audio(frame_size * 2, 0.0);
- void test_find_peaks_change_hop_frame_size() {
- sample* audio = new sample[1024];
- pd->frame_size(256);
- pd->hop_size(256);
+ _pd.clear();
+ _pd.frame_size(frame_size);
- 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);
- }
+ Frames frames = _pd.find_peaks(audio.size(), &audio[0]);
- delete [] audio;
+ CPPUNIT_ASSERT(frames.size() == 2);
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() == 0);
}
+}
- void test_find_peaks_audio() {
- sample* audio = new sample[(int)sf.frames()];
- sf.read(audio, (int)sf.frames());
+void TestMQPeakDetection::test_find_peaks_audio() {
+ int num_frames = 5;
+ int num_samples = _pd.frame_size() + (_pd.hop_size() * num_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);
- }
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
- delete [] audio;
+ _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);
}
+}
-public:
- void setUp() {
- pd = new MQPeakDetection();
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
- }
+void TestMQPeakDetection::test_find_peaks_change_hop_frame_size() {
+ int num_samples = 1024;
+ std::vector<sample> audio(num_samples, 0.0);
- void tearDown() {
- delete pd;
+ _pd.clear();
+ _pd.frame_size(256);
+ _pd.hop_size(256);
+
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ CPPUNIT_ASSERT(frames.size() == 4);
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() == 0);
}
-};
+}
+
// ---------------------------------------------------------------------------
// TestLorisPeakDetection
// ---------------------------------------------------------------------------
-class TestLorisPeakDetection : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestLorisPeakDetection);
- 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;
- LorisPeakDetection* 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);
- }
+void TestLorisPeakDetection::setUp() {
+ _sf = SndfileHandle(TEST_AUDIO_FILE);
- delete [] audio;
+ if(_sf.error() > 0) {
+ throw Exception(std::string("Could not open audio file: ") +
+ std::string(TEST_AUDIO_FILE));
}
+}
- void test_find_peaks_change_hop_frame_size() {
- sample* audio = new sample[1024];
- pd->frame_size(256);
- pd->hop_size(256);
+void TestLorisPeakDetection::test_find_peaks_in_frame_basic() {
+ int frame_size = 2048;
- 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);
- }
+ _pd.clear();
+ _pd.frame_size(frame_size);
- delete [] audio;
- }
+ Frame f = Frame(frame_size, true);
+ Peaks p = _pd.find_peaks_in_frame(&f);
+ CPPUNIT_ASSERT(p.size() == 0);
+}
- void test_find_peaks_audio() {
- sample* audio = new sample[(int)sf.frames()];
- sf.read(audio, (int)sf.frames());
+void TestLorisPeakDetection::test_find_peaks_basic() {
+ int frame_size = 512;
+ std::vector<sample> audio(frame_size * 2, 0.0);
- 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);
- }
+ _pd.clear();
+ _pd.frame_size(frame_size);
- delete [] audio;
- }
+ Frames frames = _pd.find_peaks(audio.size(), &audio[0]);
-public:
- void setUp() {
- pd = new LorisPeakDetection();
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
+ CPPUNIT_ASSERT(frames.size() == 2);
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() == 0);
}
+}
+
+void TestLorisPeakDetection::test_find_peaks_audio() {
+ int num_frames = 5;
+ int num_samples = _pd.frame_size() + (_pd.hop_size() * num_frames);
- void tearDown() {
- delete pd;
+ 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);
}
-};
+}
-} // end of namespace simpl
+void TestLorisPeakDetection::test_find_peaks_change_hop_frame_size() {
+ int num_samples = 1024;
+ std::vector<sample> audio(num_samples, 0.0);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPeakDetection);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection);
+ _pd.clear();
+ _pd.frame_size(256);
+ _pd.hop_size(256);
-int main(int arg, char **argv) {
- CppUnit::TextTestRunner runner;
- runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
- return runner.run("", false);
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ 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
new file mode 100644
index 0000000..5b36f19
--- /dev/null
+++ b/tests/test_peak_detection.h
@@ -0,0 +1,65 @@
+#ifndef TEST_PEAK_DETECTION_H
+#define TEST_PEAK_DETECTION_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "../src/simpl/base.h"
+#include "../src/simpl/peak_detection.h"
+#include "../src/simpl/exceptions.h"
+#include "test_common.h"
+
+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_audio);
+ CPPUNIT_TEST(test_find_peaks_change_hop_frame_size);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ MQPeakDetection _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();
+};
+
+
+// ---------------------------------------------------------------------------
+// TestLorisPeakDetection
+// ---------------------------------------------------------------------------
+class TestLorisPeakDetection : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestLorisPeakDetection);
+ 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:
+ LorisPeakDetection _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/test_synthesis.cpp b/tests/test_synthesis.cpp
index fa49016..e0d5142 100644
--- a/tests/test_synthesis.cpp
+++ b/tests/test_synthesis.cpp
@@ -1,133 +1,82 @@
-#include <iostream>
-#include <cppunit/ui/text/TextTestRunner.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/TestResultCollector.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/BriefTestProgressListener.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <sndfile.hh>
-
-#include "../src/simpl/base.h"
-#include "../src/simpl/peak_detection.h"
-#include "../src/simpl/partial_tracking.h"
-#include "../src/simpl/synthesis.h"
-
-namespace simpl
-{
+#include "test_synthesis.h"
+
+using namespace simpl;
// ---------------------------------------------------------------------------
// TestMQSynthesis
// ---------------------------------------------------------------------------
-class TestMQSynthesis : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestMQSynthesis);
- CPPUNIT_TEST(test_basic);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- MQPeakDetection* pd;
- MQPartialTracking* pt;
- MQSynthesis* synth;
- SndfileHandle sf;
- int num_samples;
-
- void test_basic() {
- 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]));
- frames = pt->find_partials(frames);
- frames = synth->synth(frames);
-
- for(int i = 0; i < frames.size(); i++) {
- CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
- CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
-
- double energy = 0.f;
- for(int j = 0; j < synth->hop_size(); j++) {
- energy += frames[i]->synth()[j] * frames[i]->synth()[j];
- }
- CPPUNIT_ASSERT(energy > 0.f);
- }
- }
+void TestMQSynthesis::setUp() {
+ _sf = SndfileHandle(TEST_AUDIO_FILE);
-public:
- void setUp() {
- pd = new MQPeakDetection();
- pt = new MQPartialTracking();
- synth = new MQSynthesis();
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
+ if(_sf.error() > 0) {
+ throw Exception(std::string("Could not open audio file: ") +
+ std::string(TEST_AUDIO_FILE));
}
+}
+
+void TestMQSynthesis::test_basic() {
+ int num_samples = 4096;
- void tearDown() {
- delete pd;
- delete pt;
- delete synth;
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
+
+ _pd.clear();
+ _pt.reset();
+ _synth.reset();
+
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ frames = _pt.find_partials(frames);
+ frames = _synth.synth(frames);
+
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
+
+ double energy = 0.f;
+ for(int j = 0; j < _synth.hop_size(); j++) {
+ energy += frames[i]->synth()[j] * frames[i]->synth()[j];
+ }
+ CPPUNIT_ASSERT(energy > 0.f);
}
-};
+}
+
// ---------------------------------------------------------------------------
// TestLorisSynthesis
// ---------------------------------------------------------------------------
-class TestLorisSynthesis : public CPPUNIT_NS::TestCase {
- CPPUNIT_TEST_SUITE(TestLorisSynthesis);
- CPPUNIT_TEST(test_basic);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- static const double PRECISION = 0.001;
- LorisPeakDetection* pd;
- LorisPartialTracking* pt;
- LorisSynthesis* synth;
- SndfileHandle sf;
- int num_samples;
-
- void test_basic() {
- 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]));
- frames = pt->find_partials(frames);
- frames = synth->synth(frames);
-
- for(int i = 0; i < frames.size(); i++) {
- // if Loris thinPeaks is used, final frame will have no peaks
- // so don't check it
- if(i < frames.size() - 1) {
- CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
- CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
- }
-
- double energy = 0.f;
- for(int j = 0; j < synth->hop_size(); j++) {
- energy += frames[i]->synth()[j] * frames[i]->synth()[j];
- }
- CPPUNIT_ASSERT(energy > 0.f);
- }
- }
+void TestLorisSynthesis::setUp() {
+ _sf = SndfileHandle(TEST_AUDIO_FILE);
-public:
- void setUp() {
- pd = new LorisPeakDetection();
- pt = new LorisPartialTracking();
- synth = new LorisSynthesis();
- sf = SndfileHandle("../tests/audio/flute.wav");
- num_samples = 4096;
+ if(_sf.error() > 0) {
+ throw Exception(std::string("Could not open audio file: ") +
+ std::string(TEST_AUDIO_FILE));
}
+}
- void tearDown() {
- delete pd;
- delete pt;
- delete synth;
- }
-};
+void TestLorisSynthesis::test_basic() {
+ int num_samples = 4096;
+
+ std::vector<sample> audio(_sf.frames(), 0.0);
+ _sf.read(&audio[0], (int)_sf.frames());
+
+ _pd.clear();
+ _pt.reset();
+ _synth.reset();
-} // end of namespace simpl
+ Frames frames = _pd.find_peaks(num_samples,
+ &(audio[(int)_sf.frames() / 2]));
+ frames = _pt.find_partials(frames);
+ frames = _synth.synth(frames);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis);
-CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis);
+ for(int i = 0; i < frames.size(); i++) {
+ CPPUNIT_ASSERT(frames[i]->num_peaks() > 0);
+ CPPUNIT_ASSERT(frames[i]->num_partials() > 0);
-int main(int arg, char **argv) {
- CppUnit::TextTestRunner runner;
- runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
- return runner.run("", false);
+ double energy = 0.f;
+ for(int j = 0; j < _synth.hop_size(); j++) {
+ energy += frames[i]->synth()[j] * frames[i]->synth()[j];
+ }
+ CPPUNIT_ASSERT(energy > 0.f);
+ }
}
diff --git a/tests/test_synthesis.h b/tests/test_synthesis.h
new file mode 100644
index 0000000..64ee65c
--- /dev/null
+++ b/tests/test_synthesis.h
@@ -0,0 +1,57 @@
+#ifndef TEST_SYNTHESIS_H
+#define TEST_SYNTHESIS_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "../src/simpl/base.h"
+#include "../src/simpl/peak_detection.h"
+#include "../src/simpl/partial_tracking.h"
+#include "../src/simpl/synthesis.h"
+#include "test_common.h"
+
+namespace simpl
+{
+
+// ---------------------------------------------------------------------------
+// TestMQSynthesis
+// ---------------------------------------------------------------------------
+class TestMQSynthesis : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestMQSynthesis);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ MQPeakDetection _pd;
+ MQPartialTracking _pt;
+ MQSynthesis _synth;
+ SndfileHandle _sf;
+
+ void test_basic();
+};
+
+// ---------------------------------------------------------------------------
+// TestLorisSynthesis
+// ---------------------------------------------------------------------------
+class TestLorisSynthesis : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestLorisSynthesis);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+
+protected:
+ LorisPeakDetection _pd;
+ LorisPartialTracking _pt;
+ LorisSynthesis _synth;
+ SndfileHandle _sf;
+
+ void test_basic();
+};
+
+} // end of namespace simpl
+
+#endif
diff --git a/tests/tests.cpp b/tests/tests.cpp
new file mode 100644
index 0000000..d13b4f7
--- /dev/null
+++ b/tests/tests.cpp
@@ -0,0 +1,24 @@
+#include <cppunit/ui/text/TextTestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "test_base.h"
+#include "test_peak_detection.h"
+#include "test_partial_tracking.h"
+#include "test_synthesis.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestPeak);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestFrame);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPeakDetection);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPeakDetection);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQPartialTracking);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestSMSPartialTracking);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis);
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis);
+
+int main(int arg, char **argv) {
+ CppUnit::TextTestRunner runner;
+ runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
+ return runner.run("", false);
+}