summaryrefslogtreecommitdiff
path: root/libs/ardour/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour/tests')
-rw-r--r--libs/ardour/tests/interpolation-test.cc192
-rw-r--r--libs/ardour/tests/interpolation-test.h15
2 files changed, 70 insertions, 137 deletions
diff --git a/libs/ardour/tests/interpolation-test.cc b/libs/ardour/tests/interpolation-test.cc
index 6a5bcd5ed4..45e350d12b 100644
--- a/libs/ardour/tests/interpolation-test.cc
+++ b/libs/ardour/tests/interpolation-test.cc
@@ -16,10 +16,7 @@ InterpolationTest::linearInterpolationTest ()
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));
- //printf ("Interpolate: input: %d, output: %d, i: %d\n", input + i, output + i, i);
result = linear.interpolate (0, 1024, input + i, output + i*3);
- //printf ("Result: %d\n", result);
- //CPPUNIT_ASSERT_EQUAL ((uint32_t)((NUM_SAMPLES - 100) * interpolation.speed()), result);
i += result;
}
@@ -87,146 +84,87 @@ InterpolationTest::linearInterpolationTest ()
}
/*
for (int i=0; i < NUM_SAMPLES; ++i) {
- cout << "input[" << i << "] = " << input[i] << " output[" << i << "] = " << output[i] << endl;
- }
- */
+ cout << i << " " << output[i] << endl;
+ }
+ */
}
void
-InterpolationTest::splineInterpolationTest ()
+InterpolationTest::cubicInterpolationTest ()
{
nframes_t result = 0;
- cout << "\nspline Interpolation Test\n";
-
- cout << "\nSpeed: 1/2" << endl;
- spline.reset();
- spline.set_speed (0.5);
- int one_period = 1024;
-
- /*
-
- for (int i = 0; 2 * i < NUM_SAMPLES - one_period;) {
- result = spline.interpolate (0, one_period, input + i, output + 2*i);
+ 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;
}
- for (int i=0; i < NUM_SAMPLES - one_period; ++i) {
- //cout << "input[" << i << "] = " << input[i] << " output[" << i << "] = " << output[i] << endl;
- if (i % 200 == 0) { CPPUNIT_ASSERT_EQUAL (double(1.0), double(output[i])); }
- else if (i % 2 == 0) { CPPUNIT_ASSERT_EQUAL (double(0.0), double(output[i])); }
- }
- */
+ 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]);
+ }
- // square wave
- for (int i = 0; i < NUM_SAMPLES; ++i) {
- if (i % (INTERVAL/2) < INTERVAL/4 ) {
- input[i] = 1.0f;
- } else {
- input[i] = 0.0f;
- }
- output[i] = 0.0f;
+ 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);
- /*
- //sine wave
- for (int i = 0; i < NUM_SAMPLES; ++i) {
- input[i] = sin(double(i) * M_2_PI / INTERVAL * 10.0);
- }
+ /* 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);
*/
- one_period = 512;
-
- cout << "\nSpeed: 1/60" << endl;
- spline.reset();
- spline.set_speed (1.0/90.0);
-
-
- for (int i = 0, o = 0; 90 * i < NUM_SAMPLES - one_period; o++) {
- result = spline.interpolate (0, one_period, input + i, output + o * one_period);
- //printf ("Result: %d\n", result);
- i += result;
- }
-
- for (int i=0; i < NUM_SAMPLES - one_period; ++i) {
- cout << i << " " << output[i] << endl;
- //if (i % 333 == 0) { CPPUNIT_ASSERT_EQUAL (double(1.0), double(output[i])); }
- //else if (i % 2 == 0) { CPPUNIT_ASSERT_EQUAL (double(0.0), double(output[i])); }
+ 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]);
}
-}
-
-void
-InterpolationTest::libSamplerateInterpolationTest ()
-{
- nframes_t result;
-
- cout << "\nLibSamplerate Interpolation Test\n";
-/*
- cout << "\nSpeed: 1.0";
- interpolation.set_speed (1.0);
- for (int i = 0; i < NUM_SAMPLES;) {
- interpolation.set_speed (1.0);
- result = interpolation.interpolate (0, INTERVAL/10, input + i, output + i);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(INTERVAL/10 * interpolation.speed()), result);
- i += result;
- }
-
- for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) {
- CPPUNIT_ASSERT_EQUAL (1.0f, output[i+1]);
- }
-*/
-
- cout << "\nSpeed: 0.5";
- for (int i = 0; i < NUM_SAMPLES;) {
- interpolation.set_speed (0.5);
- //printf ("Interpolate: input: %d, output: %d, i: %d\n", input + i, output + i, i);
- result = interpolation.interpolate (0, NUM_SAMPLES - 100, input + i, output + i);
- printf ("Result: %d\n", result);
- //CPPUNIT_ASSERT_EQUAL ((uint32_t)((NUM_SAMPLES - 100) * interpolation.speed()), result);
- //i += result;
- break;
- }
-
- for (int i=0; i < NUM_SAMPLES; ++i) {
- cout << "input[" << i << "] = " << input[i] << " output[" << i << "] = " << output[i] << endl;
- }
-
- cout << "\nSpeed: 0.2";
- interpolation.set_speed (0.2);
- result = interpolation.interpolate (0, NUM_SAMPLES, input, output);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * interpolation.speed()), result);
-
- cout << "\nSpeed: 0.02";
- interpolation.set_speed (0.02);
- result = interpolation.interpolate (0, NUM_SAMPLES, input, output);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * interpolation.speed()), result);
-
- cout << "\nSpeed: 0.002";
- interpolation.set_speed (0.002);
- result = interpolation.interpolate (0, NUM_SAMPLES, input, output);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES * interpolation.speed()), result);
-
- cout << "\nSpeed: 2.0";
- interpolation.set_speed (2.0);
- result = interpolation.interpolate (0, NUM_SAMPLES / 2, input, output);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 2 * interpolation.speed()), result);
- for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / interpolation.speed() +0.5)) {
- CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
- }
-
- cout << "\nSpeed: 10.0";
- interpolation.set_speed (10.0);
- result = interpolation.interpolate (0, NUM_SAMPLES / 10, input, output);
- CPPUNIT_ASSERT_EQUAL ((uint32_t)(NUM_SAMPLES / 10 * interpolation.speed()), result);
- for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / interpolation.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;
- }
- */
+ 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
index 07cc3ab4f7..639c8fc956 100644
--- a/libs/ardour/tests/interpolation-test.h
+++ b/libs/ardour/tests/interpolation-test.h
@@ -26,9 +26,8 @@
class InterpolationTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(InterpolationTest);
- CPPUNIT_TEST(splineInterpolationTest);
- //CPPUNIT_TEST(linearInterpolationTest);
- //CPPUNIT_TEST(libSamplerateInterpolationTest);
+ CPPUNIT_TEST(cubicInterpolationTest);
+ CPPUNIT_TEST(linearInterpolationTest);
CPPUNIT_TEST_SUITE_END();
#define NUM_SAMPLES 1000000
@@ -38,8 +37,7 @@ class InterpolationTest : public CppUnit::TestFixture
ARDOUR::Sample output[NUM_SAMPLES];
ARDOUR::LinearInterpolation linear;
- ARDOUR::SplineInterpolation spline;
- ARDOUR::LibSamplerateInterpolation interpolation;
+ ARDOUR::CubicInterpolation cubic;
public:
@@ -53,15 +51,12 @@ class InterpolationTest : public CppUnit::TestFixture
output[i] = 0.0f;
}
linear.add_channel_to (NUM_SAMPLES, NUM_SAMPLES);
- spline.add_channel_to (NUM_SAMPLES, NUM_SAMPLES);
- interpolation.add_channel_to (NUM_SAMPLES, NUM_SAMPLES);
+ cubic.add_channel_to (NUM_SAMPLES, NUM_SAMPLES);
}
void tearDown() {
}
void linearInterpolationTest();
- void splineInterpolationTest();
- void libSamplerateInterpolationTest();
-
+ void cubicInterpolationTest();
};