Remove lxvst variable from wscript that was no longer in use
[ardour.git] / libs / ardour / test / interpolation_test.cc
1 #include <sigc++/sigc++.h>
2 #include "interpolation_test.h"
3
4 CPPUNIT_TEST_SUITE_REGISTRATION(InterpolationTest);
5
6 using namespace std;
7 using namespace ARDOUR;
8
9 void
10 InterpolationTest::linearInterpolationTest ()
11 {
12         framecnt_t result = 0;
13 //      cout << "\nLinear Interpolation Test\n";
14
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);
20                 i += result;
21         }
22
23 //      cout << "\nSpeed: 1.0";
24         linear.reset();
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]);
31         }
32
33 //      cout << "\nSpeed: 0.5";
34         linear.reset();
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]);
41         }
42
43 //      cout << "\nSpeed: 0.2";
44         linear.reset();
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);
49
50 //      cout << "\nSpeed: 0.02";
51         linear.reset();
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);
56
57 //      cout << "\nSpeed: 0.002";
58         linear.reset();
59         linear.set_speed (0.002);
60         linear.set_target_speed (linear.speed());
61         result = linear.interpolate (0, NUM_SAMPLES, input, output);
62         linear.speed();
63         CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * linear.speed()), result);
64
65 //      cout << "\nSpeed: 2.0";
66         linear.reset();
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]);
73         }
74
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]);
82         }
83         /*
84            for (int i=0; i < NUM_SAMPLES; ++i) {
85            cout  << i << " " << output[i] << endl; 
86            }
87            */
88 }
89
90 void
91 InterpolationTest::cubicInterpolationTest ()
92 {
93         framecnt_t result = 0;
94 //      cout << "\nCubic Interpolation Test\n";
95
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);
101                 i += result;
102         }
103
104 //      cout << "\nSpeed: 1.0";
105         cubic.reset();
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]);
112         }
113
114 //      cout << "\nSpeed: 0.5";
115         cubic.reset();
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]);
122         }
123
124 //      cout << "\nSpeed: 0.2";
125         cubic.reset();
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);
130
131 //      cout << "\nSpeed: 0.02";
132         cubic.reset();
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);
137
138         /* This one fails due too error accumulation
139            cout << "\nSpeed: 0.002";
140            cubic.reset();
141            cubic.set_speed (0.002);
142            cubic.set_target_speed (cubic.speed());
143            result = cubic.interpolate (0, NUM_SAMPLES, input, output);
144            cubic.speed();
145            CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
146            */
147
148 //      cout << "\nSpeed: 2.0";
149         cubic.reset();
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]);
156         }
157
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]);
165         }
166 }