Jamoma API  0.6.0.a19
TTBackEaseOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTBackEaseOutFunction 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"
18 #include "TTBackEaseOutFunction.h"
19 
20 
21 /*
22  * coefficients calculated in Octave using:
23 
24  x = linspace(0,1,128);
25  f = (1 - x);
26  y = 1 - (f .* f .* f - f .* sin(f * pi));
27  printf("%.16e,\n", y)
28  plot(x, y)
29 
30  */
31 
33 {
34  int errorCount = 0;
35  int testAssertionCount = 0;
36  int badSampleCount = 0;
37  TTAudioSignalPtr input = NULL;
38  TTAudioSignalPtr output = NULL;
39  int N = 128;
40  TTValue v;
41 
42 
43  TTFloat64 inputSignal1[128] = {
44  0.0000000000000000e+00,
45  7.8740157480314960e-03,
46  1.5748031496062992e-02,
47  2.3622047244094488e-02,
48  3.1496062992125984e-02,
49  3.9370078740157480e-02,
50  4.7244094488188976e-02,
51  5.5118110236220472e-02,
52  6.2992125984251968e-02,
53  7.0866141732283464e-02,
54  7.8740157480314960e-02,
55  8.6614173228346455e-02,
56  9.4488188976377951e-02,
57  1.0236220472440945e-01,
58  1.1023622047244094e-01,
59  1.1811023622047244e-01,
60  1.2598425196850394e-01,
61  1.3385826771653542e-01,
62  1.4173228346456693e-01,
63  1.4960629921259844e-01,
64  1.5748031496062992e-01,
65  1.6535433070866140e-01,
66  1.7322834645669291e-01,
67  1.8110236220472442e-01,
68  1.8897637795275590e-01,
69  1.9685039370078738e-01,
70  2.0472440944881889e-01,
71  2.1259842519685040e-01,
72  2.2047244094488189e-01,
73  2.2834645669291337e-01,
74  2.3622047244094488e-01,
75  2.4409448818897639e-01,
76  2.5196850393700787e-01,
77  2.5984251968503935e-01,
78  2.6771653543307083e-01,
79  2.7559055118110237e-01,
80  2.8346456692913385e-01,
81  2.9133858267716534e-01,
82  2.9921259842519687e-01,
83  3.0708661417322836e-01,
84  3.1496062992125984e-01,
85  3.2283464566929132e-01,
86  3.3070866141732280e-01,
87  3.3858267716535434e-01,
88  3.4645669291338582e-01,
89  3.5433070866141730e-01,
90  3.6220472440944884e-01,
91  3.7007874015748032e-01,
92  3.7795275590551181e-01,
93  3.8582677165354329e-01,
94  3.9370078740157477e-01,
95  4.0157480314960631e-01,
96  4.0944881889763779e-01,
97  4.1732283464566927e-01,
98  4.2519685039370081e-01,
99  4.3307086614173229e-01,
100  4.4094488188976377e-01,
101  4.4881889763779526e-01,
102  4.5669291338582674e-01,
103  4.6456692913385828e-01,
104  4.7244094488188976e-01,
105  4.8031496062992124e-01,
106  4.8818897637795278e-01,
107  4.9606299212598426e-01,
108  5.0393700787401574e-01,
109  5.1181102362204722e-01,
110  5.1968503937007871e-01,
111  5.2755905511811019e-01,
112  5.3543307086614167e-01,
113  5.4330708661417326e-01,
114  5.5118110236220474e-01,
115  5.5905511811023623e-01,
116  5.6692913385826771e-01,
117  5.7480314960629919e-01,
118  5.8267716535433067e-01,
119  5.9055118110236215e-01,
120  5.9842519685039375e-01,
121  6.0629921259842523e-01,
122  6.1417322834645671e-01,
123  6.2204724409448819e-01,
124  6.2992125984251968e-01,
125  6.3779527559055116e-01,
126  6.4566929133858264e-01,
127  6.5354330708661412e-01,
128  6.6141732283464560e-01,
129  6.6929133858267720e-01,
130  6.7716535433070868e-01,
131  6.8503937007874016e-01,
132  6.9291338582677164e-01,
133  7.0078740157480313e-01,
134  7.0866141732283461e-01,
135  7.1653543307086609e-01,
136  7.2440944881889768e-01,
137  7.3228346456692917e-01,
138  7.4015748031496065e-01,
139  7.4803149606299213e-01,
140  7.5590551181102361e-01,
141  7.6377952755905509e-01,
142  7.7165354330708658e-01,
143  7.7952755905511806e-01,
144  7.8740157480314954e-01,
145  7.9527559055118113e-01,
146  8.0314960629921262e-01,
147  8.1102362204724410e-01,
148  8.1889763779527558e-01,
149  8.2677165354330706e-01,
150  8.3464566929133854e-01,
151  8.4251968503937003e-01,
152  8.5039370078740162e-01,
153  8.5826771653543310e-01,
154  8.6614173228346458e-01,
155  8.7401574803149606e-01,
156  8.8188976377952755e-01,
157  8.8976377952755903e-01,
158  8.9763779527559051e-01,
159  9.0551181102362199e-01,
160  9.1338582677165348e-01,
161  9.2125984251968507e-01,
162  9.2913385826771655e-01,
163  9.3700787401574803e-01,
164  9.4488188976377951e-01,
165  9.5275590551181100e-01,
166  9.6062992125984248e-01,
167  9.6850393700787396e-01,
168  9.7637795275590555e-01,
169  9.8425196850393704e-01,
170  9.9212598425196852e-01,
171  1.0000000000000000e+00
172  };
173 
174 
175  TTFloat64 expectedSignal1[128] = {
176  1.1102230246251565e-16,
177  4.7976203072120360e-02,
178  9.5178919703606368e-02,
179  1.4159666846106500e-01,
180  1.8721846223341077e-01,
181  2.3203381638264620e-01,
182  2.7603275644175118e-01,
183  3.1920582535528719e-01,
184  3.6154409025867262e-01,
185  4.0303914879248737e-01,
186  4.4368313494850720e-01,
187  4.8346872444456779e-01,
188  5.2238913962570965e-01,
189  5.6043815388945473e-01,
190  5.9761009563343404e-01,
191  6.3389985172395502e-01,
192  6.6930287048449033e-01,
193  7.0381516420344004e-01,
194  7.3743331116090083e-01,
195  7.7015445717455022e-01,
196  8.0197631666512892e-01,
197  8.3289717324238910e-01,
198  8.6291587981273865e-01,
199  8.9203185821019138e-01,
200  9.2024509835259993e-01,
201  9.4755615692551809e-01,
202  9.7396615559640187e-01,
203  9.9947677876222762e-01,
204  1.0240902708339499e+00,
205  1.0478094330616039e+00,
206  1.0706376199041807e+00,
207  1.0925787349487699e+00,
208  1.1136372263838075e+00,
209  1.1338180820316002e+00,
210  1.1531268239456391e+00,
211  1.1715695025785400e+00,
212  1.1891526905267800e+00,
213  1.2058834758587171e+00,
214  1.2217694550326899e+00,
215  1.2368187254123097e+00,
216  1.2510398773863596e+00,
217  1.2644419861010001e+00,
218  1.2770346028122928e+00,
219  1.2888277458673090e+00,
220  1.2998318913223943e+00,
221  1.3100579632074063e+00,
222  1.3195173234450190e+00,
223  1.3282217614344365e+00,
224  1.3361834833091035e+00,
225  1.3434151008782453e+00,
226  1.3499296202622932e+00,
227  1.3557404302324805e+00,
228  1.3608612902651029e+00,
229  1.3653063183211509e+00,
230  1.3690899783622084e+00,
231  1.3722270676137092e+00,
232  1.3747327035868215e+00,
233  1.3766223108703939e+00,
234  1.3779116077045681e+00,
235  1.3786165923478073e+00,
236  1.3787535292492397e+00,
237  1.3783389350383395e+00,
238  1.3773895643441061e+00,
239  1.3759223954560005e+00,
240  1.3739546158390161e+00,
241  1.3715036075153475e+00,
242  1.3685869323252078e+00,
243  1.3652223170794233e+00,
244  1.3614276386164939e+00,
245  1.3572209087768674e+00,
246  1.3526202593072187e+00,
247  1.3476439267075606e+00,
248  1.3423102370340374e+00,
249  1.3366375906702714e+00,
250  1.3306444470801273e+00,
251  1.3243493095547680e+00,
252  1.3177707099668492e+00,
253  1.3109271935446811e+00,
254  1.3038373036791475e+00,
255  1.2965195667761280e+00,
256  1.2889924771671160e+00,
257  1.2812744820906570e+00,
258  1.2733839667571603e+00,
259  1.2653392395095504e+00,
260  1.2571585170921311e+00,
261  1.2488599100399336e+00,
262  1.2404614082007019e+00,
263  1.2319808664015510e+00,
264  1.2234359902722021e+00,
265  1.2148443222365504e+00,
266  1.2062232276841811e+00,
267  1.1975898813332830e+00,
268  1.1889612537962435e+00,
269  1.1803540983590322e+00,
270  1.1717849379852949e+00,
271  1.1632700525558877e+00,
272  1.1548254663543733e+00,
273  1.1464669358088018e+00,
274  1.1382099374998689e+00,
275  1.1300696564453272e+00,
276  1.1220609746702903e+00,
277  1.1141984600728247e+00,
278  1.1064963555939866e+00,
279  1.0989685687011925e+00,
280  1.0916286611935619e+00,
281  1.0844898393375981e+00,
282  1.0775649443412934e+00,
283  1.0708664431744743e+00,
284  1.0644064197429051e+00,
285  1.0581965664233808e+00,
286  1.0522481759667419e+00,
287  1.0465721337754386e+00,
288  1.0411789105619620e+00,
289  1.0360785553941496e+00,
290  1.0312806891330528e+00,
291  1.0267944982687285e+00,
292  1.0226287291589955e+00,
293  1.0187916826758643e+00,
294  1.0152912092640092e+00,
295  1.0121347044153242e+00,
296  1.0093291045632546e+00,
297  1.0068808834002581e+00,
298  1.0047960486214011e+00,
299  1.0030801390967492e+00,
300  1.0017382224748577e+00,
301  1.0007748932193188e+00,
302  1.0001942710799685e+00,
303  1.0000000000000000e+00
304  };
305 
306  // setup Function
307  this->setAttributeValue(TT("function"), TT("easeOutBack"));
308 
309 
310  // create 1 channel audio signal objects
311  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
312  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
313  input->allocWithVectorSize(N);
314  output->allocWithVectorSize(N);
315 
316  // create a signal to be transformed and then process it)
317  input->clear();
318  for (int i=0; i<N; i++)
319  input->mSampleVectors[0][i] = inputSignal1[i];
320 
321  this->process(input, output);
322 
323  // now test the output
324  for (int n=0; n<N; n++)
325  {
326  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
327  badSampleCount += result;
328  if (result)
329  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
330  }
331 
332  TTTestAssertion("Produces correct function values",
333  badSampleCount == 0,
334  testAssertionCount,
335  errorCount);
336  if (badSampleCount)
337  TTTestLog("badSampleCount is %i", badSampleCount);
338 
339 
340  TTObjectBaseRelease(&input);
341  TTObjectBaseRelease(&output);
342 
343  // wrap up test results and pass back to whoever called test
344  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
345 
346 }
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.
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTBackEaseOutFunction Unit for Jamoms 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