Jamoma API  0.6.0.a19
TTBounceEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTBounceEaseInOutFunction of the #TTFunctionLib
6  *
7  * @details Derived from Sam Hocevar's public domain C/C++ implementation of Robert Penner easing functions
8  *
9  * @authors Trond Lossius
10  *
11  * @copyright Copyright © 2014 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"
19 
20 
21 /*
22  * Coefficients calculated in Octave using script found
23  * in the OctaveScript subfolder of this extension.
24  */
25 
27 {
28  int errorCount = 0;
29  int testAssertionCount = 0;
30  int badSampleCount = 0;
31  TTAudioSignalPtr input = NULL;
32  TTAudioSignalPtr output = NULL;
33  int N = 128;
34  TTValue v;
35 
36 
37  TTFloat64 inputSignal1[128] = {
38  0.0000000000000000e+00,
39  7.8740157480314960e-03,
40  1.5748031496062992e-02,
41  2.3622047244094488e-02,
42  3.1496062992125984e-02,
43  3.9370078740157480e-02,
44  4.7244094488188976e-02,
45  5.5118110236220472e-02,
46  6.2992125984251968e-02,
47  7.0866141732283464e-02,
48  7.8740157480314960e-02,
49  8.6614173228346455e-02,
50  9.4488188976377951e-02,
51  1.0236220472440945e-01,
52  1.1023622047244094e-01,
53  1.1811023622047244e-01,
54  1.2598425196850394e-01,
55  1.3385826771653542e-01,
56  1.4173228346456693e-01,
57  1.4960629921259844e-01,
58  1.5748031496062992e-01,
59  1.6535433070866140e-01,
60  1.7322834645669291e-01,
61  1.8110236220472442e-01,
62  1.8897637795275590e-01,
63  1.9685039370078738e-01,
64  2.0472440944881889e-01,
65  2.1259842519685040e-01,
66  2.2047244094488189e-01,
67  2.2834645669291337e-01,
68  2.3622047244094488e-01,
69  2.4409448818897639e-01,
70  2.5196850393700787e-01,
71  2.5984251968503935e-01,
72  2.6771653543307083e-01,
73  2.7559055118110237e-01,
74  2.8346456692913385e-01,
75  2.9133858267716534e-01,
76  2.9921259842519687e-01,
77  3.0708661417322836e-01,
78  3.1496062992125984e-01,
79  3.2283464566929132e-01,
80  3.3070866141732280e-01,
81  3.3858267716535434e-01,
82  3.4645669291338582e-01,
83  3.5433070866141730e-01,
84  3.6220472440944884e-01,
85  3.7007874015748032e-01,
86  3.7795275590551181e-01,
87  3.8582677165354329e-01,
88  3.9370078740157477e-01,
89  4.0157480314960631e-01,
90  4.0944881889763779e-01,
91  4.1732283464566927e-01,
92  4.2519685039370081e-01,
93  4.3307086614173229e-01,
94  4.4094488188976377e-01,
95  4.4881889763779526e-01,
96  4.5669291338582674e-01,
97  4.6456692913385828e-01,
98  4.7244094488188976e-01,
99  4.8031496062992124e-01,
100  4.8818897637795278e-01,
101  4.9606299212598426e-01,
102  5.0393700787401574e-01,
103  5.1181102362204722e-01,
104  5.1968503937007871e-01,
105  5.2755905511811019e-01,
106  5.3543307086614167e-01,
107  5.4330708661417326e-01,
108  5.5118110236220474e-01,
109  5.5905511811023623e-01,
110  5.6692913385826771e-01,
111  5.7480314960629919e-01,
112  5.8267716535433067e-01,
113  5.9055118110236215e-01,
114  5.9842519685039375e-01,
115  6.0629921259842523e-01,
116  6.1417322834645671e-01,
117  6.2204724409448819e-01,
118  6.2992125984251968e-01,
119  6.3779527559055116e-01,
120  6.4566929133858264e-01,
121  6.5354330708661412e-01,
122  6.6141732283464560e-01,
123  6.6929133858267720e-01,
124  6.7716535433070868e-01,
125  6.8503937007874016e-01,
126  6.9291338582677164e-01,
127  7.0078740157480313e-01,
128  7.0866141732283461e-01,
129  7.1653543307086609e-01,
130  7.2440944881889768e-01,
131  7.3228346456692917e-01,
132  7.4015748031496065e-01,
133  7.4803149606299213e-01,
134  7.5590551181102361e-01,
135  7.6377952755905509e-01,
136  7.7165354330708658e-01,
137  7.7952755905511806e-01,
138  7.8740157480314954e-01,
139  7.9527559055118113e-01,
140  8.0314960629921262e-01,
141  8.1102362204724410e-01,
142  8.1889763779527558e-01,
143  8.2677165354330706e-01,
144  8.3464566929133854e-01,
145  8.4251968503937003e-01,
146  8.5039370078740162e-01,
147  8.5826771653543310e-01,
148  8.6614173228346458e-01,
149  8.7401574803149606e-01,
150  8.8188976377952755e-01,
151  8.8976377952755903e-01,
152  8.9763779527559051e-01,
153  9.0551181102362199e-01,
154  9.1338582677165348e-01,
155  9.2125984251968507e-01,
156  9.2913385826771655e-01,
157  9.3700787401574803e-01,
158  9.4488188976377951e-01,
159  9.5275590551181100e-01,
160  9.6062992125984248e-01,
161  9.6850393700787396e-01,
162  9.7637795275590555e-01,
163  9.8425196850393704e-01,
164  9.9212598425196852e-01,
165  1.0000000000000000e+00
166  };
167 
168 
169  TTFloat64 expectedSignal1[128] = {
170  -8.8817841970012523e-16,
171  7.1647343294687360e-03,
172  1.1651063302125841e-02,
173  1.3458986917972204e-02,
174  1.2588505177009601e-02,
175  9.0396180792362557e-03,
176  2.8123256246512796e-03,
177  1.0035054973156932e-02,
178  2.3004793932025258e-02,
179  3.2982039371280081e-02,
180  3.9966791290923176e-02,
181  4.3959049690952767e-02,
182  4.4958814571368855e-02,
183  4.2966085932171882e-02,
184  3.7980863773361406e-02,
185  3.0003148094938314e-02,
186  1.9032938896902607e-02,
187  5.0702361792533956e-03,
188  1.7193409386819569e-02,
189  4.0517856035712230e-02,
190  6.1591698183396604e-02,
191  8.0414935829871803e-02,
192  9.6987568975138272e-02,
193  1.1130959761919557e-01,
194  1.2338102176204369e-01,
195  1.3320184140368285e-01,
196  1.4077205654411351e-01,
197  1.4609166718333477e-01,
198  1.4916067332134708e-01,
199  1.4997907495815022e-01,
200  1.4854687209374462e-01,
201  1.4486406472812963e-01,
202  1.3893065286130568e-01,
203  1.3074663649327301e-01,
204  1.2031201562403160e-01,
205  1.0762679025358080e-01,
206  9.2690960381921039e-02,
207  7.5504526009052109e-02,
208  5.6067487134974447e-02,
209  3.4379843759687612e-02,
210  1.0441595883192045e-02,
211  2.5263113026225914e-02,
212  6.6524195548390952e-02,
213  1.0590977431954868e-01,
214  1.4341984933969865e-01,
215  1.7905442060884114e-01,
216  2.1281348812697637e-01,
217  2.4469705189410379e-01,
218  2.7470511191022379e-01,
219  3.0283766817533631e-01,
220  3.2909472068944123e-01,
221  3.5347626945253896e-01,
222  3.7598231446462893e-01,
223  3.9661285572571137e-01,
224  4.1536789323578649e-01,
225  4.3224742699485402e-01,
226  4.4725145700291402e-01,
227  4.6037998325996649e-01,
228  4.7163300576601147e-01,
229  4.8101052452104903e-01,
230  4.8851253952507906e-01,
231  4.9413905077810155e-01,
232  4.9789005828011657e-01,
233  4.9976556203112404e-01,
234  5.0023443796887590e-01,
235  5.0210994171988343e-01,
236  5.0586094922189839e-01,
237  5.1148746047492089e-01,
238  5.1898947547895091e-01,
239  5.2836699423398847e-01,
240  5.3962001674003346e-01,
241  5.5274854299708598e-01,
242  5.6775257300514603e-01,
243  5.8463210676421351e-01,
244  6.0338714427428841e-01,
245  6.2401768553537096e-01,
246  6.4652373054746126e-01,
247  6.7090527931055877e-01,
248  6.9716233182466369e-01,
249  7.2529488808977627e-01,
250  7.5530294810589615e-01,
251  7.8718651187302369e-01,
252  8.2094557939115864e-01,
253  8.5658015066030102e-01,
254  8.9409022568045105e-01,
255  9.3347580445160905e-01,
256  9.7473688697377403e-01,
257  9.8955840411680795e-01,
258  9.6562015624031239e-01,
259  9.4393251286502555e-01,
260  9.2449547399094789e-01,
261  9.0730903961807896e-01,
262  8.9237320974641920e-01,
263  8.7968798437596840e-01,
264  8.6925336350672699e-01,
265  8.6106934713869432e-01,
266  8.5513593527187037e-01,
267  8.5145312790625538e-01,
268  8.5002092504184956e-01,
269  8.5083932667865292e-01,
270  8.5390833281666545e-01,
271  8.5922794345588649e-01,
272  8.6679815859631715e-01,
273  8.7661897823795631e-01,
274  8.8869040238080443e-01,
275  9.0301243102486173e-01,
276  9.1958506417012775e-01,
277  9.3840830181660340e-01,
278  9.5948214396428777e-01,
279  9.8280659061318043e-01,
280  9.9492976382074660e-01,
281  9.8096706110309739e-01,
282  9.6999685190506169e-01,
283  9.6201913622663859e-01,
284  9.5703391406782767e-01,
285  9.5504118542863159e-01,
286  9.5604095030904723e-01,
287  9.6003320870907682e-01,
288  9.6701796062871992e-01,
289  9.7699520606797474e-01,
290  9.8996494502684307e-01,
291  9.9718767437534872e-01,
292  9.9096038192076463e-01,
293  9.8741149482299040e-01,
294  9.8654101308202691e-01,
295  9.8834893669787416e-01,
296  9.9283526567053126e-01,
297  1.0000000000000009e+00
298  };
299 
300  // setup Function
301  this->setAttributeValue(TT("function"), TT("easeInOutBounce"));
302 
303 
304  // create 1 channel audio signal objects
305  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
306  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
307  input->allocWithVectorSize(N);
308  output->allocWithVectorSize(N);
309 
310  // create a signal to be transformed and then process it)
311  input->clear();
312  for (int i=0; i<N; i++)
313  input->mSampleVectors[0][i] = inputSignal1[i];
314 
315  this->process(input, output);
316 
317  // now test the output
318  for (int n=0; n<N; n++)
319  {
320  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
321  badSampleCount += result;
322  if (result)
323  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
324  }
325 
326  TTTestAssertion("Produces correct function values",
327  badSampleCount == 0,
328  testAssertionCount,
329  errorCount);
330  if (badSampleCount)
331  TTTestLog("badSampleCount is %i", badSampleCount);
332 
333 
334  TTObjectBaseRelease(&input);
335  TTObjectBaseRelease(&output);
336 
337  // wrap up test results and pass back to whoever called test
338  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
339 
340 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTBounceEaseInOutFunction Unit for Jamoms DSP
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
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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