summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-08-22 16:44:52 +0100
committerJohn Glover <j@johnglover.net>2012-08-22 16:44:52 +0100
commite4ab5141d33d0c94a1c82091a02cfc7ecffc65fd (patch)
tree1279128c939768c209dbffb94419ec5c8e54cefb /tests
parent5fb34d7d5451cefd88bb9d7a0d9c442d67caf143 (diff)
downloadsimpl-e4ab5141d33d0c94a1c82091a02cfc7ecffc65fd.tar.gz
simpl-e4ab5141d33d0c94a1c82091a02cfc7ecffc65fd.tar.bz2
simpl-e4ab5141d33d0c94a1c82091a02cfc7ecffc65fd.zip
[loris] Add C++ implementation of LorisPartialTracking.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_partial_tracking.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/test_partial_tracking.cpp b/tests/test_partial_tracking.cpp
new file mode 100644
index 0000000..25fcfff
--- /dev/null
+++ b/tests/test_partial_tracking.cpp
@@ -0,0 +1,65 @@
+#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
+{
+
+// ---------------------------------------------------------------------------
+// TestLorisPartialTracking
+// ---------------------------------------------------------------------------
+class TestLorisPartialTracking : public CPPUNIT_NS::TestCase {
+ CPPUNIT_TEST_SUITE(TestLorisPartialTracking);
+ CPPUNIT_TEST(test_basic);
+ CPPUNIT_TEST_SUITE_END();
+
+protected:
+ static const double PRECISION = 0.001;
+ LorisPeakDetection* pd;
+ LorisPartialTracking* pt;
+ 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);
+
+ 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 LorisPeakDetection();
+ pt = new LorisPartialTracking();
+ sf = SndfileHandle("../tests/audio/flute.wav");
+ num_samples = 4096;
+ }
+
+ void tearDown() {
+ delete pd;
+ }
+};
+
+} // end of namespace simpl
+
+CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisPartialTracking);
+
+int main(int arg, char **argv) {
+ CppUnit::TextTestRunner runner;
+ runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
+ return runner.run("", false);
+}