Jamoma API  0.6.0.a19
TTQuinticEaseInFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTQuinticEaseInFunction 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  y = x .* x .* x .* x .* x;
26  printf("%.16e,\n", y)
27 
28  */
29 
31 {
32  int errorCount = 0;
33  int testAssertionCount = 0;
34  int badSampleCount = 0;
35  TTAudioSignalPtr input = NULL;
36  TTAudioSignalPtr output = NULL;
37  int N = 128;
38  TTValue v;
39 
40 
41  TTFloat64 inputSignal1[128] = {
42  0.0000000000000000e+00,
43  7.8740157480314960e-03,
44  1.5748031496062992e-02,
45  2.3622047244094488e-02,
46  3.1496062992125984e-02,
47  3.9370078740157480e-02,
48  4.7244094488188976e-02,
49  5.5118110236220472e-02,
50  6.2992125984251968e-02,
51  7.0866141732283464e-02,
52  7.8740157480314960e-02,
53  8.6614173228346455e-02,
54  9.4488188976377951e-02,
55  1.0236220472440945e-01,
56  1.1023622047244094e-01,
57  1.1811023622047244e-01,
58  1.2598425196850394e-01,
59  1.3385826771653542e-01,
60  1.4173228346456693e-01,
61  1.4960629921259844e-01,
62  1.5748031496062992e-01,
63  1.6535433070866140e-01,
64  1.7322834645669291e-01,
65  1.8110236220472442e-01,
66  1.8897637795275590e-01,
67  1.9685039370078738e-01,
68  2.0472440944881889e-01,
69  2.1259842519685040e-01,
70  2.2047244094488189e-01,
71  2.2834645669291337e-01,
72  2.3622047244094488e-01,
73  2.4409448818897639e-01,
74  2.5196850393700787e-01,
75  2.5984251968503935e-01,
76  2.6771653543307083e-01,
77  2.7559055118110237e-01,
78  2.8346456692913385e-01,
79  2.9133858267716534e-01,
80  2.9921259842519687e-01,
81  3.0708661417322836e-01,
82  3.1496062992125984e-01,
83  3.2283464566929132e-01,
84  3.3070866141732280e-01,
85  3.3858267716535434e-01,
86  3.4645669291338582e-01,
87  3.5433070866141730e-01,
88  3.6220472440944884e-01,
89  3.7007874015748032e-01,
90  3.7795275590551181e-01,
91  3.8582677165354329e-01,
92  3.9370078740157477e-01,
93  4.0157480314960631e-01,
94  4.0944881889763779e-01,
95  4.1732283464566927e-01,
96  4.2519685039370081e-01,
97  4.3307086614173229e-01,
98  4.4094488188976377e-01,
99  4.4881889763779526e-01,
100  4.5669291338582674e-01,
101  4.6456692913385828e-01,
102  4.7244094488188976e-01,
103  4.8031496062992124e-01,
104  4.8818897637795278e-01,
105  4.9606299212598426e-01,
106  5.0393700787401574e-01,
107  5.1181102362204722e-01,
108  5.1968503937007871e-01,
109  5.2755905511811019e-01,
110  5.3543307086614167e-01,
111  5.4330708661417326e-01,
112  5.5118110236220474e-01,
113  5.5905511811023623e-01,
114  5.6692913385826771e-01,
115  5.7480314960629919e-01,
116  5.8267716535433067e-01,
117  5.9055118110236215e-01,
118  5.9842519685039375e-01,
119  6.0629921259842523e-01,
120  6.1417322834645671e-01,
121  6.2204724409448819e-01,
122  6.2992125984251968e-01,
123  6.3779527559055116e-01,
124  6.4566929133858264e-01,
125  6.5354330708661412e-01,
126  6.6141732283464560e-01,
127  6.6929133858267720e-01,
128  6.7716535433070868e-01,
129  6.8503937007874016e-01,
130  6.9291338582677164e-01,
131  7.0078740157480313e-01,
132  7.0866141732283461e-01,
133  7.1653543307086609e-01,
134  7.2440944881889768e-01,
135  7.3228346456692917e-01,
136  7.4015748031496065e-01,
137  7.4803149606299213e-01,
138  7.5590551181102361e-01,
139  7.6377952755905509e-01,
140  7.7165354330708658e-01,
141  7.7952755905511806e-01,
142  7.8740157480314954e-01,
143  7.9527559055118113e-01,
144  8.0314960629921262e-01,
145  8.1102362204724410e-01,
146  8.1889763779527558e-01,
147  8.2677165354330706e-01,
148  8.3464566929133854e-01,
149  8.4251968503937003e-01,
150  8.5039370078740162e-01,
151  8.5826771653543310e-01,
152  8.6614173228346458e-01,
153  8.7401574803149606e-01,
154  8.8188976377952755e-01,
155  8.8976377952755903e-01,
156  8.9763779527559051e-01,
157  9.0551181102362199e-01,
158  9.1338582677165348e-01,
159  9.2125984251968507e-01,
160  9.2913385826771655e-01,
161  9.3700787401574803e-01,
162  9.4488188976377951e-01,
163  9.5275590551181100e-01,
164  9.6062992125984248e-01,
165  9.6850393700787396e-01,
166  9.7637795275590555e-01,
167  9.8425196850393704e-01,
168  9.9212598425196852e-01,
169  1.0000000000000000e+00
170  };
171 
172 
173  TTFloat64 expectedSignal1[128] = {
174  0.0000000000000000e+00,
175  3.0267837606662424e-11,
176  9.6857080341319758e-10,
177  7.3550845384189693e-09,
178  3.0994265709222322e-08,
179  9.4586992520820068e-08,
180  2.3536270522940702e-07,
181  5.0871154665517538e-07,
182  9.9181650269511432e-07,
183  1.7872855428358094e-06,
184  3.0267837606662422e-06,
185  4.8746655143905908e-06,
186  7.5316065673410246e-06,
187  1.1238236228490512e-05,
188  1.6278769492965612e-05,
189  2.2984639182559280e-05,
190  3.1738128086243658e-05,
191  4.2976001100682862e-05,
192  5.7193137370745902e-05,
193  7.4946162430019261e-05,
194  9.6857080341319749e-05,
195  1.2361690583720757e-04,
196  1.5598929646049890e-04,
197  1.9481418470477849e-04,
198  2.4101141015491279e-04,
199  2.9558435162756267e-04,
200  3.5962355931169640e-04,
201  4.3431038690910191e-04,
202  5.2092062377489959e-04,
203  6.2082812705805616e-04,
204  7.3550845384189696e-04,
205  8.6654249328461735e-04,
206  1.0156200987597971e-03,
207  1.1845437199969131e-03,
208  1.3752320352218516e-03,
209  1.5897235832974235e-03,
210  1.8301803958638689e-03,
211  2.0988916294793817e-03,
212  2.3982771977606164e-03,
213  2.7308914035231949e-03,
214  3.0994265709222320e-03,
215  3.5067166775928399e-03,
216  3.9557409867906424e-03,
217  4.4496276795322909e-03,
218  4.9916574867359649e-03,
219  5.5852673213619046e-03,
220  6.2340539105529115e-03,
221  6.9417774277748569e-03,
222  7.7123651249572092e-03,
223  8.5499149646335315e-03,
224  9.4586992520820055e-03,
225  1.0443168267465944e-02,
226  1.1507953897974285e-02,
227  1.2657873269962129e-02,
228  1.3897932381091261e-02,
229  1.5233329732470595e-02,
230  1.6669459960796787e-02,
231  1.8211917470494669e-02,
232  1.9866500065857797e-02,
233  2.1639212583188974e-02,
234  2.3536270522940703e-02,
235  2.5564103681855774e-02,
236  2.7729359785107755e-02,
237  3.0038908118441454e-02,
238  3.2499843160313506e-02,
239  3.5119488214032844e-02,
240  3.7905399039901221e-02,
241  4.0865367487353713e-02,
242  4.4007425127099251e-02,
243  4.7339846883261177e-02,
244  5.0871154665517553e-02,
245  5.4610121001241942e-02,
246  5.8565772667643803e-02,
247  6.2747394323908967e-02,
248  6.7164532143340214e-02,
249  7.1826997445497712e-02,
250  7.6744870328339723e-02,
251  8.1928503300362679e-02,
252  8.7388524912742238e-02,
253  9.3135843391473461e-02,
254  9.9181650269511423e-02,
255  1.0553742401891170e-01,
256  1.1221493368297088e-01,
257  1.1922624250836709e-01,
258  1.2658371157730056e-01,
259  1.3430000343963405e-01,
260  1.4238808574503331e-01,
261  1.5086123487510772e-01,
262  1.5973303957555088e-01,
263  1.6901740458828085e-01,
264  1.7872855428358095e-01,
265  1.8888103629223996e-01,
266  1.9948972513769317e-01,
267  2.1056982586816200e-01,
268  2.2213687768879542e-01,
269  2.3420675759381007e-01,
270  2.4679568399863069e-01,
271  2.5992022037203077e-01,
272  2.7359727886827301e-01,
273  2.8784412395924985e-01,
274  3.0267837606662418e-01,
275  3.1811801519396948e-01,
276  3.3418138455891022e-01,
277  3.5088719422526315e-01,
278  3.6825452473517711e-01,
279  3.8630283074127375e-01,
280  4.0505194463878813e-01,
281  4.2452208019770921e-01,
282  4.4473383619492035e-01,
283  4.6570820004633906e-01,
284  4.8746655143905904e-01,
285  5.1003066596348989e-01,
286  5.3342271874549718e-01,
287  5.5766528807854365e-01,
288  5.8278135905582940e-01,
289  6.0879432720243254e-01,
290  6.3572800210744951e-01,
291  6.6360661105613628e-01,
292  6.9245480266204718e-01,
293  7.2229765049917749e-01,
294  7.5316065673410248e-01,
295  7.8506975575811888e-01,
296  8.1805131781938478e-01,
297  8.5213215265506015e-01,
298  8.8733951312344816e-01,
299  9.2370109883613383e-01,
300  9.6124505979012653e-01,
301  1.0000000000000000e+00
302  };
303 
304  // setup Function
305  this->setAttributeValue(TT("function"), TT("easeInQuintic"));
306 
307 
308  // create 1 channel audio signal objects
309  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
310  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
311  input->allocWithVectorSize(N);
312  output->allocWithVectorSize(N);
313 
314  // create a signal to be transformed and then process it)
315  input->clear();
316  for (int i=0; i<N; i++)
317  input->mSampleVectors[0][i] = inputSignal1[i];
318 
319  this->process(input, output);
320 
321  // now test the output
322  for (int n=0; n<N; n++)
323  {
324  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
325  badSampleCount += result;
326  if (result)
327  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
328  }
329 
330  TTTestAssertion("Produces correct function values",
331  badSampleCount == 0,
332  testAssertionCount,
333  errorCount);
334  if (badSampleCount)
335  TTTestLog("badSampleCount is %i", badSampleCount);
336 
337 
338  TTObjectBaseRelease(&input);
339  TTObjectBaseRelease(&output);
340 
341  // wrap up test results and pass back to whoever called test
342  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
343 
344 }
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
TTQuinticEaseInFunction Unit for Jamoms DSP
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