Jamoma API  0.6.0.a19
TTQuinticEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTQuinticEaseInOutFunction 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:
23 
24  x = linspace(0,1,128);
25 
26  ya = (x < 0.5) .* (16 * x .* x .* x .* x .* x)
27  f = ((2 * x) - 2)
28  yb = (x >= 0.5) .* (0.5 * f .* f .* f .* f .* f + 1)
29  y = ya + yb
30 
31  printf("%.16e,\n", y)
32  plot (x,y)
33  */
34 
36 {
37  int errorCount = 0;
38  int testAssertionCount = 0;
39  int badSampleCount = 0;
40  TTAudioSignalPtr input = NULL;
41  TTAudioSignalPtr output = NULL;
42  int N = 128;
43  TTValue v;
44 
45 
46  TTFloat64 inputSignal1[128] = {
47  0.0000000000000000e+00,
48  7.8740157480314960e-03,
49  1.5748031496062992e-02,
50  2.3622047244094488e-02,
51  3.1496062992125984e-02,
52  3.9370078740157480e-02,
53  4.7244094488188976e-02,
54  5.5118110236220472e-02,
55  6.2992125984251968e-02,
56  7.0866141732283464e-02,
57  7.8740157480314960e-02,
58  8.6614173228346455e-02,
59  9.4488188976377951e-02,
60  1.0236220472440945e-01,
61  1.1023622047244094e-01,
62  1.1811023622047244e-01,
63  1.2598425196850394e-01,
64  1.3385826771653542e-01,
65  1.4173228346456693e-01,
66  1.4960629921259844e-01,
67  1.5748031496062992e-01,
68  1.6535433070866140e-01,
69  1.7322834645669291e-01,
70  1.8110236220472442e-01,
71  1.8897637795275590e-01,
72  1.9685039370078738e-01,
73  2.0472440944881889e-01,
74  2.1259842519685040e-01,
75  2.2047244094488189e-01,
76  2.2834645669291337e-01,
77  2.3622047244094488e-01,
78  2.4409448818897639e-01,
79  2.5196850393700787e-01,
80  2.5984251968503935e-01,
81  2.6771653543307083e-01,
82  2.7559055118110237e-01,
83  2.8346456692913385e-01,
84  2.9133858267716534e-01,
85  2.9921259842519687e-01,
86  3.0708661417322836e-01,
87  3.1496062992125984e-01,
88  3.2283464566929132e-01,
89  3.3070866141732280e-01,
90  3.3858267716535434e-01,
91  3.4645669291338582e-01,
92  3.5433070866141730e-01,
93  3.6220472440944884e-01,
94  3.7007874015748032e-01,
95  3.7795275590551181e-01,
96  3.8582677165354329e-01,
97  3.9370078740157477e-01,
98  4.0157480314960631e-01,
99  4.0944881889763779e-01,
100  4.1732283464566927e-01,
101  4.2519685039370081e-01,
102  4.3307086614173229e-01,
103  4.4094488188976377e-01,
104  4.4881889763779526e-01,
105  4.5669291338582674e-01,
106  4.6456692913385828e-01,
107  4.7244094488188976e-01,
108  4.8031496062992124e-01,
109  4.8818897637795278e-01,
110  4.9606299212598426e-01,
111  5.0393700787401574e-01,
112  5.1181102362204722e-01,
113  5.1968503937007871e-01,
114  5.2755905511811019e-01,
115  5.3543307086614167e-01,
116  5.4330708661417326e-01,
117  5.5118110236220474e-01,
118  5.5905511811023623e-01,
119  5.6692913385826771e-01,
120  5.7480314960629919e-01,
121  5.8267716535433067e-01,
122  5.9055118110236215e-01,
123  5.9842519685039375e-01,
124  6.0629921259842523e-01,
125  6.1417322834645671e-01,
126  6.2204724409448819e-01,
127  6.2992125984251968e-01,
128  6.3779527559055116e-01,
129  6.4566929133858264e-01,
130  6.5354330708661412e-01,
131  6.6141732283464560e-01,
132  6.6929133858267720e-01,
133  6.7716535433070868e-01,
134  6.8503937007874016e-01,
135  6.9291338582677164e-01,
136  7.0078740157480313e-01,
137  7.0866141732283461e-01,
138  7.1653543307086609e-01,
139  7.2440944881889768e-01,
140  7.3228346456692917e-01,
141  7.4015748031496065e-01,
142  7.4803149606299213e-01,
143  7.5590551181102361e-01,
144  7.6377952755905509e-01,
145  7.7165354330708658e-01,
146  7.7952755905511806e-01,
147  7.8740157480314954e-01,
148  7.9527559055118113e-01,
149  8.0314960629921262e-01,
150  8.1102362204724410e-01,
151  8.1889763779527558e-01,
152  8.2677165354330706e-01,
153  8.3464566929133854e-01,
154  8.4251968503937003e-01,
155  8.5039370078740162e-01,
156  8.5826771653543310e-01,
157  8.6614173228346458e-01,
158  8.7401574803149606e-01,
159  8.8188976377952755e-01,
160  8.8976377952755903e-01,
161  8.9763779527559051e-01,
162  9.0551181102362199e-01,
163  9.1338582677165348e-01,
164  9.2125984251968507e-01,
165  9.2913385826771655e-01,
166  9.3700787401574803e-01,
167  9.4488188976377951e-01,
168  9.5275590551181100e-01,
169  9.6062992125984248e-01,
170  9.6850393700787396e-01,
171  9.7637795275590555e-01,
172  9.8425196850393704e-01,
173  9.9212598425196852e-01,
174  1.0000000000000000e+00
175  };
176 
177 
178  TTFloat64 expectedSignal1[128] = {
179  0.0000000000000000e+00,
180  4.8428540170659879e-10,
181  1.5497132854611161e-08,
182  1.1768135261470351e-07,
183  4.9590825134755716e-07,
184  1.5133918803331211e-06,
185  3.7658032836705123e-06,
186  8.1393847464828061e-06,
187  1.5869064043121829e-05,
188  2.8596568685372951e-05,
189  4.8428540170659875e-05,
190  7.7994648230249452e-05,
191  1.2050570507745639e-04,
192  1.7981177965584820e-04,
193  2.6046031188744980e-04,
194  3.6775422692094848e-04,
195  5.0781004937989853e-04,
196  6.8761601761092579e-04,
197  9.1509019793193443e-04,
198  1.1991385988803082e-03,
199  1.5497132854611160e-03,
200  1.9778704933953212e-03,
201  2.4958287433679825e-03,
202  3.1170269552764558e-03,
203  3.8561825624786046e-03,
204  4.7293496260410028e-03,
205  5.7539769489871424e-03,
206  6.9489661905456305e-03,
207  8.3347299803983935e-03,
208  9.9332500329288986e-03,
209  1.1768135261470351e-02,
210  1.3864679892553878e-02,
211  1.6249921580156753e-02,
212  1.8952699519950610e-02,
213  2.2003712563549625e-02,
214  2.5435577332758776e-02,
215  2.9282886333821902e-02,
216  3.3582266071670107e-02,
217  3.8372435164169862e-02,
218  4.3694262456371119e-02,
219  4.9590825134755712e-02,
220  5.6107466841485439e-02,
221  6.3291855788650278e-02,
222  7.1194042872516655e-02,
223  7.9866519787775439e-02,
224  8.9364277141790474e-02,
225  9.9744862568846585e-02,
226  1.1106843884439771e-01,
227  1.2339784199931535e-01,
228  1.3679863943413650e-01,
229  1.5133918803331209e-01,
230  1.6709069227945511e-01,
231  1.8412726236758856e-01,
232  2.0252597231939407e-01,
233  2.2236691809746018e-01,
234  2.4373327571952952e-01,
235  2.6671135937274859e-01,
236  2.9139067952791470e-01,
237  3.1786400105372475e-01,
238  3.4622740133102359e-01,
239  3.7658032836705124e-01,
240  4.0902565890969239e-01,
241  4.4366975656172408e-01,
242  4.8062252989506327e-01,
243  5.1937747010493673e-01,
244  5.5633024343827597e-01,
245  5.9097434109030744e-01,
246  6.2341967163294854e-01,
247  6.5377259866897619e-01,
248  6.8213599894627519e-01,
249  7.0860932047208536e-01,
250  7.3328864062725141e-01,
251  7.5626672428047048e-01,
252  7.7763308190253988e-01,
253  7.9747402768060582e-01,
254  8.1587273763241130e-01,
255  8.3290930772054494e-01,
256  8.4866081196668786e-01,
257  8.6320136056586350e-01,
258  8.7660215800068464e-01,
259  8.8893156115560235e-01,
260  9.0025513743115337e-01,
261  9.1063572285820948e-01,
262  9.2013348021222452e-01,
263  9.2880595712748326e-01,
264  9.3670814421134974e-01,
265  9.4389253315851451e-01,
266  9.5040917486524434e-01,
267  9.5630573754362891e-01,
268  9.6162756483583012e-01,
269  9.6641773392832986e-01,
270  9.7071711366617808e-01,
271  9.7456442266724130e-01,
272  9.7799628743645040e-01,
273  9.8104730048004940e-01,
274  9.8375007841984330e-01,
275  9.8613532010744609e-01,
276  9.8823186473852964e-01,
277  9.9006674996707111e-01,
278  9.9166527001960159e-01,
279  9.9305103380945436e-01,
280  9.9424602305101284e-01,
281  9.9527065037395901e-01,
282  9.9614381743752145e-01,
283  9.9688297304472351e-01,
284  9.9750417125663204e-01,
285  9.9802212950660463e-01,
286  9.9845028671453884e-01,
287  9.9880086140111968e-01,
288  9.9908490980206810e-01,
289  9.9931238398238909e-01,
290  9.9949218995062006e-01,
291  9.9963224577307908e-01,
292  9.9973953968811258e-01,
293  9.9982018822034413e-01,
294  9.9987949429492251e-01,
295  9.9992200535176978e-01,
296  9.9995157145982938e-01,
297  9.9997140343131463e-01,
298  9.9998413093595684e-01,
299  9.9999186061525347e-01,
300  9.9999623419671635e-01,
301  9.9999848660811963e-01,
302  9.9999950409174865e-01,
303  9.9999988231864734e-01,
304  9.9999998450286720e-01,
305  9.9999999951571461e-01,
306  1.0000000000000000e+00
307  };
308 
309  // setup Function
310  this->setAttributeValue(TT("function"), TT("easeInOutQuintic"));
311 
312 
313  // create 1 channel audio signal objects
314  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
315  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
316  input->allocWithVectorSize(N);
317  output->allocWithVectorSize(N);
318 
319  // create a signal to be transformed and then process it)
320  input->clear();
321  for (int i=0; i<N; i++)
322  input->mSampleVectors[0][i] = inputSignal1[i];
323 
324  this->process(input, output);
325 
326  // now test the output
327  for (int n=0; n<N; n++)
328  {
329  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
330  badSampleCount += result;
331  if (result)
332  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
333  }
334 
335  TTTestAssertion("Produces correct function values",
336  badSampleCount == 0,
337  testAssertionCount,
338  errorCount);
339  if (badSampleCount)
340  TTTestLog("badSampleCount is %i", badSampleCount);
341 
342 
343  TTObjectBaseRelease(&input);
344  TTObjectBaseRelease(&output);
345 
346  // wrap up test results and pass back to whoever called test
347  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
348 
349 }
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.
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.
TTQuinticEaseInOutFunction Unit for Jamoms DSP
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