Jamoma API  0.6.0.a19
TTQuarticEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTQuarticEaseInOutFunction 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) .* (8 * x .* x .* x .* x)
27  f = x - 1
28  yb = (x >= 0.5) .* (-8 * f .* f .* f .* f + 1)
29  y = ya + yb
30 
31  printf("%.16e,\n", y)
32 
33 
34 
35  */
36 
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  3.0752123008369022e-08,
183  4.9203396813390436e-07,
184  2.4909219636778909e-06,
185  7.8725434901424697e-06,
186  1.9220076880230639e-05,
187  3.9854751418846255e-05,
188  7.3835847343094033e-05,
189  1.2596069584227951e-04,
190  2.0176467905790916e-04,
191  3.0752123008369022e-04,
192  4.5024183296553090e-04,
193  6.3767602270154008e-04,
194  8.7831138524202773e-04,
195  1.1813735574895045e-03,
196  1.5568262272986819e-03,
197  2.0153711334764722e-03,
198  2.5684480657819880e-03,
199  3.2282348649265466e-03,
200  4.0076474225736614e-03,
201  4.9203396813390435e-03,
202  5.9807036347906146e-03,
203  7.2038693274484944e-03,
204  8.6057048547849967e-03,
205  1.0202816363224641e-02,
206  1.2012548050144147e-02,
207  1.4052982163872444e-02,
208  1.6342939003690649e-02,
209  1.8901976919832073e-02,
210  2.1750392313482244e-02,
211  2.4909219636778911e-02,
212  2.8400231392811975e-02,
213  3.2245938135623556e-02,
214  3.6469588470207995e-02,
215  4.1095169052511808e-02,
216  4.6147404589433776e-02,
217  5.1651757838824745e-02,
218  5.7634429609487892e-02,
219  6.4122358761178583e-02,
220  7.1143222204604256e-02,
221  7.8725434901424696e-02,
222  8.6898149864251845e-02,
223  9.5691258156649833e-02,
224  1.0513538889313505e-01,
225  1.1526190923917591e-01,
226  1.2610292441119322e-01,
227  1.3769127767655995e-01,
228  1.5006055035360116e-01,
229  1.6324506181159426e-01,
230  1.7727986947076874e-01,
231  1.9220076880230635e-01,
232  2.0804429332834115e-01,
233  2.2484771462195910e-01,
234  2.4264904230719855e-01,
235  2.6148702405905039e-01,
236  2.8140114560345680e-01,
237  3.0243163071731316e-01,
238  3.2461944122846637e-01,
239  3.4800627701571590e-01,
240  3.7263457600881350e-01,
241  3.9854751418846257e-01,
242  4.2578900558631916e-01,
243  4.5440370228499161e-01,
244  4.8443699441803995e-01,
245  5.1556300558196000e-01,
246  5.4559629771500839e-01,
247  5.7421099441368073e-01,
248  6.0145248581153732e-01,
249  6.2736542399118633e-01,
250  6.5199372298428404e-01,
251  6.7538055877153358e-01,
252  6.9756836928268684e-01,
253  7.1859885439654314e-01,
254  7.3851297594094967e-01,
255  7.5735095769280125e-01,
256  7.7515228537804082e-01,
257  7.9195570667165893e-01,
258  8.0779923119769359e-01,
259  8.2272013052923132e-01,
260  8.3675493818840574e-01,
261  8.4993944964639878e-01,
262  8.6230872232344002e-01,
263  8.7389707558880669e-01,
264  8.8473809076082399e-01,
265  8.9486461110686488e-01,
266  9.0430874184335019e-01,
267  9.1310185013574818e-01,
268  9.2127456509857530e-01,
269  9.2885677779539577e-01,
270  9.3587764123882144e-01,
271  9.4236557039051205e-01,
272  9.4834824216117519e-01,
273  9.5385259541056622e-01,
274  9.5890483094748824e-01,
275  9.6353041152979202e-01,
276  9.6775406186437640e-01,
277  9.7159976860718800e-01,
278  9.7509078036322105e-01,
279  9.7824960768651770e-01,
280  9.8109802308016791e-01,
281  9.8365706099630934e-01,
282  9.8594701783612759e-01,
283  9.8798745194985582e-01,
284  9.8979718363677538e-01,
285  9.9139429514521504e-01,
286  9.9279613067255146e-01,
287  9.9401929636520936e-01,
288  9.9507966031866091e-01,
289  9.9599235257742635e-01,
290  9.9677176513507348e-01,
291  9.9743155193421806e-01,
292  9.9798462886652350e-01,
293  9.9844317377270131e-01,
294  9.9881862644251052e-01,
295  9.9912168861475792e-01,
296  9.9936232397729841e-01,
297  9.9954975816703451e-01,
298  9.9969247876991629e-01,
299  9.9979823532094214e-01,
300  9.9987403930415775e-01,
301  9.9992616415265689e-01,
302  9.9996014524858112e-01,
303  9.9998077992311973e-01,
304  9.9999212745650989e-01,
305  9.9999750907803631e-01,
306  9.9999950796603188e-01,
307  9.9999996924787704e-01,
308  1.0000000000000000e+00
309  };
310 
311  // setup Function
312  this->setAttributeValue(TT("function"), TT("easeInOutQuartic"));
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.
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
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTQuarticEaseInOutFunction Unit for Jamoms DSP