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 (result, cubic.interpolate (0, NUM_SAMPLES, NULL, NULL));
110 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
111 for (int i = 0; i < NUM_SAMPLES; i += INTERVAL) {
112 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
115 // cout << "\nSpeed: 0.5";
117 cubic.set_speed (0.5);
118 cubic.set_target_speed (cubic.speed());
119 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
120 CPPUNIT_ASSERT_EQUAL (result, cubic.interpolate (0, NUM_SAMPLES, NULL, NULL));
121 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
122 for (int i = 0; i < NUM_SAMPLES; i += (INTERVAL / cubic.speed() +0.5)) {
123 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
126 // cout << "\nSpeed: 0.2";
128 cubic.set_speed (0.2);
129 cubic.set_target_speed (cubic.speed());
130 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
131 CPPUNIT_ASSERT_EQUAL (result, cubic.interpolate (0, NUM_SAMPLES, NULL, NULL));
132 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
134 // cout << "\nSpeed: 0.02";
136 cubic.set_speed (0.02);
137 cubic.set_target_speed (cubic.speed());
138 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
139 CPPUNIT_ASSERT_EQUAL (result, cubic.interpolate (0, NUM_SAMPLES, NULL, NULL));
140 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
142 /* This one fails due too error accumulation
143 cout << "\nSpeed: 0.002";
145 cubic.set_speed (0.002);
146 cubic.set_target_speed (cubic.speed());
147 result = cubic.interpolate (0, NUM_SAMPLES, input, output);
149 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
152 // cout << "\nSpeed: 2.0";
154 cubic.set_speed (2.0);
155 cubic.set_target_speed (cubic.speed());
156 result = cubic.interpolate (0, NUM_SAMPLES / 2, input, output);
157 CPPUNIT_ASSERT_EQUAL (result, cubic.interpolate (0, NUM_SAMPLES / 2, NULL, NULL));
158 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 2 * cubic.speed()), result);
159 for (int i = 0; i < NUM_SAMPLES / 2; i += (INTERVAL / cubic.speed() +0.5)) {
160 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);
163 // cout << "\nSpeed: 10.0";
164 cubic.set_speed (10.0);
165 cubic.set_target_speed (cubic.speed());
166 result = cubic.interpolate (0, NUM_SAMPLES / 10, input, output);
167 CPPUNIT_ASSERT_EQUAL (result, cubic.interpolate (0, NUM_SAMPLES / 10, NULL, NULL));
168 CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES / 10 * cubic.speed()), result);
169 for (int i = 0; i < NUM_SAMPLES / 10; i += (INTERVAL / cubic.speed() +0.5)) {
170 CPPUNIT_ASSERT_EQUAL (1.0f, output[i]);