Jamoma API  0.6.0.a19
TTDelay.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspLibrary
4  *
5  * @brief Unit tests for the #TTDelay class
6  *
7  * @details
8  *
9  * @see TTDelay
10  *
11  * @authors Nils Peters, Tim Place, Nathan Wolek
12  *
13  * @copyright Copyright © 2011-2012 by Nils Peters, Tim Place, Nathan Wolek @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 
19 #include "TTDelay.h"
20 
21 
22 TTErr TTDelay::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26  int badSampleCount = 0;
27 // TTAudioSignalPtr input = NULL;
28 // TTAudioSignalPtr output = NULL;
29  TTAudio input(1);
30  TTAudio output(1);
31 
32  // create 1 channel audio signal objects
33  input.allocWithVectorSize(64);
34  output.allocWithVectorSize(64);
35 
36  // create an impulse
37  input.clear(); // set all samples to zero
38  input.rawSamples()[0][0] = 1.0; // set the first sample to 1
39 
40  // test 1: one sample delay, no interpolation
41  this->setAttributeValue("delayMaxInSamples", 64);
42  this->setAttributeValue("delayInSamples", 1);
43  this->setAttributeValue("interpolation", "none"),
44  this->process(input, output);
45 
46 
47  TTFloat64 expectedImpulseResponse[64] = {
48  0.0000000000000000e+00,
49  1.0,
50  0.0000000000000000e+00,
51  0.0000000000000000e+00,
52  0.0000000000000000e+00,
53  0.0000000000000000e+00,
54  0.0000000000000000e+00,
55  0.0000000000000000e+00,
56  0.0000000000000000e+00,
57  0.0000000000000000e+00,
58  0.0000000000000000e+00,
59  0.0000000000000000e+00,
60  0.0000000000000000e+00,
61  0.0000000000000000e+00,
62  0.0000000000000000e+00,
63  0.0000000000000000e+00,
64  0.0000000000000000e+00,
65  0.0000000000000000e+00,
66  0.0000000000000000e+00,
67  0.0000000000000000e+00,
68  0.0000000000000000e+00,
69  0.0000000000000000e+00,
70  0.0000000000000000e+00,
71  0.0000000000000000e+00,
72  0.0000000000000000e+00,
73  0.0000000000000000e+00,
74  0.0000000000000000e+00,
75  0.0000000000000000e+00,
76  0.0000000000000000e+00,
77  0.0000000000000000e+00,
78  0.0000000000000000e+00,
79  0.0000000000000000e+00,
80  0.0000000000000000e+00,
81  0.0000000000000000e+00,
82  0.0000000000000000e+00,
83  0.0000000000000000e+00,
84  0.0000000000000000e+00,
85  0.0000000000000000e+00,
86  0.0000000000000000e+00,
87  0.0000000000000000e+00,
88  0.0000000000000000e+00,
89  0.0000000000000000e+00,
90  0.0000000000000000e+00,
91  0.0000000000000000e+00,
92  0.0000000000000000e+00,
93  0.0000000000000000e+00,
94  0.0000000000000000e+00,
95  0.0000000000000000e+00,
96  0.0000000000000000e+00,
97  0.0000000000000000e+00,
98  0.0000000000000000e+00,
99  0.0000000000000000e+00,
100  0.0000000000000000e+00,
101  0.0000000000000000e+00,
102  0.0000000000000000e+00,
103  0.0000000000000000e+00,
104  0.0000000000000000e+00,
105  0.0000000000000000e+00,
106  0.0000000000000000e+00,
107  0.0000000000000000e+00,
108  0.0000000000000000e+00,
109  0.0000000000000000e+00,
110  0.0000000000000000e+00,
111  0.0000000000000000e+00
112  };
113 
114  badSampleCount = 0; // reset
115  for (int i=0; i<64; i++) {
116  TTBoolean result = TTTestFloatEquivalence(output.rawSamples()[0][i], expectedImpulseResponse[i]);
117  badSampleCount += !result;
118  if (!result)
119  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output.rawSamples()[0][i], expectedImpulseResponse[i]);
120  }
121 
122  TTTestAssertion("Produces correct impulse response: 1 sample, no interp",
123  badSampleCount == 0,
124  testAssertionCount,
125  errorCount);
126  if (badSampleCount)
127  TTTestLog("badSampleCount is %i", badSampleCount);
128 
129  //test 2: negative values for delay in samples, should clip to 0
130  this->setAttributeValue("delayInSamples", -1);
131 
132  TTInt64 inquiry2 = this->mDelayInSamples;
133  TTBoolean result2 = { inquiry2 == 0 };
134 
135  TTTestAssertion("setting delayInSamples to negative value clips to 0",
136  result2,
137  testAssertionCount,
138  errorCount);
139 
140  if(!result2)
141  {
142  TTTestLog("Expected a value of %i, but returned value was %i", 0, inquiry2);
143  }
144 
145  //test 3: negative values for delay in milliseconds, should clip to 0
146  this->setAttributeValue("delay", -1);
147 
148  TTInt64 inquiry3 = this->mDelay;
149  TTBoolean result3 = { inquiry3 == 0 };
150 
151  TTTestAssertion("setting delay to negative value clips to 0",
152  result3,
153  testAssertionCount,
154  errorCount);
155 
156  if(!result3)
157  {
158  TTTestLog("Expected a value of %i, but returned value was %i", 0, inquiry3);
159  }
160 
161  //test 4,5,6,7: setting delayInSamples supports fractional values
162  this->setAttributeValue("delayInSamples", 44.1);
163 
164  TTFloat64 inquiry4 = this->mDelayInSamples;
165  TTFloat64 expect4 = 44.1;
166  TTBoolean result4 = TTTestFloatEquivalence(inquiry4,expect4);
167  TTUInt64 inquiry5 = this->mIntegralDelay;
168  TTUInt64 expect5 = 44;
169  TTBoolean result5 = { inquiry5 == expect5 };
170  TTFloat64 inquiry6 = this->mFractionalDelay;
171  TTFloat64 expect6 = 0.1;
172  TTBoolean result6 = TTTestFloatEquivalence(inquiry6,expect6);
173  TTFloat64 inquiry7 = this->mDelay;
174  TTFloat64 expect7 = 1.0;
175  TTBoolean result7 = TTTestFloatEquivalence(inquiry7,expect7);
176 
177  TTTestAssertion("float delayInSamples to yields correct mDelayInSamples",
178  result4,
179  testAssertionCount,
180  errorCount);
181 
182  if(!result4)
183  {
184  TTTestLog("Expected a value of %f, but returned value was %f", expect4, inquiry4);
185  }
186 
187  TTTestAssertion("float delayInSamples to yields correct mIntegralDelay",
188  result5,
189  testAssertionCount,
190  errorCount);
191 
192  if(!result5)
193  {
194  TTTestLog("Expected a value of %i, but returned value was %i", expect5, inquiry5);
195  }
196 
197  TTTestAssertion("float delayInSamples to yields correct mFractionalDelay",
198  result6,
199  testAssertionCount,
200  errorCount);
201 
202  if(!result6)
203  {
204  TTTestLog("Expected a value of %f, but returned value was %f", expect6, inquiry6);
205  }
206 
207  TTTestAssertion("float delayInSamples to yields correct mDelay",
208  result7,
209  testAssertionCount,
210  errorCount);
211 
212  if(!result7)
213  {
214  TTTestLog("Expected a value of %f, but returned value was %f", expect7, inquiry7);
215  }
216 
217  //test 8,9,10,11: setting delay supports fractional values
218  this->setAttributeValue("delay", 1.1);
219 
220  TTFloat64 inquiry8 = this->mDelayInSamples;
221  TTFloat64 expect8 = 48.51;
222  TTBoolean result8 = TTTestFloatEquivalence(inquiry8,expect8);
223  TTUInt64 inquiry9 = this->mIntegralDelay;
224  TTUInt64 expect9 = 48;
225  TTBoolean result9 = { inquiry9 == expect9 };
226  TTFloat64 inquiry10 = this->mFractionalDelay;
227  TTFloat64 expect10 = 0.51;
228  TTBoolean result10 = TTTestFloatEquivalence(inquiry10,expect10);
229  TTFloat64 inquiry11 = this->mDelay;
230  TTFloat64 expect11 = 1.1;
231  TTBoolean result11 = TTTestFloatEquivalence(inquiry11,expect11);
232 
233  TTTestAssertion("float delay to yields correct mDelayInSamples",
234  result8,
235  testAssertionCount,
236  errorCount);
237 
238  if(!result8)
239  {
240  TTTestLog("Expected a value of %f, but returned value was %f", expect8, inquiry8);
241  }
242 
243  TTTestAssertion("float delay to yields correct mIntegralDelay",
244  result9,
245  testAssertionCount,
246  errorCount);
247 
248  if(!result9)
249  {
250  TTTestLog("Expected a value of %i, but returned value was %i", expect9, inquiry9);
251  }
252 
253  TTTestAssertion("float delay to yields correct mFractionalDelay",
254  result10,
255  testAssertionCount,
256  errorCount);
257 
258  if(!result10)
259  {
260  TTTestLog("Expected a value of %f, but returned value was %f", expect10, inquiry10);
261  }
262 
263  TTTestAssertion("float delay to yields correct mDelay",
264  result11,
265  testAssertionCount,
266  errorCount);
267 
268  if(!result11)
269  {
270  TTTestLog("Expected a value of %f, but returned value was %f", expect11, inquiry11);
271  }
272 
273  // test 12: 1.4 sample delay, linear interpolation
274  this->clear();
275  this->setAttributeValue("delayInSamples", 1.4);
276  this->setAttributeValue("interpolation", "linear"),
277  this->process(input, output);
278 
279 
280  TTFloat64 expectedImpulseResponse12[64] = {
281  0.0000000000000000e+00,
282  0.6000000000000000e+00,
283  0.4000000000000000e+00,
284  0.0000000000000000e+00,
285  0.0000000000000000e+00,
286  0.0000000000000000e+00,
287  0.0000000000000000e+00,
288  0.0000000000000000e+00,
289  0.0000000000000000e+00,
290  0.0000000000000000e+00,
291  0.0000000000000000e+00,
292  0.0000000000000000e+00,
293  0.0000000000000000e+00,
294  0.0000000000000000e+00,
295  0.0000000000000000e+00,
296  0.0000000000000000e+00,
297  0.0000000000000000e+00,
298  0.0000000000000000e+00,
299  0.0000000000000000e+00,
300  0.0000000000000000e+00,
301  0.0000000000000000e+00,
302  0.0000000000000000e+00,
303  0.0000000000000000e+00,
304  0.0000000000000000e+00,
305  0.0000000000000000e+00,
306  0.0000000000000000e+00,
307  0.0000000000000000e+00,
308  0.0000000000000000e+00,
309  0.0000000000000000e+00,
310  0.0000000000000000e+00,
311  0.0000000000000000e+00,
312  0.0000000000000000e+00,
313  0.0000000000000000e+00,
314  0.0000000000000000e+00,
315  0.0000000000000000e+00,
316  0.0000000000000000e+00,
317  0.0000000000000000e+00,
318  0.0000000000000000e+00,
319  0.0000000000000000e+00,
320  0.0000000000000000e+00,
321  0.0000000000000000e+00,
322  0.0000000000000000e+00,
323  0.0000000000000000e+00,
324  0.0000000000000000e+00,
325  0.0000000000000000e+00,
326  0.0000000000000000e+00,
327  0.0000000000000000e+00,
328  0.0000000000000000e+00,
329  0.0000000000000000e+00,
330  0.0000000000000000e+00,
331  0.0000000000000000e+00,
332  0.0000000000000000e+00,
333  0.0000000000000000e+00,
334  0.0000000000000000e+00,
335  0.0000000000000000e+00,
336  0.0000000000000000e+00,
337  0.0000000000000000e+00,
338  0.0000000000000000e+00,
339  0.0000000000000000e+00,
340  0.0000000000000000e+00,
341  0.0000000000000000e+00,
342  0.0000000000000000e+00,
343  0.0000000000000000e+00,
344  0.0000000000000000e+00
345  };
346 
347  badSampleCount = 0; // reset
348  for (int i=0; i<64; i++) {
349  TTBoolean result = TTTestFloatEquivalence(output.rawSamples()[0][i], expectedImpulseResponse12[i]);
350  badSampleCount += !result;
351  if (!result)
352  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output.rawSamples()[0][i], expectedImpulseResponse12[i]);
353  }
354 
355  TTTestAssertion("Produces correct impulse response: 1.4 samples, linear interp",
356  badSampleCount == 0,
357  testAssertionCount,
358  errorCount);
359  if (badSampleCount)
360  TTTestLog("badSampleCount is %i", badSampleCount);
361 
362 
363  // test 13: 1.1 sample delay, cosine interpolation
364  this->clear();
365  this->setAttributeValue("delayInSamples", 1.1);
366  this->setAttributeValue("interpolation", "cosine"),
367  this->process(input, output);
368 
369 
370  TTFloat64 expectedImpulseResponse13[64] = {
371  0.0000000000000000e+00,
372  0.9755282581475768e+00,
373  0.0244717418524232e+00,
374  0.0000000000000000e+00,
375  0.0000000000000000e+00,
376  0.0000000000000000e+00,
377  0.0000000000000000e+00,
378  0.0000000000000000e+00,
379  0.0000000000000000e+00,
380  0.0000000000000000e+00,
381  0.0000000000000000e+00,
382  0.0000000000000000e+00,
383  0.0000000000000000e+00,
384  0.0000000000000000e+00,
385  0.0000000000000000e+00,
386  0.0000000000000000e+00,
387  0.0000000000000000e+00,
388  0.0000000000000000e+00,
389  0.0000000000000000e+00,
390  0.0000000000000000e+00,
391  0.0000000000000000e+00,
392  0.0000000000000000e+00,
393  0.0000000000000000e+00,
394  0.0000000000000000e+00,
395  0.0000000000000000e+00,
396  0.0000000000000000e+00,
397  0.0000000000000000e+00,
398  0.0000000000000000e+00,
399  0.0000000000000000e+00,
400  0.0000000000000000e+00,
401  0.0000000000000000e+00,
402  0.0000000000000000e+00,
403  0.0000000000000000e+00,
404  0.0000000000000000e+00,
405  0.0000000000000000e+00,
406  0.0000000000000000e+00,
407  0.0000000000000000e+00,
408  0.0000000000000000e+00,
409  0.0000000000000000e+00,
410  0.0000000000000000e+00,
411  0.0000000000000000e+00,
412  0.0000000000000000e+00,
413  0.0000000000000000e+00,
414  0.0000000000000000e+00,
415  0.0000000000000000e+00,
416  0.0000000000000000e+00,
417  0.0000000000000000e+00,
418  0.0000000000000000e+00,
419  0.0000000000000000e+00,
420  0.0000000000000000e+00,
421  0.0000000000000000e+00,
422  0.0000000000000000e+00,
423  0.0000000000000000e+00,
424  0.0000000000000000e+00,
425  0.0000000000000000e+00,
426  0.0000000000000000e+00,
427  0.0000000000000000e+00,
428  0.0000000000000000e+00,
429  0.0000000000000000e+00,
430  0.0000000000000000e+00,
431  0.0000000000000000e+00,
432  0.0000000000000000e+00,
433  0.0000000000000000e+00,
434  0.0000000000000000e+00
435  };
436 
437  badSampleCount = 0; // reset
438  for (int i=0; i<64; i++) {
439  TTBoolean result = TTTestFloatEquivalence(output.rawSamples()[0][i], expectedImpulseResponse13[i]);
440  badSampleCount += !result;
441  if (!result)
442  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output.rawSamples()[0][i], expectedImpulseResponse13[i]);
443  }
444 
445  TTTestAssertion("Produces correct impulse response: 1.1 samples, cosine interp",
446  badSampleCount == 0,
447  testAssertionCount,
448  errorCount);
449  if (badSampleCount)
450  TTTestLog("badSampleCount is %i", badSampleCount);
451 
452  // test 14: 1.8 sample delay, cubic interpolation
453 
454  this->clear();
455  this->setAttributeValue("delayInSamples", 1.8);
456  this->setAttributeValue("interpolation", "cubic"),
457  this->process(input, output);
458 
459 
460  TTFloat64 expectedImpulseResponse14[64] = {
461  -0.0160000000000000e+00,
462  0.1680000000000000e+00,
463  0.9120000000000000e+00,
464  -0.0640000000000000e+00,
465  0.0000000000000000e+00,
466  0.0000000000000000e+00,
467  0.0000000000000000e+00,
468  0.0000000000000000e+00,
469  0.0000000000000000e+00,
470  0.0000000000000000e+00,
471  0.0000000000000000e+00,
472  0.0000000000000000e+00,
473  0.0000000000000000e+00,
474  0.0000000000000000e+00,
475  0.0000000000000000e+00,
476  0.0000000000000000e+00,
477  0.0000000000000000e+00,
478  0.0000000000000000e+00,
479  0.0000000000000000e+00,
480  0.0000000000000000e+00,
481  0.0000000000000000e+00,
482  0.0000000000000000e+00,
483  0.0000000000000000e+00,
484  0.0000000000000000e+00,
485  0.0000000000000000e+00,
486  0.0000000000000000e+00,
487  0.0000000000000000e+00,
488  0.0000000000000000e+00,
489  0.0000000000000000e+00,
490  0.0000000000000000e+00,
491  0.0000000000000000e+00,
492  0.0000000000000000e+00,
493  0.0000000000000000e+00,
494  0.0000000000000000e+00,
495  0.0000000000000000e+00,
496  0.0000000000000000e+00,
497  0.0000000000000000e+00,
498  0.0000000000000000e+00,
499  0.0000000000000000e+00,
500  0.0000000000000000e+00,
501  0.0000000000000000e+00,
502  0.0000000000000000e+00,
503  0.0000000000000000e+00,
504  0.0000000000000000e+00,
505  0.0000000000000000e+00,
506  0.0000000000000000e+00,
507  0.0000000000000000e+00,
508  0.0000000000000000e+00,
509  0.0000000000000000e+00,
510  0.0000000000000000e+00,
511  0.0000000000000000e+00,
512  0.0000000000000000e+00,
513  0.0000000000000000e+00,
514  0.0000000000000000e+00,
515  0.0000000000000000e+00,
516  0.0000000000000000e+00,
517  0.0000000000000000e+00,
518  0.0000000000000000e+00,
519  0.0000000000000000e+00,
520  0.0000000000000000e+00,
521  0.0000000000000000e+00,
522  0.0000000000000000e+00,
523  0.0000000000000000e+00,
524  0.0000000000000000e+00
525  };
526 
527  badSampleCount = 0; // reset
528  for (int i=0; i<64; i++) {
529  TTBoolean result = TTTestFloatEquivalence(output.rawSamples()[0][i], expectedImpulseResponse14[i]);
530  badSampleCount += !result;
531  if (!result)
532  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output.rawSamples()[0][i], expectedImpulseResponse14[i]);
533  }
534 
535  TTTestAssertion("Produces correct impulse response: 1.8 samples, cubic interp",
536  badSampleCount == 0,
537  testAssertionCount,
538  errorCount);
539  if (badSampleCount)
540  TTTestLog("badSampleCount is %i", badSampleCount);
541 
542 
543  // Wrap up the test results to pass back to whoever called this test
544  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
545 }
546 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
TTFloat64 mDelayInSamples
mIntegralDelay + mFractionalDelay
Definition: TTDelay.h:28
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
std::int64_t TTInt64
64 bit signed integer
Definition: TTBase.h:179
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
Basic audio delay unit with 4 interpolation options.
TTUInt64 mIntegralDelay
mDelayInSamples - mFractionalDelay. Used to set the TTDelayBuffer->mReadPointer.
Definition: TTDelay.h:33
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr clear()
Zero out the delay's buffer.
Definition: TTDelay.cpp:92
TTFloat64 mFractionalDelay
mDelayInSamples - mFractionalDelay. Used in interpolated dsp loops, to approximate the distance betwe...
Definition: TTDelay.h:32
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25