Jamoma API  0.6.0.a19
TTHilbert9.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief Unit test for the FilterLib #TTHilbert9 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 "TTHilbert9.h"
18 
19 
20 TTErr TTHilbert9::test(TTValue& returnedTestInfo)
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  1.7420609006175897e-02,
58  0.0000000000000000e+00,
59  -4.3505920836946033e-01,
60  0.0000000000000000e+00,
61  8.0706423584914044e-01,
62  0.0000000000000000e+00,
63  3.6492490730992394e-01,
64  0.0000000000000000e+00,
65  1.4751919086999823e-01,
66  0.0000000000000000e+00,
67  5.8960238068315345e-02,
68  0.0000000000000000e+00,
69  2.3536102363706037e-02,
70  0.0000000000000000e+00,
71  9.3940174253356358e-03,
72  0.0000000000000000e+00,
73  3.7494000604139655e-03,
74  0.0000000000000000e+00,
75  1.4964820197642804e-03,
76  0.0000000000000000e+00,
77  5.9728436681720997e-04,
78  0.0000000000000000e+00,
79  2.3839150972818700e-04,
80  0.0000000000000000e+00,
81  9.5148165510533045e-05,
82  0.0000000000000000e+00,
83  3.7976073091935286e-05,
84  0.0000000000000000e+00,
85  1.5157224731653196e-05,
86  0.0000000000000000e+00,
87  6.0496371230651281e-06,
88  0.0000000000000000e+00,
89  2.4145653289898111e-06,
90  0.0000000000000000e+00,
91  9.6371494841091791e-07,
92  0.0000000000000000e+00,
93  3.8464335201036664e-07,
94  0.0000000000000000e+00,
95  1.5352102661656153e-07,
96  0.0000000000000000e+00,
97  6.1274179029013311e-08,
98  0.0000000000000000e+00,
99  2.4456096330419825e-08,
100  0.0000000000000000e+00,
101  9.7610552634181111e-09,
102  0.0000000000000000e+00,
103  3.8958874943991041e-09,
104  0.0000000000000000e+00,
105  1.5549486156377259e-09,
106  0.0000000000000000e+00,
107  6.2061987178780377e-10,
108  0.0000000000000000e+00,
109  2.4770530767664106e-10,
110  0.0000000000000000e+00,
111  9.8865541115251806e-11,
112  0.0000000000000000e+00,
113  3.9459773033088236e-11,
114  0.0000000000000000e+00,
115  1.5749407430114503e-11,
116  0.0000000000000000e+00,
117  6.2859924255457196e-12,
118  0.0000000000000000e+00,
119  2.5089007919411533e-12,
120  0.0000000000000000e+00,
121  1.0013666510672705e-12,
122  0.0000000000000000e+00,
123  3.9967111218210333e-13,
124  0.0000000000000000e+00,
125  1.5951899111342436e-13,
126  0.0000000000000000e+00,
127  6.3668120487653824e-14,
128  0.0000000000000000e+00,
129  2.5411579763240305e-14,
130  0.0000000000000000e+00,
131  1.0142413206445196e-14,
132  0.0000000000000000e+00,
133  4.0480972300305685e-15,
134  0.0000000000000000e+00,
135  1.6156994248043121e-15,
136  0.0000000000000000e+00,
137  6.4486707778342382e-16,
138  0.0000000000000000e+00,
139  2.5738298945009473e-16,
140  0.0000000000000000e+00,
141  1.0272815211155196e-16,
142  0.0000000000000000e+00,
143  4.1001440144902600e-17,
144  0.0000000000000000e+00,
145  1.6364726313099775e-17,
146  0.0000000000000000e+00,
147  6.5315819726384476e-18,
148  0.0000000000000000e+00,
149  2.6069218787451070e-18,
150  0.0000000000000000e+00,
151  1.0404893807272607e-18,
152  0.0000000000000000e+00,
153  4.1528599695796719e-19,
154  0.0000000000000000e+00,
155  1.6575129209759770e-19,
156  0.0000000000000000e+00,
157  6.6155591648335443e-20,
158  0.0000000000000000e+00,
159  2.6404393298872762e-20,
160  0.0000000000000000e+00,
161  1.0538670550898157e-20,
162  0.0000000000000000e+00,
163  4.2062536988914454e-21,
164  0.0000000000000000e+00,
165  1.6788237277167869e-21,
166  0.0000000000000000e+00,
167  6.7006160600528881e-22,
168  0.0000000000000000e+00,
169  2.6743877181972321e-22,
170  0.0000000000000000e+00,
171  1.0674167275281468e-22,
172  0.0000000000000000e+00,
173  4.2603339166354575e-23,
174  0.0000000000000000e+00,
175  1.7004085295970599e-23,
176  0.0000000000000000e+00,
177  6.7867665401445153e-24,
178  0.0000000000000000e+00,
179  2.7087725842765494e-24,
180  0.0000000000000000e+00,
181  1.0811406094384403e-24,
182  0.0000000000000000e+00,
183  4.3151094490610365e-25,
184  0.0000000000000000e+00
185  };
186  TTFloat64 expectedImpulseResponseCh2[128] = {
187  0.0000000000000000e+00,
188  1.3088561157231265e-01,
189  0.0000000000000000e+00,
190  -8.0318229350905646e-01,
191  0.0000000000000000e+00,
192  2.4061706763854041e-01,
193  0.0000000000000000e+00,
194  3.2748856429240580e-01,
195  0.0000000000000000e+00,
196  2.7115156377578087e-01,
197  0.0000000000000000e+00,
198  2.0771812898972941e-01,
199  0.0000000000000000e+00,
200  1.5647053596965757e-01,
201  0.0000000000000000e+00,
202  1.1741317279214779e-01,
203  0.0000000000000000e+00,
204  8.8026322157452805e-02,
205  0.0000000000000000e+00,
206  6.5980841307707747e-02,
207  0.0000000000000000e+00,
208  4.9454073881787727e-02,
209  0.0000000000000000e+00,
210  3.7066483763912313e-02,
211  0.0000000000000000e+00,
212  2.7781747650721667e-02,
213  0.0000000000000000e+00,
214  2.0822720437544736e-02,
215  0.0000000000000000e+00,
216  1.5606852020098936e-02,
217  0.0000000000000000e+00,
218  1.1697502379486035e-02,
219  0.0000000000000000e+00,
220  8.7674029766002318e-03,
221  0.0000000000000000e+00,
222  6.5712621653267744e-03,
223  0.0000000000000000e+00,
224  4.9252311707943894e-03,
225  0.0000000000000000e+00,
226  3.6915133612201298e-03,
227  0.0000000000000000e+00,
228  2.7668286874658961e-03,
229  0.0000000000000000e+00,
230  2.0737676493775997e-03,
231  0.0000000000000000e+00,
232  1.5543109998395106e-03,
233  0.0000000000000000e+00,
234  1.1649726935158236e-03,
235  0.0000000000000000e+00,
236  8.7315947501983486e-04,
237  0.0000000000000000e+00,
238  6.5444235136189995e-04,
239  0.0000000000000000e+00,
240  4.9051153140880911e-04,
241  0.0000000000000000e+00,
242  3.6764363116830850e-04,
243  0.0000000000000000e+00,
244  2.7555282778045581e-04,
245  0.0000000000000000e+00,
246  2.0652978716512792e-04,
247  0.0000000000000000e+00,
248  1.5479628109807555e-04,
249  0.0000000000000000e+00,
250  1.1602146581711255e-04,
251  0.0000000000000000e+00,
252  8.6959327671592014e-05,
253  0.0000000000000000e+00,
254  6.5176944764819235e-05,
255  0.0000000000000000e+00,
256  4.8850816153033016e-05,
257  0.0000000000000000e+00,
258  3.6614208404956519e-05,
259  0.0000000000000000e+00,
260  2.7442740217930922e-05,
261  0.0000000000000000e+00,
262  2.0568626865817874e-05,
263  0.0000000000000000e+00,
264  1.5416405496883087e-05,
265  0.0000000000000000e+00,
266  1.1554760558143691e-05,
267  0.0000000000000000e+00,
268  8.6604164364401853e-06,
269  0.0000000000000000e+00,
270  6.4910746073142995e-06,
271  0.0000000000000000e+00,
272  4.8651297390774720e-06,
273  0.0000000000000000e+00,
274  3.6464666961899777e-06,
275  0.0000000000000000e+00,
276  2.7330657309344397e-06,
277  0.0000000000000000e+00,
278  2.0484619528852104e-06,
279  0.0000000000000000e+00,
280  1.5353441100677822e-06,
281  0.0000000000000000e+00,
282  1.1507568070764773e-06,
283  0.0000000000000000e+00,
284  8.6250451631614136e-07,
285  0.0000000000000000e+00,
286  6.4645634602472670e-07,
287  0.0000000000000000e+00,
288  4.8452593512271245e-07,
289  0.0000000000000000e+00,
290  3.6315736282919755e-07,
291  0.0000000000000000e+00,
292  2.7219032174955979e-07,
293  0.0000000000000000e+00,
294  2.0400955298536579e-07,
295  0.0000000000000000e+00,
296  1.5290733866571095e-07,
297  0.0000000000000000e+00,
298  1.1460568329125052e-07,
299  0.0000000000000000e+00,
300  8.5898183548725818e-08,
301  0.0000000000000000e+00,
302  6.4381605912329973e-08,
303  0.0000000000000000e+00,
304  4.8254701189336697e-08,
305  0.0000000000000000e+00,
306  3.6167413873505584e-08,
307  0.0000000000000000e+00,
308  2.7107862945103133e-08,
309  0.0000000000000000e+00,
310  2.0317632773539256e-08,
311  0.0000000000000000e+00,
312  1.5228282744249575e-08,
313  0.0000000000000000e+00,
314  1.1413760546003468e-08
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  if (result)
348  TTTestLog("BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, outputImaginary->mSampleVectors[0][i], expectedImpulseResponseCh2[i]);
349  }
350 
351  TTTestAssertion("Produces correct impulse response for imaginary signal",
352  badSampleCount == 0,
353  testAssertionCount,
354  errorCount);
355  if (badSampleCount)
356  TTTestLog("badSampleCount is %i", badSampleCount);
357 
358 
359 
360  TTObjectBaseRelease(&input);
361  TTObjectBaseRelease(&outputReal);
362  TTObjectBaseRelease(&outputImaginary);
363 
364  // Wrap up the test results to pass back to whoever called this test
365  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
366 }
367 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
TTObject inputArray
If the process method is passed a signal, rather than an array of signals, we wrap the signal in this...
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
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
TTHilbert9 is a 9th-order Hilbert Transform filter built up from a 2-path allpass structure ...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34