Jamoma API  0.6.0.a19
TTExpFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTExpFunction 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 "TTExpFunction.h"
19 
20 
21 /*
22  * coefficients calculated in Octave using:
23 
24  // Test is performed with base = e:
25  // This implies that k = log(base) = log(e) = 1
26  // and we get the following equations:
27 
28  x = linspace(0,1,128);
29  y = (exp(x) - 1.) / (e - 1.);
30  printf("%.16e,\n", y)
31 
32  % TODO: Add additional tests for other bases (in particular 2 and 10)
33 
34  */
35 
36 TTErr TTExpFunction::test(TTValue& returnedTestInfo)
37 {
38  int errorCount = 0;
39  int testAssertionCount = 0;
40  int badSampleCount = 0;
41  TTAudioSignalPtr input = NULL;
42  TTAudioSignalPtr output = NULL;
43  int N = 128;
44  TTValue v;
45 
46 
47  TTFloat64 inputSignal1[128] = {
48  0.0000000000000000e+00,
49  7.8740157480314960e-03,
50  1.5748031496062992e-02,
51  2.3622047244094488e-02,
52  3.1496062992125984e-02,
53  3.9370078740157480e-02,
54  4.7244094488188976e-02,
55  5.5118110236220472e-02,
56  6.2992125984251968e-02,
57  7.0866141732283464e-02,
58  7.8740157480314960e-02,
59  8.6614173228346455e-02,
60  9.4488188976377951e-02,
61  1.0236220472440945e-01,
62  1.1023622047244094e-01,
63  1.1811023622047244e-01,
64  1.2598425196850394e-01,
65  1.3385826771653542e-01,
66  1.4173228346456693e-01,
67  1.4960629921259844e-01,
68  1.5748031496062992e-01,
69  1.6535433070866140e-01,
70  1.7322834645669291e-01,
71  1.8110236220472442e-01,
72  1.8897637795275590e-01,
73  1.9685039370078738e-01,
74  2.0472440944881889e-01,
75  2.1259842519685040e-01,
76  2.2047244094488189e-01,
77  2.2834645669291337e-01,
78  2.3622047244094488e-01,
79  2.4409448818897639e-01,
80  2.5196850393700787e-01,
81  2.5984251968503935e-01,
82  2.6771653543307083e-01,
83  2.7559055118110237e-01,
84  2.8346456692913385e-01,
85  2.9133858267716534e-01,
86  2.9921259842519687e-01,
87  3.0708661417322836e-01,
88  3.1496062992125984e-01,
89  3.2283464566929132e-01,
90  3.3070866141732280e-01,
91  3.3858267716535434e-01,
92  3.4645669291338582e-01,
93  3.5433070866141730e-01,
94  3.6220472440944884e-01,
95  3.7007874015748032e-01,
96  3.7795275590551181e-01,
97  3.8582677165354329e-01,
98  3.9370078740157477e-01,
99  4.0157480314960631e-01,
100  4.0944881889763779e-01,
101  4.1732283464566927e-01,
102  4.2519685039370081e-01,
103  4.3307086614173229e-01,
104  4.4094488188976377e-01,
105  4.4881889763779526e-01,
106  4.5669291338582674e-01,
107  4.6456692913385828e-01,
108  4.7244094488188976e-01,
109  4.8031496062992124e-01,
110  4.8818897637795278e-01,
111  4.9606299212598426e-01,
112  5.0393700787401574e-01,
113  5.1181102362204722e-01,
114  5.1968503937007871e-01,
115  5.2755905511811019e-01,
116  5.3543307086614167e-01,
117  5.4330708661417326e-01,
118  5.5118110236220474e-01,
119  5.5905511811023623e-01,
120  5.6692913385826771e-01,
121  5.7480314960629919e-01,
122  5.8267716535433067e-01,
123  5.9055118110236215e-01,
124  5.9842519685039375e-01,
125  6.0629921259842523e-01,
126  6.1417322834645671e-01,
127  6.2204724409448819e-01,
128  6.2992125984251968e-01,
129  6.3779527559055116e-01,
130  6.4566929133858264e-01,
131  6.5354330708661412e-01,
132  6.6141732283464560e-01,
133  6.6929133858267720e-01,
134  6.7716535433070868e-01,
135  6.8503937007874016e-01,
136  6.9291338582677164e-01,
137  7.0078740157480313e-01,
138  7.0866141732283461e-01,
139  7.1653543307086609e-01,
140  7.2440944881889768e-01,
141  7.3228346456692917e-01,
142  7.4015748031496065e-01,
143  7.4803149606299213e-01,
144  7.5590551181102361e-01,
145  7.6377952755905509e-01,
146  7.7165354330708658e-01,
147  7.7952755905511806e-01,
148  7.8740157480314954e-01,
149  7.9527559055118113e-01,
150  8.0314960629921262e-01,
151  8.1102362204724410e-01,
152  8.1889763779527558e-01,
153  8.2677165354330706e-01,
154  8.3464566929133854e-01,
155  8.4251968503937003e-01,
156  8.5039370078740162e-01,
157  8.5826771653543310e-01,
158  8.6614173228346458e-01,
159  8.7401574803149606e-01,
160  8.8188976377952755e-01,
161  8.8976377952755903e-01,
162  8.9763779527559051e-01,
163  9.0551181102362199e-01,
164  9.1338582677165348e-01,
165  9.2125984251968507e-01,
166  9.2913385826771655e-01,
167  9.3700787401574803e-01,
168  9.4488188976377951e-01,
169  9.5275590551181100e-01,
170  9.6062992125984248e-01,
171  9.6850393700787396e-01,
172  9.7637795275590555e-01,
173  9.8425196850393704e-01,
174  9.9212598425196852e-01,
175  1.0000000000000000e+00
176  };
177 
178 
179  TTFloat64 expectedSignal1[128] = {
180  0.0000000000000000e+00,
181  4.6005825147629152e-03,
182  9.2375330821049106e-03,
183  1.3911139195021205e-02,
184  1.8621690619167727e-02,
185  2.3369479410825809e-02,
186  2.8154799935009960e-02,
187  3.2977948883719160e-02,
188  3.7839225294331119e-02,
189  4.2738930568143582e-02,
190  4.7677368489060491e-02,
191  5.2654845242427264e-02,
192  5.7671669434014423e-02,
193  6.2728152109150795e-02,
194  6.7824606772009077e-02,
195  7.2961349405042994e-02,
196  7.8138698488578115e-02,
197  8.3356975020558055e-02,
198  8.8616502536446803e-02,
199  9.3917607129286942e-02,
200  9.9260617469918877e-02,
201  1.0464586482735769e-01,
202  1.1007368308933271e-01,
203  1.1554440878298762e-01,
204  1.2105838109574638e-01,
205  1.2661594189634237e-01,
206  1.3221743575601486e-01,
207  1.3786320996987186e-01,
208  1.4355361457842331e-01,
209  1.4928900238928342e-01,
210  1.5506972899904498e-01,
211  1.6089615281532627e-01,
212  1.6676863507899289e-01,
213  1.7268753988655430e-01,
214  1.7865323421273882e-01,
215  1.8466608793324524e-01,
216  1.9072647384767608e-01,
217  1.9683476770265088e-01,
218  2.0299134821510270e-01,
219  2.0919659709575908e-01,
220  2.1545089907280757e-01,
221  2.2175464191574987e-01,
222  2.2810821645944329e-01,
223  2.3451201662833268e-01,
224  2.4096643946087376e-01,
225  2.4747188513415022e-01,
226  2.5402875698868432e-01,
227  2.6063746155344464e-01,
228  2.6729840857105047e-01,
229  2.7401201102317674e-01,
230  2.8077868515615856e-01,
231  2.8759885050679890e-01,
232  2.9447292992837976e-01,
233  3.0140134961687987e-01,
234  3.0838453913739833e-01,
235  3.1542293145078831e-01,
236  3.2251696294050070e-01,
237  3.2966707343964002e-01,
238  3.3687370625823421e-01,
239  3.4413730821072019e-01,
240  3.5145832964364643e-01,
241  3.5883722446359484e-01,
242  3.6627445016532295e-01,
243  3.7377046786012885e-01,
244  3.8132574230444044e-01,
245  3.8894074192863026e-01,
246  3.9661593886605873e-01,
247  4.0435180898234613e-01,
248  4.1214883190487728e-01,
249  4.2000749105253787e-01,
250  4.2792827366568653e-01,
251  4.3591167083636512e-01,
252  4.4395817753874534e-01,
253  4.5206829265981824e-01,
254  4.6024251903032487e-01,
255  4.6848136345593228e-01,
256  4.7678533674865586e-01,
257  4.8515495375852924e-01,
258  4.9359073340552601e-01,
259  5.0209319871173264e-01,
260  5.1066287683377598e-01,
261  5.1930029909550768e-01,
262  5.2800600102094553e-01,
263  5.3678052236747731e-01,
264  5.4562440715932548e-01,
265  5.5453820372127671e-01,
266  5.6352246471267853e-01,
267  5.7257774716170418e-01,
268  5.8170461249988947e-01,
269  5.9090362659694051e-01,
270  6.0017535979581904e-01,
271  6.0952038694810284e-01,
272  6.1893928744962790e-01,
273  6.2843264527641018e-01,
274  6.3800104902085353e-01,
275  6.4764509192824138e-01,
276  6.5736537193351940e-01,
277  6.6716249169836694e-01,
278  6.7703705864856267e-01,
279  6.8698968501164492e-01,
280  6.9702098785487066e-01,
281  7.0713158912347340e-01,
282  7.1732211567922455e-01,
283  7.2759319933929811e-01,
284  7.3794547691544510e-01,
285  7.4837959025347489e-01,
286  7.5889618627305100e-01,
287  7.6949591700779929e-01,
288  7.8017943964573544e-01,
289  7.9094741657000989e-01,
290  8.0180051539997621e-01,
291  8.1273940903258513e-01,
292  8.2376477568410156e-01,
293  8.3487729893215701e-01,
294  8.4607766775813087e-01,
295  8.5736657658986704e-01,
296  8.6874472534472902e-01,
297  8.8021281947299557e-01,
298  8.9177157000159757e-01,
299  9.0342169357820468e-01,
300  9.1516391251565465e-01,
301  9.2699895483673922e-01,
302  9.3892755431934116e-01,
303  9.5095045054192850e-01,
304  9.6306838892940949e-01,
305  9.7528212079934806e-01,
306  9.8759240340854781e-01,
307  1.0000000000000000e+00,
308  };
309 
310  // setup Function
311  this->setAttributeValue(TT("function"), TT("exponential"));
312 
313 
314  // create 1 channel audio signal objects
315  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
316  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
317  input->allocWithVectorSize(N);
318  output->allocWithVectorSize(N);
319 
320  // create a signal to be transformed and then process it)
321  input->clear();
322  for (int i=0; i<N; i++)
323  input->mSampleVectors[0][i] = inputSignal1[i];
324 
325  this->process(input, output);
326 
327  // now test the output
328  for (int n=0; n<N; n++)
329  {
330  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
331  badSampleCount += result;
332  if (result)
333  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
334  }
335 
336  TTTestAssertion("Produces correct function values",
337  badSampleCount == 0,
338  testAssertionCount,
339  errorCount);
340  if (badSampleCount)
341  TTTestLog("badSampleCount is %i", badSampleCount);
342 
343 
344  TTObjectBaseRelease(&input);
345  TTObjectBaseRelease(&output);
346 
347  // wrap up test results and pass back to whoever called test
348  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
349 
350 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTExpFunction Unit for Jamoms DSP
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
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...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34