Jamoma API  0.6.0.a19
TTCubicEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTCubicEaseInOutFunction 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) .* (4 * x .* x .* x)
27  f = ((2 * x) - 2);
28  yb = (x >= 0.5) .* (0.5 .* f .* f .* f + 1)
29 
30  y = ya + yb
31 
32  printf("%.16e,\n", y)
33  plot (x,y)
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  1.9527598110314327e-06,
183  1.5622078488251462e-05,
184  5.2724514897848688e-05,
185  1.2497662790601169e-04,
186  2.4409497637892913e-04,
187  4.2179611918278950e-04,
188  6.6979661518378158e-04,
189  9.9981302324809356e-04,
190  1.4235619022419147e-03,
191  1.9527598110314331e-03,
192  2.5991233084828374e-03,
193  3.3743689534623160e-03,
194  4.2902133048360585e-03,
195  5.3583729214702527e-03,
196  6.5905643622310864e-03,
197  7.9985041859847485e-03,
198  9.5939089515974275e-03,
199  1.1388495217935318e-02,
200  1.3393979543864603e-02,
201  1.5622078488251465e-02,
202  1.8084508609962097e-02,
203  2.0792986467862699e-02,
204  2.3759228620819448e-02,
205  2.6994951627698528e-02,
206  3.0511872047366134e-02,
207  3.4321706438688468e-02,
208  3.8436171360531707e-02,
209  4.2866983371762021e-02,
210  4.7625859031245610e-02,
211  5.2724514897848691e-02,
212  5.8174667530437429e-02,
213  6.3988033487877988e-02,
214  7.0176329329036599e-02,
215  7.6751271612779420e-02,
216  8.3724576897972705e-02,
217  9.1107961743482541e-02,
218  9.8913142708175167e-02,
219  1.0715183635091682e-01,
220  1.1583575923057358e-01,
221  1.2497662790601172e-01,
222  1.3458615893609738e-01,
223  1.4467606887969678e-01,
224  1.5525807429567617e-01,
225  1.6634389174290160e-01,
226  1.7794523778023932e-01,
227  1.9007382896655559e-01,
228  2.0274138186071647e-01,
229  2.1595961302158823e-01,
230  2.2974023900803706e-01,
231  2.4409497637892907e-01,
232  2.5903554169313064e-01,
233  2.7457365150950774e-01,
234  2.9072102238692660e-01,
235  3.0748937088425365e-01,
236  3.2489041356035470e-01,
237  3.4293586697409617e-01,
238  3.6163744768434414e-01,
239  3.8100687224996488e-01,
240  4.0105585722982467e-01,
241  4.2179611918278953e-01,
242  4.4323937466772567e-01,
243  4.6539734024349944e-01,
244  4.8828173246897677e-01,
245  5.1171826753102323e-01,
246  5.3460265975650056e-01,
247  5.5676062533227422e-01,
248  5.7820388081721030e-01,
249  5.9894414277017516e-01,
250  6.1899312775003512e-01,
251  6.3836255231565586e-01,
252  6.5706413302590383e-01,
253  6.7510958643964525e-01,
254  6.9251062911574635e-01,
255  7.0927897761307324e-01,
256  7.2542634849049215e-01,
257  7.4096445830686952e-01,
258  7.5590502362107093e-01,
259  7.7025976099196292e-01,
260  7.8404038697841183e-01,
261  7.9725861813928356e-01,
262  8.0992617103344444e-01,
263  8.2205476221976059e-01,
264  8.3365610825709835e-01,
265  8.4474192570432372e-01,
266  8.5532393112030325e-01,
267  8.6541384106390262e-01,
268  8.7502337209398828e-01,
269  8.8416424076942646e-01,
270  8.9284816364908315e-01,
271  9.0108685729182481e-01,
272  9.0889203825651743e-01,
273  9.1627542310202736e-01,
274  9.2324872838722061e-01,
275  9.2982367067096339e-01,
276  9.3601196651212204e-01,
277  9.4182533246956257e-01,
278  9.4727548510215132e-01,
279  9.5237414096875439e-01,
280  9.5713301662823791e-01,
281  9.6156382863946832e-01,
282  9.6567829356131152e-01,
283  9.6948812795263384e-01,
284  9.7300504837230151e-01,
285  9.7624077137918053e-01,
286  9.7920701353213724e-01,
287  9.8191549139003786e-01,
288  9.8437792151174852e-01,
289  9.8660602045613544e-01,
290  9.8861150478206472e-01,
291  9.9040609104840260e-01,
292  9.9200149581401520e-01,
293  9.9340943563776896e-01,
294  9.9464162707852977e-01,
295  9.9570978669516397e-01,
296  9.9662563104653767e-01,
297  9.9740087669151711e-01,
298  9.9804724018896862e-01,
299  9.9857643809775809e-01,
300  9.9900018697675186e-01,
301  9.9933020338481626e-01,
302  9.9957820388081720e-01,
303  9.9975590502362111e-01,
304  9.9987502337209400e-01,
305  9.9994727548510220e-01,
306  9.9998437792151174e-01,
307  9.9999804724018893e-01,
308  1.0000000000000000e+00
309  };
310 
311  // setup Function
312  this->setAttributeValue(TT("function"), TT("easeInOutCubic"));
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.
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
TTCubicEaseInOutFunction 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
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