1 #include <sigc++/sigc++.h>
2 #include "interpolation_test.h"
4 CPPUNIT_TEST_SUITE_REGISTRATION(InterpolationTest);
7 using namespace ARDOUR;
10 InterpolationTest::linearInterpolationTest ()
12 framecnt_t result = 0;
13 // cout << "\nLinear Interpolation Test\n";
15 // cout << "\nSpeed: 1/3";
16 for (int i = 0; 3*i < NUM_SAMPLES - 1024;) {
17 linear.set_speed (double(1.0)/double(3.0));
18 linear.set_target_speed (double(1.0)/double(3.0));
19 result = linear.interpolate (0, 1024, input + i, output + i*3);
23 // cout << "\nSpeed: 1.0";
25 linear.set_speed (1.0);
26 linear.set_target_speed (linear.speed());
27 result = linear.interpolate (0, NUM_SAMPLES, input, output);
28 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
29 for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) {
30 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
33 // cout << "\nSpeed: 0.5";
35 linear.set_speed (0.5);
36 linear.set_target_speed (linear.speed());
37 result = linear.interpolate (0, NUM_SAMPLES, input, output);
38 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
39 for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / linear.speed() +0.5)) {
40 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
43 // cout << "\nSpeed: 0.2";
45 linear.set_speed (0.2);
46 linear.set_target_speed (linear.speed());
47 result = linear.interpolate (0, NUM_SAMPLES, input, output);
48 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
50 // cout << "\nSpeed: 0.02";
52 linear.set_speed (0.02);
53 linear.set_target_speed (linear.speed());
54 result = linear.interpolate (0, NUM_SAMPLES, input, output);
55 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
57 // cout << "\nSpeed: 0.002";
59 linear.set_speed (0.002);
60 linear.set_target_speed (linear.speed());
61 result = linear.interpolate (0, NUM_SAMPLES, input, output);
63 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
65 // cout << "\nSpeed: 2.0";
67 linear.set_speed (2.0);
68 linear.set_target_speed (linear.speed());
69 result = linear.interpolate (0, NUM_SAMPLES / 2, input, output);
70 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 2 * linear.speed()), result);
71 for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / linear.speed() +0.5)) {
72 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
75 // cout << "\nSpeed: 10.0";
76 linear.set_speed (10.0);
77 linear.set_target_speed (linear.speed());
78 result = linear.interpolate (0, NUM_SAMPLES / 10, input, output);
79 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 10 * linear.speed()), result);
80 for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / linear.speed() +0.5)) {
81 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
84 for (int i=0; i < NUM_SAMPLES; ++i) {
85 cout << i << " " << output[i] << endl;
91 InterpolationTest::cubicInterpolationTest ()
93 framecnt_t result = 0;
94 // cout << "\nCubic Interpolation Test\n";
96 // cout << "\nSpeed: 1/3";
97 for (int i = 0; 3*i < NUM_SAMPLES - 1024;) {
98 cubic.set_speed (double(1.0)/double(3.0));
99 cubic.set_target_speed (double(1.0)/double(3.0));
100 result = cubic.interpolate (0, 1024, input + i, output + i*3);
104 // cout << "\nSpeed: 1.0";
106 cubic.set_speed (1.0);
107 cubic.set_target_speed (cubic.speed());
108 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
109 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
110 for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) {
111 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
114 // cout << "\nSpeed: 0.5";
116 cubic.set_speed (0.5);
117 cubic.set_target_speed (cubic.speed());
118 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
119 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
120 for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / cubic.speed() +0.5)) {
121 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
124 // cout << "\nSpeed: 0.2";
126 cubic.set_speed (0.2);
127 cubic.set_target_speed (cubic.speed());
128 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
129 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
131 // cout << "\nSpeed: 0.02";
133 cubic.set_speed (0.02);
134 cubic.set_target_speed (cubic.speed());
135 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
136 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
138 /* This one fails due too error accumulation
139 cout << "\nSpeed: 0.002";
141 cubic.set_speed (0.002);
142 cubic.set_target_speed (cubic.speed());
143 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
145 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
148 // cout << "\nSpeed: 2.0";
150 cubic.set_speed (2.0);
151 cubic.set_target_speed (cubic.speed());
152 result = cubic.interpolate (0, NUM_SAMPLES / 2, input, output);
153 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 2 * cubic.speed()), result);
154 for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / cubic.speed() +0.5)) {
155 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
158 // cout << "\nSpeed: 10.0";
159 cubic.set_speed (10.0);
160 cubic.set_target_speed (cubic.speed());
161 result = cubic.interpolate (0, NUM_SAMPLES / 10, input, output);
162 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 10 * cubic.speed()), result);
163 for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / cubic.speed() +0.5)) {
164 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);