Jamoma API  0.6.0.a19
TTAllpass1.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief Unit test for the FilterLib #TTAllpass1 class.
6  *
7  * @details
8  *
9  * @authors Trond Lossius, Tim Place
10  *
11  * @copyright Copyright © 2011 by Trond Lossius & Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTAllpass1.h"
18 
19 
20 TTErr TTAllpass1::test(TTValue& returnedTestInfo)
21 {
22  int errorCount = 0;
23  int testAssertionCount = 0;
24  int badSampleCount = 0;
25  TTAudioSignalPtr input = NULL;
26  TTAudioSignalPtr output = NULL;
27 
28  // create 1 channel audio signal objects
29  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
30  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
31  input->allocWithVectorSize(64);
32  output->allocWithVectorSize(64);
33 
34  // create an impulse
35  input->clear(); // set all samples to zero
36  input->mSampleVectors[0][0] = 1.0; // set the first sample to 1
37 
38  // setup the filter
39  this->setAttributeValue(TT("linearGain"), 0.5);
40  this->setAttributeValue(TT("delayInSamples"), 1);
41  this->process(input, output);
42 
43  // coefficients calculated in Matlab/Scilab
44  // a = [0.5, 1.0]; % numerator (fir)
45  // b = [1.0, 0.5]; % denominator (iir)
46  // i = impz(a, b, 64);
47  TTFloat64 expectedImpulseResponse[64] = {
48  0.500000000000000 ,
49  0.750000000000000 ,
50  -0.375000000000000 ,
51  0.187500000000000 ,
52  -0.0937500000000000 ,
53  0.0468750000000000 ,
54  -0.0234375000000000 ,
55  0.0117187500000000 ,
56  -0.00585937500000000 ,
57  0.00292968750000000 ,
58  -0.00146484375000000 ,
59  0.000732421875000000 ,
60  -0.000366210937500000,
61  0.000183105468750000 ,
62  -9.15527343750000e-05,
63  4.57763671875000e-05 ,
64  -2.28881835937500e-05,
65  1.14440917968750e-05 ,
66  -5.72204589843750e-06,
67  2.86102294921875e-06 ,
68  -1.43051147460938e-06,
69  7.15255737304688e-07 ,
70  -3.57627868652344e-07,
71  1.78813934326172e-07 ,
72  -8.94069671630859e-08,
73  4.47034835815430e-08 ,
74  -2.23517417907715e-08,
75  1.11758708953857e-08 ,
76  -5.58793544769287e-09,
77  2.79396772384644e-09 ,
78  -1.39698386192322e-09,
79  6.98491930961609e-10 ,
80  -3.49245965480804e-10,
81  1.74622982740402e-10 ,
82  -8.73114913702011e-11,
83  4.36557456851006e-11 ,
84  -2.18278728425503e-11,
85  1.09139364212751e-11 ,
86  -5.45696821063757e-12,
87  2.72848410531878e-12 ,
88  -1.36424205265939e-12,
89  6.82121026329696e-13 ,
90  -3.41060513164848e-13,
91  1.70530256582424e-13 ,
92  -8.52651282912120e-14,
93  4.26325641456060e-14 ,
94  -2.13162820728030e-14,
95  1.06581410364015e-14 ,
96  -5.32907051820075e-15,
97  2.66453525910038e-15 ,
98  -1.33226762955019e-15,
99  6.66133814775094e-16 ,
100  -3.33066907387547e-16,
101  1.66533453693773e-16 ,
102  -8.32667268468867e-17,
103  4.16333634234434e-17 ,
104  -2.08166817117217e-17,
105  1.04083408558608e-17 ,
106  -5.20417042793042e-18,
107  2.60208521396521e-18 ,
108  -1.30104260698261e-18,
109  6.50521303491303e-19 ,
110  -3.25260651745651e-19,
111  1.62630325872826e-19
112  };
113 
114  for (int i=0; i<64; i++) {
115  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][i], expectedImpulseResponse[i]);
116  badSampleCount += result;
117  if (result)
118  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, output->mSampleVectors[0][i], expectedImpulseResponse[i]);
119  }
120 
121  TTTestAssertion("Produces correct impulse response for a delay of 1 sample and alpha = 0.5",
122  badSampleCount == 0,
123  testAssertionCount,
124  errorCount);
125  if (badSampleCount)
126  TTTestLog("badSampleCount is %i", badSampleCount);
127 
128 
129 
130 
131  TTObjectBaseRelease(&input);
132  TTObjectBaseRelease(&output);
133 
134 
135  // Wrap up the test results to pass back to whoever called this test
136  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
137 }
138 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr clear()
Zero out all of the sample values in the audio signal.
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
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 allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
TTAllpass1 is a first order allpass filter
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.