From a2e73bc5f7d7891874fa31c02d861fd31850cc3d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 27 Oct 2009 16:07:03 +0000 Subject: ardour/tests => ardour/test (consistency with evoral). git-svn-id: svn://localhost/ardour2/branches/3.0@5941 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/test/interpolation-test.cc | 170 ++++++++++++++++++++++++++++++++ libs/ardour/test/interpolation-test.h | 62 ++++++++++++ libs/ardour/test/testrunner.cpp | 27 +++++ libs/ardour/tests/interpolation-test.cc | 170 -------------------------------- libs/ardour/tests/interpolation-test.h | 62 ------------ libs/ardour/tests/testrunner.cpp | 27 ----- 6 files changed, 259 insertions(+), 259 deletions(-) create mode 100644 libs/ardour/test/interpolation-test.cc create mode 100644 libs/ardour/test/interpolation-test.h create mode 100644 libs/ardour/test/testrunner.cpp delete mode 100644 libs/ardour/tests/interpolation-test.cc delete mode 100644 libs/ardour/tests/interpolation-test.h delete mode 100644 libs/ardour/tests/testrunner.cpp diff --git a/libs/ardour/test/interpolation-test.cc b/libs/ardour/test/interpolation-test.cc new file mode 100644 index 0000000000..45e350d12b --- /dev/null +++ b/libs/ardour/test/interpolation-test.cc @@ -0,0 +1,170 @@ +#include +#include "interpolation-test.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( InterpolationTest ); + +using namespace std; +using namespace ARDOUR; + +void +InterpolationTest::linearInterpolationTest () +{ + nframes_t result = 0; + cout << "\nLinear Interpolation Test\n"; + + cout << "\nSpeed: 1/3"; + for (int i = 0; 3*i < NUM_SAMPLES - 1024;) { + linear.set_speed (double(1.0)/double(3.0)); + linear.set_target_speed (double(1.0)/double(3.0)); + result = linear.interpolate (0, 1024, input + i, output + i*3); + i += result; + } + + cout << "\nSpeed: 1.0"; + linear.reset(); + linear.set_speed (1.0); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); + for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 0.5"; + linear.reset(); + linear.set_speed (0.5); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); + for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / linear.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 0.2"; + linear.reset(); + linear.set_speed (0.2); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); + + cout << "\nSpeed: 0.02"; + linear.reset(); + linear.set_speed (0.02); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); + + /* This one fails due too error accumulation + cout << "\nSpeed: 0.002"; + linear.reset(); + linear.set_speed (0.002); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES, input, output); + linear.speed(); + CPPUNIT_ASSERT_EQUAL ((nframes_t)(NUM_SAMPLES * linear.speed()), result); + */ + + cout << "\nSpeed: 2.0"; + linear.reset(); + linear.set_speed (2.0); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES / 2, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 2 * linear.speed()), result); + for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / linear.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 10.0"; + linear.set_speed (10.0); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (0, NUM_SAMPLES / 10, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 10 * linear.speed()), result); + for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / linear.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + /* + for (int i=0; i < NUM_SAMPLES; ++i) { + cout << i << " " << output[i] << endl; + } + */ +} + +void +InterpolationTest::cubicInterpolationTest () +{ + nframes_t result = 0; + cout << "\nCubic Interpolation Test\n"; + + cout << "\nSpeed: 1/3"; + for (int i = 0; 3*i < NUM_SAMPLES - 1024;) { + cubic.set_speed (double(1.0)/double(3.0)); + cubic.set_target_speed (double(1.0)/double(3.0)); + result = cubic.interpolate (0, 1024, input + i, output + i*3); + i += result; + } + + cout << "\nSpeed: 1.0"; + cubic.reset(); + cubic.set_speed (1.0); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); + for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 0.5"; + cubic.reset(); + cubic.set_speed (0.5); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); + for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / cubic.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 0.2"; + cubic.reset(); + cubic.set_speed (0.2); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); + + cout << "\nSpeed: 0.02"; + cubic.reset(); + cubic.set_speed (0.02); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); + + /* This one fails due too error accumulation + cout << "\nSpeed: 0.002"; + cubic.reset(); + cubic.set_speed (0.002); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES, input, output); + cubic.speed(); + CPPUNIT_ASSERT_EQUAL ((nframes_t)(NUM_SAMPLES * cubic.speed()), result); + */ + + cout << "\nSpeed: 2.0"; + cubic.reset(); + cubic.set_speed (2.0); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES / 2, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 2 * cubic.speed()), result); + for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / cubic.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } + + cout << "\nSpeed: 10.0"; + cubic.set_speed (10.0); + cubic.set_target_speed (cubic.speed()); + result = cubic.interpolate (0, NUM_SAMPLES / 10, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 10 * cubic.speed()), result); + for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / cubic.speed() +0.5)) { + CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); + } +} + + diff --git a/libs/ardour/test/interpolation-test.h b/libs/ardour/test/interpolation-test.h new file mode 100644 index 0000000000..639c8fc956 --- /dev/null +++ b/libs/ardour/test/interpolation-test.h @@ -0,0 +1,62 @@ +/* + * Copyright(C) 2000-2008 Paul Davis + * Author: Hans Baier + * + * Evoral is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or(at your option) any later + * version. + * + * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "ardour/interpolation.h" + +class InterpolationTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(InterpolationTest); + CPPUNIT_TEST(cubicInterpolationTest); + CPPUNIT_TEST(linearInterpolationTest); + CPPUNIT_TEST_SUITE_END(); + + #define NUM_SAMPLES 1000000 + #define INTERVAL 100 + + ARDOUR::Sample input[NUM_SAMPLES]; + ARDOUR::Sample output[NUM_SAMPLES]; + + ARDOUR::LinearInterpolation linear; + ARDOUR::CubicInterpolation cubic; + + public: + + void setUp() { + for (int i = 0; i < NUM_SAMPLES; ++i) { + if (i % INTERVAL == 0) { + input[i] = 1.0f; + } else { + input[i] = 0.0f; + } + output[i] = 0.0f; + } + linear.add_channel_to (NUM_SAMPLES, NUM_SAMPLES); + cubic.add_channel_to (NUM_SAMPLES, NUM_SAMPLES); + } + + void tearDown() { + } + + void linearInterpolationTest(); + void cubicInterpolationTest(); +}; diff --git a/libs/ardour/test/testrunner.cpp b/libs/ardour/test/testrunner.cpp new file mode 100644 index 0000000000..468af59ae4 --- /dev/null +++ b/libs/ardour/test/testrunner.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include + +int +main() +{ + CppUnit::TestResult testresult; + + CppUnit::TestResultCollector collectedresults; + testresult.addListener (&collectedresults); + + CppUnit::BriefTestProgressListener progress; + testresult.addListener (&progress); + + CppUnit::TestRunner testrunner; + testrunner.addTest (CppUnit::TestFactoryRegistry::getRegistry ().makeTest ()); + testrunner.run (testresult); + + CppUnit::CompilerOutputter compileroutputter (&collectedresults, std::cerr); + compileroutputter.write (); + + return collectedresults.wasSuccessful () ? 0 : 1; +} diff --git a/libs/ardour/tests/interpolation-test.cc b/libs/ardour/tests/interpolation-test.cc deleted file mode 100644 index 45e350d12b..0000000000 --- a/libs/ardour/tests/interpolation-test.cc +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include "interpolation-test.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( InterpolationTest ); - -using namespace std; -using namespace ARDOUR; - -void -InterpolationTest::linearInterpolationTest () -{ - nframes_t result = 0; - cout << "\nLinear Interpolation Test\n"; - - cout << "\nSpeed: 1/3"; - for (int i = 0; 3*i < NUM_SAMPLES - 1024;) { - linear.set_speed (double(1.0)/double(3.0)); - linear.set_target_speed (double(1.0)/double(3.0)); - result = linear.interpolate (0, 1024, input + i, output + i*3); - i += result; - } - - cout << "\nSpeed: 1.0"; - linear.reset(); - linear.set_speed (1.0); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 0.5"; - linear.reset(); - linear.set_speed (0.5); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / linear.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 0.2"; - linear.reset(); - linear.set_speed (0.2); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - - cout << "\nSpeed: 0.02"; - linear.reset(); - linear.set_speed (0.02); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - - /* This one fails due too error accumulation - cout << "\nSpeed: 0.002"; - linear.reset(); - linear.set_speed (0.002); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES, input, output); - linear.speed(); - CPPUNIT_ASSERT_EQUAL ((nframes_t)(NUM_SAMPLES * linear.speed()), result); - */ - - cout << "\nSpeed: 2.0"; - linear.reset(); - linear.set_speed (2.0); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES / 2, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 2 * linear.speed()), result); - for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / linear.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 10.0"; - linear.set_speed (10.0); - linear.set_target_speed (linear.speed()); - result = linear.interpolate (0, NUM_SAMPLES / 10, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 10 * linear.speed()), result); - for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / linear.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - /* - for (int i=0; i < NUM_SAMPLES; ++i) { - cout << i << " " << output[i] << endl; - } - */ -} - -void -InterpolationTest::cubicInterpolationTest () -{ - nframes_t result = 0; - cout << "\nCubic Interpolation Test\n"; - - cout << "\nSpeed: 1/3"; - for (int i = 0; 3*i < NUM_SAMPLES - 1024;) { - cubic.set_speed (double(1.0)/double(3.0)); - cubic.set_target_speed (double(1.0)/double(3.0)); - result = cubic.interpolate (0, 1024, input + i, output + i*3); - i += result; - } - - cout << "\nSpeed: 1.0"; - cubic.reset(); - cubic.set_speed (1.0); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); - for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 0.5"; - cubic.reset(); - cubic.set_speed (0.5); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); - for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / cubic.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 0.2"; - cubic.reset(); - cubic.set_speed (0.2); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); - - cout << "\nSpeed: 0.02"; - cubic.reset(); - cubic.set_speed (0.02); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * cubic.speed()), result); - - /* This one fails due too error accumulation - cout << "\nSpeed: 0.002"; - cubic.reset(); - cubic.set_speed (0.002); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES, input, output); - cubic.speed(); - CPPUNIT_ASSERT_EQUAL ((nframes_t)(NUM_SAMPLES * cubic.speed()), result); - */ - - cout << "\nSpeed: 2.0"; - cubic.reset(); - cubic.set_speed (2.0); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES / 2, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 2 * cubic.speed()), result); - for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / cubic.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } - - cout << "\nSpeed: 10.0"; - cubic.set_speed (10.0); - cubic.set_target_speed (cubic.speed()); - result = cubic.interpolate (0, NUM_SAMPLES / 10, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 10 * cubic.speed()), result); - for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / cubic.speed() +0.5)) { - CPPUNIT_ASSERT_EQUAL (1.0f, output[i]); - } -} - - diff --git a/libs/ardour/tests/interpolation-test.h b/libs/ardour/tests/interpolation-test.h deleted file mode 100644 index 639c8fc956..0000000000 --- a/libs/ardour/tests/interpolation-test.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright(C) 2000-2008 Paul Davis - * Author: Hans Baier - * - * Evoral is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or(at your option) any later - * version. - * - * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "ardour/interpolation.h" - -class InterpolationTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(InterpolationTest); - CPPUNIT_TEST(cubicInterpolationTest); - CPPUNIT_TEST(linearInterpolationTest); - CPPUNIT_TEST_SUITE_END(); - - #define NUM_SAMPLES 1000000 - #define INTERVAL 100 - - ARDOUR::Sample input[NUM_SAMPLES]; - ARDOUR::Sample output[NUM_SAMPLES]; - - ARDOUR::LinearInterpolation linear; - ARDOUR::CubicInterpolation cubic; - - public: - - void setUp() { - for (int i = 0; i < NUM_SAMPLES; ++i) { - if (i % INTERVAL == 0) { - input[i] = 1.0f; - } else { - input[i] = 0.0f; - } - output[i] = 0.0f; - } - linear.add_channel_to (NUM_SAMPLES, NUM_SAMPLES); - cubic.add_channel_to (NUM_SAMPLES, NUM_SAMPLES); - } - - void tearDown() { - } - - void linearInterpolationTest(); - void cubicInterpolationTest(); -}; diff --git a/libs/ardour/tests/testrunner.cpp b/libs/ardour/tests/testrunner.cpp deleted file mode 100644 index 468af59ae4..0000000000 --- a/libs/ardour/tests/testrunner.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int -main() -{ - CppUnit::TestResult testresult; - - CppUnit::TestResultCollector collectedresults; - testresult.addListener (&collectedresults); - - CppUnit::BriefTestProgressListener progress; - testresult.addListener (&progress); - - CppUnit::TestRunner testrunner; - testrunner.addTest (CppUnit::TestFactoryRegistry::getRegistry ().makeTest ()); - testrunner.run (testresult); - - CppUnit::CompilerOutputter compileroutputter (&collectedresults, std::cerr); - compileroutputter.write (); - - return collectedresults.wasSuccessful () ? 0 : 1; -} -- cgit v1.2.3