diff options
Diffstat (limited to 'libs/ardour/tests/interpolation-test.cc')
-rw-r--r-- | libs/ardour/tests/interpolation-test.cc | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/libs/ardour/tests/interpolation-test.cc b/libs/ardour/tests/interpolation-test.cc index 8b4f1f840b..5a559cc830 100644 --- a/libs/ardour/tests/interpolation-test.cc +++ b/libs/ardour/tests/interpolation-test.cc @@ -3,44 +3,71 @@ CPPUNIT_TEST_SUITE_REGISTRATION( InterpolationTest ); +using namespace std; +using namespace ARDOUR; + void InterpolationTest::linearInterpolationTest () { - std::cout << "\nLinear Interpolation Test\n"; - std::cout << "\nSpeed: 1.0"; + cout << "\nLinear Interpolation Test\n"; + cout << "\nSpeed: 1.0"; linear.set_speed (1.0); + linear.set_target_speed (linear.speed()); nframes_t result = linear.interpolate (NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES - 1, result); - - std::cout << "\nSpeed: 0.5"; + 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.set_speed (0.5); + linear.set_target_speed (linear.speed()); result = linear.interpolate (NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES / 2 - 1, result); - - std::cout << "\nSpeed: 0.2"; + 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.set_speed (0.2); + linear.set_target_speed (linear.speed()); result = linear.interpolate (NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES / 5 - 2, result); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - std::cout << "\nSpeed: 0.02"; + cout << "\nSpeed: 0.02"; linear.set_speed (0.02); + linear.set_target_speed (linear.speed()); result = linear.interpolate (NUM_SAMPLES, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES / 50 - 2, result); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); - std::cout << "\nSpeed: 2.0"; + cout << "\nSpeed: 0.002"; + linear.set_speed (0.002); + linear.set_target_speed (linear.speed()); + result = linear.interpolate (NUM_SAMPLES, input, output); + CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * linear.speed()), result); + + cout << "\nSpeed: 2.0"; linear.set_speed (2.0); + linear.set_target_speed (linear.speed()); result = linear.interpolate (NUM_SAMPLES / 2, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES - 2, result); + 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]); + } -/* - for (int i=0; i < NUM_SAMPLES / 5; ++i) { - std::cout << "input[" << i << "] = " << input[i] << " output[" << i << "] = " << output[i] << std::endl; - } -*/ - std::cout << "\nSpeed: 10.0"; + cout << "\nSpeed: 10.0"; linear.set_speed (10.0); + linear.set_target_speed (linear.speed()); result = linear.interpolate (NUM_SAMPLES / 10, input, output); - CPPUNIT_ASSERT_EQUAL ((uint32_t)NUM_SAMPLES - 10, result); + 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 << "input[" << i << "] = " << input[i] << " output[" << i << "] = " << output[i] << endl; + } + */ } |