summaryrefslogtreecommitdiff
path: root/tests/test_residual.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_residual.cpp')
-rw-r--r--tests/test_residual.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_residual.cpp b/tests/test_residual.cpp
new file mode 100644
index 0000000..a597317
--- /dev/null
+++ b/tests/test_residual.cpp
@@ -0,0 +1,51 @@
+#include "test_residual.h"
+
+using namespace simpl;
+
+// ---------------------------------------------------------------------------
+// test_basic
+// ---------------------------------------------------------------------------
+static void test_basic(Residual* residual, SndfileHandle *sf) {
+ int num_samples = 4096;
+ int hop_size = 256;
+ int frame_size = 512;
+
+ std::vector<sample> audio(sf->frames(), 0.0);
+ sf->read(&audio[0], (int)sf->frames());
+
+ residual->reset();
+ residual->frame_size(frame_size);
+ residual->hop_size(hop_size);
+
+ Frames frames = residual->synth(num_samples,
+ &(audio[(int)sf->frames() / 2]));
+
+ 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 < residual->hop_size(); j++) {
+ energy += frames[i]->synth_residual()[j] *
+ frames[i]->synth_residual()[j];
+ }
+ CPPUNIT_ASSERT(energy > 0.f);
+ }
+}
+
+
+// ---------------------------------------------------------------------------
+// TestSMSResidual
+// ---------------------------------------------------------------------------
+void TestSMSResidual::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 TestSMSResidual::test_basic() {
+ ::test_basic(&_res, &_sf);
+}