Jamoma API  0.6.0.a19
TTLogFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTLogFunction of the #TTFunctionLib
6  *
7  * @details
8  *
9  * @authors Trond Lossius
10  *
11  * @copyright Copyright © 2012 by Trond Lossius @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 "TTFunction.h"
18 #include "TTLogFunction.h"
19 
20 
21 /*
22  *
23 
24  We are testing with base = e
25  => k = 1 / log(e) = 1
26  => l = e-1
27  => y = k * log(x*l +1) = log(x*l + 1) = log(x*(e-1) + 1)
28 
29  Coefficients are calculated in Octave using:
30 
31  x = linspace(0,1,128);
32  y = log(x*(e-1) + 1);
33  printf("%.16e,\n", y)
34 
35  */
36 
37 TTErr TTLogFunction::test(TTValue& returnedTestInfo)
38 {
39  int errorCount = 0;
40  int testAssertionCount = 0;
41  int badSampleCount = 0;
42  TTAudioSignalPtr input = NULL;
43  TTAudioSignalPtr output = NULL;
44  int N = 128;
45  TTValue v;
46 
47 
48  TTFloat64 inputSignal1[128] = {
49  0.0000000000000000e+00,
50  7.8740157480314960e-03,
51  1.5748031496062992e-02,
52  2.3622047244094488e-02,
53  3.1496062992125984e-02,
54  3.9370078740157480e-02,
55  4.7244094488188976e-02,
56  5.5118110236220472e-02,
57  6.2992125984251968e-02,
58  7.0866141732283464e-02,
59  7.8740157480314960e-02,
60  8.6614173228346455e-02,
61  9.4488188976377951e-02,
62  1.0236220472440945e-01,
63  1.1023622047244094e-01,
64  1.1811023622047244e-01,
65  1.2598425196850394e-01,
66  1.3385826771653542e-01,
67  1.4173228346456693e-01,
68  1.4960629921259844e-01,
69  1.5748031496062992e-01,
70  1.6535433070866140e-01,
71  1.7322834645669291e-01,
72  1.8110236220472442e-01,
73  1.8897637795275590e-01,
74  1.9685039370078738e-01,
75  2.0472440944881889e-01,
76  2.1259842519685040e-01,
77  2.2047244094488189e-01,
78  2.2834645669291337e-01,
79  2.3622047244094488e-01,
80  2.4409448818897639e-01,
81  2.5196850393700787e-01,
82  2.5984251968503935e-01,
83  2.6771653543307083e-01,
84  2.7559055118110237e-01,
85  2.8346456692913385e-01,
86  2.9133858267716534e-01,
87  2.9921259842519687e-01,
88  3.0708661417322836e-01,
89  3.1496062992125984e-01,
90  3.2283464566929132e-01,
91  3.3070866141732280e-01,
92  3.3858267716535434e-01,
93  3.4645669291338582e-01,
94  3.5433070866141730e-01,
95  3.6220472440944884e-01,
96  3.7007874015748032e-01,
97  3.7795275590551181e-01,
98  3.8582677165354329e-01,
99  3.9370078740157477e-01,
100  4.0157480314960631e-01,
101  4.0944881889763779e-01,
102  4.1732283464566927e-01,
103  4.2519685039370081e-01,
104  4.3307086614173229e-01,
105  4.4094488188976377e-01,
106  4.4881889763779526e-01,
107  4.5669291338582674e-01,
108  4.6456692913385828e-01,
109  4.7244094488188976e-01,
110  4.8031496062992124e-01,
111  4.8818897637795278e-01,
112  4.9606299212598426e-01,
113  5.0393700787401574e-01,
114  5.1181102362204722e-01,
115  5.1968503937007871e-01,
116  5.2755905511811019e-01,
117  5.3543307086614167e-01,
118  5.4330708661417326e-01,
119  5.5118110236220474e-01,
120  5.5905511811023623e-01,
121  5.6692913385826771e-01,
122  5.7480314960629919e-01,
123  5.8267716535433067e-01,
124  5.9055118110236215e-01,
125  5.9842519685039375e-01,
126  6.0629921259842523e-01,
127  6.1417322834645671e-01,
128  6.2204724409448819e-01,
129  6.2992125984251968e-01,
130  6.3779527559055116e-01,
131  6.4566929133858264e-01,
132  6.5354330708661412e-01,
133  6.6141732283464560e-01,
134  6.6929133858267720e-01,
135  6.7716535433070868e-01,
136  6.8503937007874016e-01,
137  6.9291338582677164e-01,
138  7.0078740157480313e-01,
139  7.0866141732283461e-01,
140  7.1653543307086609e-01,
141  7.2440944881889768e-01,
142  7.3228346456692917e-01,
143  7.4015748031496065e-01,
144  7.4803149606299213e-01,
145  7.5590551181102361e-01,
146  7.6377952755905509e-01,
147  7.7165354330708658e-01,
148  7.7952755905511806e-01,
149  7.8740157480314954e-01,
150  7.9527559055118113e-01,
151  8.0314960629921262e-01,
152  8.1102362204724410e-01,
153  8.1889763779527558e-01,
154  8.2677165354330706e-01,
155  8.3464566929133854e-01,
156  8.4251968503937003e-01,
157  8.5039370078740162e-01,
158  8.5826771653543310e-01,
159  8.6614173228346458e-01,
160  8.7401574803149606e-01,
161  8.8188976377952755e-01,
162  8.8976377952755903e-01,
163  8.9763779527559051e-01,
164  9.0551181102362199e-01,
165  9.1338582677165348e-01,
166  9.2125984251968507e-01,
167  9.2913385826771655e-01,
168  9.3700787401574803e-01,
169  9.4488188976377951e-01,
170  9.5275590551181100e-01,
171  9.6062992125984248e-01,
172  9.6850393700787396e-01,
173  9.7637795275590555e-01,
174  9.8425196850393704e-01,
175  9.9212598425196852e-01,
176  1.0000000000000000e+00
177  };
178 
179 
180  TTFloat64 expectedSignal1[128] = {
181  0.0000000000000000e+00,
182  1.3439068004527731e-02,
183  2.6699919872319844e-02,
184  3.9787220475518303e-02,
185  5.2705453892800097e-02,
186  6.5458932632876290e-02,
187  7.8051806277199445e-02,
188  9.0488069585220057e-02,
189  1.0277157010180595e-01,
190  1.1490601530307312e-01,
191  1.2689497931383456e-01,
192  1.3874190922711904e-01,
193  1.5045013105371655e-01,
194  1.6202285532744146e-01,
195  1.7346318238974670e-01,
196  1.8477410737545458e-01,
197  1.9595852491965574e-01,
198  2.0701923360429070e-01,
199  2.1795894016149450e-01,
200  2.2878026344950209e-01,
201  2.3948573821572341e-01,
202  2.5007781866051476e-01,
203  2.6055888181418080e-01,
204  2.7093123073883135e-01,
205  2.8119709756588146e-01,
206  2.9135864637921588e-01,
207  3.0141797595333425e-01,
208  3.1137712235514214e-01,
209  3.2123806141745626e-01,
210  3.3100271109174007e-01,
211  3.4067293368707802e-01,
212  3.5025053800192463e-01,
213  3.5973728135473371e-01,
214  3.6913487151916818e-01,
215  3.7844496856922216e-01,
216  3.8766918663924055e-01,
217  3.9680909560350375e-01,
218  4.0586622267974831e-01,
219  4.1484205396072188e-01,
220  4.2373803587760944e-01,
221  4.3255557659894256e-01,
222  4.4129604736836597e-01,
223  4.4996078378445059e-01,
224  4.5855108702552999e-01,
225  4.6706822502237866e-01,
226  4.7551343358136855e-01,
227  4.8388791746059695e-01,
228  4.9219285140132479e-01,
229  5.0042938111693902e-01,
230  5.0859862424151647e-01,
231  5.1670167123995647e-01,
232  5.2473958628153383e-01,
233  5.3271340807862377e-01,
234  5.4062415069225078e-01,
235  5.4847280430602485e-01,
236  5.5626033596994062e-01,
237  5.6398769031543905e-01,
238  5.7165579024305202e-01,
239  5.7926553758388177e-01,
240  5.8681781373610242e-01,
241  5.9431348027760444e-01,
242  6.0175337955585084e-01,
243  6.0913833525594951e-01,
244  6.1646915294790594e-01,
245  6.2374662061395936e-01,
246  6.3097150915687239e-01,
247  6.3814457288998616e-01,
248  6.4526655000982847e-01,
249  6.5233816305200676e-01,
250  6.5936011933109906e-01,
251  6.6633311136520312e-01,
252  6.7325781728578993e-01,
253  6.8013490123346143e-01,
254  6.8696501374019359e-01,
255  6.9374879209861351e-01,
256  7.0048686071883637e-01,
257  7.0717983147335828e-01,
258  7.1382830403048636e-01,
259  7.2043286617675706e-01,
260  7.2699409412877625e-01,
261  7.3351255283489558e-01,
262  7.3998879626712100e-01,
263  7.4642336770362949e-01,
264  7.5281680000225315e-01,
265  7.5916961586527720e-01,
266  7.6548232809587957e-01,
267  7.7175543984652695e-01,
268  7.7798944485962906e-01,
269  7.8418482770073639e-01,
270  7.9034206398455942e-01,
271  7.9646162059407277e-01,
272  8.0254395589295535e-01,
273  8.0858951993160733e-01,
274  8.1459875464697973e-01,
275  8.2057209405643372e-01,
276  8.2650996444584535e-01,
277  8.3241278455215739e-01,
278  8.3828096574057565e-01,
279  8.4411491217659584e-01,
280  8.4991502099304284e-01,
281  8.5568168245229204e-01,
282  8.6141528010384039e-01,
283  8.6711619093738623e-01,
284  8.7278478553157135e-01,
285  8.7842142819852853e-01,
286  8.8402647712437987e-01,
287  8.8960028450581896e-01,
288  8.9514319668290820e-01,
289  9.0065555426821531e-01,
290  9.0613769227240970e-01,
291  9.1158994022643580e-01,
292  9.1701262230037428e-01,
293  9.2240605741909587e-01,
294  9.2777055937481456e-01,
295  9.3310643693663786e-01,
296  9.3841399395720948e-01,
297  9.4369352947653695e-01,
298  9.4894533782309187e-01,
299  9.5416970871227125e-01,
300  9.5936692734229811e-01,
301  9.6453727448764470e-01,
302  9.6968102659005129e-01,
303  9.7479845584721636e-01,
304  9.7988983029923060e-01,
305  9.8495541391281993e-01,
306  9.8999546666346538e-01,
307  9.9501024461546550e-01,
308  1.0000000000000000e+00,
309  };
310 
311  // setup Function
312  this->setAttributeValue(TT("function"), TT("logarithm"));
313 
314 
315  // create 1 channel audio signal objects
316  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
317  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
318  input->allocWithVectorSize(N);
319  output->allocWithVectorSize(N);
320 
321  // create a signal to be transformed and then process it)
322  input->clear();
323  for (int i=0; i<N; i++)
324  input->mSampleVectors[0][i] = inputSignal1[i];
325 
326  this->process(input, output);
327 
328  // now test the output
329  for (int n=0; n<N; n++)
330  {
331  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
332  badSampleCount += result;
333  if (result)
334  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
335  }
336 
337  TTTestAssertion("Produces correct function values",
338  badSampleCount == 0,
339  testAssertionCount,
340  errorCount);
341  if (badSampleCount)
342  TTTestLog("badSampleCount is %i", badSampleCount);
343 
344 
345  TTObjectBaseRelease(&input);
346  TTObjectBaseRelease(&output);
347 
348  // wrap up test results and pass back to whoever called test
349  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
350 
351 }
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.
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFunction is a generalized function wrapper for Jamoma DSP
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
TTLogFunction Unit for Jamoms DSP
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34