diff options
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) { |