diff options
author | John Glover <j@johnglover.net> | 2012-10-25 09:58:30 +0200 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-10-25 09:58:30 +0200 |
commit | b08857ae522d8570e88bc773c868fb221bf708d3 (patch) | |
tree | 25abec82d9e2b9703509eec6d5a835df17124677 /tests | |
parent | 04be6d799285d7d47a2d8f8fb4a6249c6eb9e2f8 (diff) | |
download | simpl-b08857ae522d8570e88bc773c868fb221bf708d3.tar.gz simpl-b08857ae522d8570e88bc773c868fb221bf708d3.tar.bz2 simpl-b08857ae522d8570e88bc773c868fb221bf708d3.zip |
[mq] Add C++ MQSynthesis class.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_synthesis.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_synthesis.cpp b/tests/test_synthesis.cpp index 50ca6ed..fa49016 100644 --- a/tests/test_synthesis.cpp +++ b/tests/test_synthesis.cpp @@ -16,6 +16,57 @@ 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); + } + } + +public: + void setUp() { + pd = new MQPeakDetection(); + pt = new MQPartialTracking(); + synth = new MQSynthesis(); + sf = SndfileHandle("../tests/audio/flute.wav"); + num_samples = 4096; + } + + void tearDown() { + delete pd; + delete pt; + delete synth; + } +}; + +// --------------------------------------------------------------------------- // TestLorisSynthesis // --------------------------------------------------------------------------- class TestLorisSynthesis : public CPPUNIT_NS::TestCase { @@ -72,6 +123,7 @@ public: } // end of namespace simpl +CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestMQSynthesis); CPPUNIT_TEST_SUITE_REGISTRATION(simpl::TestLorisSynthesis); int main(int arg, char **argv) { |