Jamoma API  0.6.0.a19
TTHilbertLinear33.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief Unit test for the FilterLib #TTHilbertLinear33 class.
6  *
7  * @details Currently this test is just a stub
8  *
9  * @authors Trond Lossius, Tim Place
10  *
11  * @copyright Copyright © 2012 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 "TTHilbertLinear33.h"
18 
19 
21 {
22  int errorCount = 0;
23  int testAssertionCount = 0;
24  int badSampleCount = 0;
25  TTAudioSignalPtr input = NULL;
26  TTAudioSignalPtr outputReal = NULL;
27  TTAudioSignalPtr outputImaginary = NULL;
28 
29  // create audio signal objects - hilbert returns real and imaginary signal so we need two channels for output
30  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
31  TTObjectBaseInstantiate(kTTSym_audiosignal, &outputReal, 1);
32  TTObjectBaseInstantiate(kTTSym_audiosignal, &outputImaginary, 1);
33  input->allocWithVectorSize(128);
34  outputReal->allocWithVectorSize(128);
35  outputImaginary->allocWithVectorSize(128);
36 
37  // create an impulse
38  input->clear(); // set all samples to zero
39  input->mSampleVectors[0][0] = 1.0; // set the first sample to 1
40 
41  // setup the filter
42  //this->setAttributeValue(TT("linearGain"), 0.5);
43  //this->setAttributeValue(TT("delayInSamples"), 1);
44 
45  TTObject inputArray(kTTSym_audiosignalarray, 1);
46  TTObject outputArray(kTTSym_audiosignalarray, 2);
47 
48  // TODO: switch these to use the new TTBASE macro:
49  ((TTAudioSignalArrayPtr)inputArray.instance())->setSignal(0, input);
50  ((TTAudioSignalArrayPtr)outputArray.instance())->setSignal(0, outputReal);
51  ((TTAudioSignalArrayPtr)outputArray.instance())->setSignal(1, outputImaginary);
52 
53  this->process(TTAudioSignalArrayPtr(inputArray.instance()), TTAudioSignalArrayPtr(outputArray.instance()));
54 
55  /// The following values are not necsessarily to be trusted. They were calculated from this filter unit itself at a time when the filter was assumed to work. As such, if this test fails in the future, it should be considered an indication that something has changed in the code or compiler that causes the calculated impulse response to differ from earlier results, but this test is not able to say anything meaningful about whether the old or new behaviour is to be trusted (or eventually none of them).
56  TTFloat64 expectedImpulseResponseCh1[128] = {
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  1.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  0.0000000000000000e+00,
113  0.0000000000000000e+00,
114  0.0000000000000000e+00,
115  0.0000000000000000e+00,
116  0.0000000000000000e+00,
117  0.0000000000000000e+00,
118  0.0000000000000000e+00,
119  0.0000000000000000e+00,
120  0.0000000000000000e+00,
121  0.0000000000000000e+00,
122  0.0000000000000000e+00,
123  0.0000000000000000e+00,
124  0.0000000000000000e+00,
125  0.0000000000000000e+00,
126  0.0000000000000000e+00,
127  0.0000000000000000e+00,
128  0.0000000000000000e+00,
129  0.0000000000000000e+00,
130  0.0000000000000000e+00,
131  0.0000000000000000e+00,
132  0.0000000000000000e+00,
133  0.0000000000000000e+00,
134  0.0000000000000000e+00,
135  0.0000000000000000e+00,
136  0.0000000000000000e+00,
137  0.0000000000000000e+00,
138  0.0000000000000000e+00,
139  0.0000000000000000e+00,
140  0.0000000000000000e+00,
141  0.0000000000000000e+00,
142  0.0000000000000000e+00,
143  0.0000000000000000e+00,
144  0.0000000000000000e+00,
145  0.0000000000000000e+00,
146  0.0000000000000000e+00,
147  0.0000000000000000e+00,
148  0.0000000000000000e+00,
149  0.0000000000000000e+00,
150  0.0000000000000000e+00,
151  0.0000000000000000e+00,
152  0.0000000000000000e+00,
153  0.0000000000000000e+00,
154  0.0000000000000000e+00,
155  0.0000000000000000e+00,
156  0.0000000000000000e+00,
157  0.0000000000000000e+00,
158  0.0000000000000000e+00,
159  0.0000000000000000e+00,
160  0.0000000000000000e+00,
161  0.0000000000000000e+00,
162  0.0000000000000000e+00,
163  0.0000000000000000e+00,
164  0.0000000000000000e+00,
165  0.0000000000000000e+00,
166  0.0000000000000000e+00,
167  0.0000000000000000e+00,
168  0.0000000000000000e+00,
169  0.0000000000000000e+00,
170  0.0000000000000000e+00,
171  0.0000000000000000e+00,
172  0.0000000000000000e+00,
173  0.0000000000000000e+00,
174  0.0000000000000000e+00,
175  0.0000000000000000e+00,
176  0.0000000000000000e+00,
177  0.0000000000000000e+00,
178  0.0000000000000000e+00,
179  0.0000000000000000e+00,
180  0.0000000000000000e+00,
181  0.0000000000000000e+00,
182  0.0000000000000000e+00,
183  0.0000000000000000e+00,
184  0.0000000000000000e+00,
185  };
186  TTFloat64 expectedImpulseResponseCh2[128] = {
187  0.0000000000000000e+00,
188  -2.8092457249341120e-03,
189  0.0000000000000000e+00,
190  -5.7437236386599748e-03,
191  0.0000000000000000e+00,
192  -1.1602174238849574e-02,
193  0.0000000000000000e+00,
194  -2.1812001394733507e-02,
195  0.0000000000000000e+00,
196  -3.9950693784204676e-02,
197  0.0000000000000000e+00,
198  -7.4975660919201770e-02,
199  0.0000000000000000e+00,
200  -1.5941021199354771e-01,
201  0.0000000000000000e+00,
202  -5.8434596240466408e-01,
203  0.0000000000000000e+00,
204  6.8737371572856165e-01,
205  0.0000000000000000e+00,
206  2.6047219272586097e-01,
207  0.0000000000000000e+00,
208  1.7220504166668985e-01,
209  0.0000000000000000e+00,
210  1.3165880751558845e-01,
211  0.0000000000000000e+00,
212  1.0672637484521202e-01,
213  0.0000000000000000e+00,
214  8.8763042682027796e-02,
215  0.0000000000000000e+00,
216  7.4590817559364642e-02,
217  0.0000000000000000e+00,
218  6.2491816141289638e-02,
219  0.0000000000000000e+00,
220  5.3601005804006424e-02,
221  0.0000000000000000e+00,
222  4.4268254704726902e-02,
223  0.0000000000000000e+00,
224  3.6698916574512824e-02,
225  0.0000000000000000e+00,
226  3.0491527642942159e-02,
227  0.0000000000000000e+00,
228  2.5364772306844932e-02,
229  0.0000000000000000e+00,
230  2.1112011554879444e-02,
231  0.0000000000000000e+00,
232  1.7575632461599877e-02,
233  0.0000000000000000e+00,
234  1.4631136058800433e-02,
235  0.0000000000000000e+00,
236  1.2180032897411687e-02,
237  0.0000000000000000e+00,
238  1.0137024036000260e-02,
239  0.0000000000000000e+00,
240  8.4366607684061290e-03,
241  0.0000000000000000e+00,
242  7.0216702898170313e-03,
243  0.0000000000000000e+00,
244  5.8441053213995897e-03,
245  0.0000000000000000e+00,
246  4.8640673178878824e-03,
247  0.0000000000000000e+00,
248  4.0483891530415182e-03,
249  0.0000000000000000e+00,
250  3.3694930991639144e-03,
251  0.0000000000000000e+00,
252  2.8044411084449080e-03,
253  0.0000000000000000e+00,
254  2.3341416117147440e-03,
255  0.0000000000000000e+00,
256  1.9427099863831426e-03,
257  0.0000000000000000e+00,
258  1.6169211725708889e-03,
259  0.0000000000000000e+00,
260  1.3457668541494491e-03,
261  0.0000000000000000e+00,
262  1.1200846929263178e-03,
263  0.0000000000000000e+00,
264  9.3224896671763400e-04,
265  0.0000000000000000e+00,
266  7.7591286433524435e-04,
267  0.0000000000000000e+00,
268  6.4579396750947084e-04,
269  0.0000000000000000e+00,
270  5.3749571564408851e-04,
271  0.0000000000000000e+00,
272  4.4735884490682882e-04,
273  0.0000000000000000e+00,
274  3.7233773378069054e-04,
275  0.0000000000000000e+00,
276  3.0989750176924926e-04,
277  0.0000000000000000e+00,
278  2.5792836193805926e-04,
279  0.0000000000000000e+00,
280  2.1467433437323476e-04,
281  0.0000000000000000e+00,
282  1.7867391348799137e-04,
283  0.0000000000000000e+00,
284  1.4871068515793736e-04,
285  0.0000000000000000e+00,
286  1.2377222529964514e-04,
287  0.0000000000000000e+00,
288  1.0301589114967565e-04,
289  0.0000000000000000e+00,
290  8.5740349291217426e-05,
291  0.0000000000000000e+00,
292  7.1361878394029805e-05,
293  0.0000000000000000e+00,
294  5.9394645929584248e-05,
295  0.0000000000000000e+00,
296  4.9434292433224237e-05,
297  0.0000000000000000e+00,
298  4.1144268647743772e-05,
299  0.0000000000000000e+00,
300  3.4244463897949263e-05,
301  0.0000000000000000e+00,
302  2.8501741462339606e-05,
303  0.0000000000000000e+00,
304  2.3722061142687539e-05,
305  0.0000000000000000e+00,
306  1.9743922861739448e-05,
307  0.0000000000000000e+00,
308  1.6432909755427518e-05,
309  0.0000000000000000e+00,
310  1.3677146376690416e-05,
311  0.0000000000000000e+00,
312  1.1383518548663555e-05,
313  0.0000000000000000e+00,
314  9.4745271402964313e-06,
315  };
316 
317 
318 
319  // TEST 1: IMPULSE RESPONSE - REAL VECTOR
320 
321  //TTTestLog("\nRESULTING VALUES - CHANNEL 1");
322  for (int i=0; i<128; i++) {
323  TTBoolean result = !TTTestFloatEquivalence(outputReal->mSampleVectors[0][i], expectedImpulseResponseCh1[i]);
324  //TTTestLog("%.16e,", outputReal->mSampleVectors[0][i]);
325  badSampleCount += result;
326  if (result)
327  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, outputReal->mSampleVectors[0][i], expectedImpulseResponseCh1[i]);
328  }
329 
330  TTTestAssertion("Produces correct impulse response for real signal",
331  badSampleCount == 0,
332  testAssertionCount,
333  errorCount);
334  if (badSampleCount)
335  TTTestLog("badSampleCount is %i", badSampleCount);
336 
337 
338 
339  // TEST 2: IMPULSE RESPONSE - IMAGINARY VECTOR
340 
341  //TTTestLog("\nRESULTING VALUES - CHANNEL 2");
342  badSampleCount = 0;
343  for (int i=0; i<128; i++) {
344  TTBoolean result = !TTTestFloatEquivalence(outputImaginary->mSampleVectors[0][i], expectedImpulseResponseCh2[i]);
345  //TTTestLog("%.16e,", outputImaginary->mSampleVectors[0][i]);
346  badSampleCount += result;
347 
348  if (result)
349  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, outputImaginary->mSampleVectors[0][i], expectedImpulseResponseCh2[i]);
350 
351  }
352 
353  TTTestAssertion("Produces correct impulse response for imaginary signal",
354  badSampleCount == 0,
355  testAssertionCount,
356  errorCount);
357  if (badSampleCount)
358  TTTestLog("badSampleCount is %i", badSampleCount);
359 
360 
361 
362  TTObjectBaseRelease(&input);
363  TTObjectBaseRelease(&outputReal);
364  TTObjectBaseRelease(&outputImaginary);
365 
366  // Wrap up the test results to pass back to whoever called this test
367  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
368 }
369 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTObject inputArray
If the process method is passed a signal, rather than an array of signals, we wrap the signal in this...
TTHilbertLinear33 is a 33rd-order Hilbert Transform filter built up from a 2-path allpass structure w...
Create and use Jamoma object instances.
Definition: TTObject.h:29
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTObject outputArray
If the process method is passed a signal, rather than an array of signals, we wrap the signal in this...
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.
A simple container for an array of TTAudioSignal pointers.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTObjectBase * instance() const
Return a direct pointer to the internal instance.
Definition: TTObject.cpp:105
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34