ardour
interpolation_test.cc
Go to the documentation of this file.
1 #include <sigc++/sigc++.h>
2 #include "interpolation_test.h"
3 
5 
6 using namespace std;
7 using namespace ARDOUR;
8 
9 void
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
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 (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]);
113  }
114 
115 // cout << "\nSpeed: 0.5";
116  cubic.reset();
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]);
124  }
125 
126 // cout << "\nSpeed: 0.2";
127  cubic.reset();
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);
133 
134 // cout << "\nSpeed: 0.02";
135  cubic.reset();
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);
141 
142  /* This one fails due too error accumulation
143  cout << "\nSpeed: 0.002";
144  cubic.reset();
145  cubic.set_speed (0.002);
146  cubic.set_target_speed (cubic.speed());
147  result = cubic.interpolate (0, NUM_SAMPLES, input, output);
148  cubic.speed();
149  CPPUNIT_ASSERT_EQUAL ((framecnt_t)(NUM_SAMPLES * cubic.speed()), result);
150  */
151 
152 // cout << "\nSpeed: 2.0";
153  cubic.reset();
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]);
161  }
162 
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]);
171  }
172 }
tuple f
Definition: signals.py:35
Definition: Beats.hpp:239
#define INTERVAL
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
#define NUM_SAMPLES
CPPUNIT_TEST_SUITE_REGISTRATION(InterpolationTest)