Jamoma API  0.6.0.a19
TTElasticEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTElasticEaseInOutFunction 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) .* (0.5 * sin(13 * pi * 0.5 * (2 * x)) .* (2 .^ (10 * ((2 * x) - 1))))
27  yb = (x >= 0.5) .* ( 0.5 * (sin(-13 * pi * 0.5 * ((2 * x - 1) + 1)) .* (2 .^ (-10 * (2 * x - 1))) + 2) )
28 
29  y = ya + yb
30 
31  printf("%.16e,\n", y)
32 
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.7212919087887220e-04,
183  3.6428115825032776e-04,
184  5.5681212538514341e-04,
185  7.2523729129917911e-04,
186  8.4217530142449161e-04,
187  8.8013688122700728e-04,
188  8.1500761062674716e-04,
189  6.2994960545508731e-04,
190  3.1932624629521728e-04,
191  -1.0784542795925848e-04,
192  -6.2547061152585625e-04,
193  -1.1895412328992759e-03,
194  -1.7393833055452798e-03,
195  -2.2013360681815437e-03,
196  -2.4949865616371398e-03,
197  -2.5417872457472106e-03,
198  -2.2755379952188381e-03,
199  -1.6538492770053939e-03,
200  -6.6936257989751744e-04,
201  6.4076345679647568e-04,
202  2.1887352845862532e-03,
203  3.8349778181745071e-03,
204  5.3933181551453551e-03,
205  6.6433823861694963e-03,
206  7.3503828317161681e-03,
207  7.2915728928402450e-03,
208  6.2876192086438873e-03,
209  4.2360860651949588e-03,
210  1.1432729932745308e-03,
211  -2.8500604137973850e-03,
212  -7.4538577095366433e-03,
213  -1.2229367236301886e-02,
214  -1.6608872031544694e-02,
215  -1.9936696275030769e-02,
216  -2.1531444658621453e-02,
217  -2.0766709959568155e-02,
218  -1.7164452036046624e-02,
219  -1.0492219625767187e-02,
220  -8.5274179465549349e-04,
221  1.1247409269414112e-02,
222  2.4863955294929865e-02,
223  3.8628661908787582e-02,
224  5.0820562824315484e-02,
225  5.9499588637134289e-02,
226  6.2700767366834734e-02,
227  5.8678984504384434e-02,
228  4.6185393459574682e-02,
229  2.4747913615511853e-02,
230  -5.0789933075330949e-03,
231  -4.1534648835194088e-02,
232  -8.1582624664898892e-02,
233  -1.2098709911298249e-01,
234  -1.5456094969936141e-01,
235  -1.7659581175034159e-01,
236  -1.8146360014809260e-01,
237  -1.6435454100319857e-01,
238  -1.2209080623811928e-01,
239  -5.3930333133583058e-02,
240  3.7744176260350017e-02,
241  1.4696704264767757e-01,
242  2.6407698327710605e-01,
243  3.7604876448408031e-01,
244  4.6733519045813759e-01,
245  5.3266480954186257e-01,
246  6.2395123551592002e-01,
247  7.3592301672289429e-01,
248  8.5303295735232298e-01,
249  9.6225582373965057e-01,
250  1.0539303331335836e+00,
251  1.1220908062381196e+00,
252  1.1643545410031988e+00,
253  1.1814636001480927e+00,
254  1.1765958117503417e+00,
255  1.1545609496993614e+00,
256  1.1209870991129824e+00,
257  1.0815826246648983e+00,
258  1.0415346488351940e+00,
259  1.0050789933075328e+00,
260  9.7525208638448802e-01,
261  9.5381460654042516e-01,
262  9.4132101549561553e-01,
263  9.3729923263316528e-01,
264  9.4050041136286566e-01,
265  9.4917943717568443e-01,
266  9.6137133809121245e-01,
267  9.7513604470507009e-01,
268  9.8875259073058586e-01,
269  1.0008527417946556e+00,
270  1.0104922196257673e+00,
271  1.0171644520360466e+00,
272  1.0207667099595681e+00,
273  1.0215314446586214e+00,
274  1.0199366962750307e+00,
275  1.0166088720315447e+00,
276  1.0122293672363019e+00,
277  1.0074538577095367e+00,
278  1.0028500604137973e+00,
279  9.9885672700672545e-01,
280  9.9576391393480501e-01,
281  9.9371238079135615e-01,
282  9.9270842710715979e-01,
283  9.9264961716828382e-01,
284  9.9335661761383054e-01,
285  9.9460668184485468e-01,
286  9.9616502218182545e-01,
287  9.9781126471541370e-01,
288  9.9935923654320347e-01,
289  1.0006693625798975e+00,
290  1.0016538492770055e+00,
291  1.0022755379952188e+00,
292  1.0025417872457472e+00,
293  1.0024949865616370e+00,
294  1.0022013360681816e+00,
295  1.0017393833055452e+00,
296  1.0011895412328993e+00,
297  1.0006254706115258e+00,
298  1.0001078454279593e+00,
299  9.9968067375370473e-01,
300  9.9937005039454496e-01,
301  9.9918499238937331e-01,
302  9.9911986311877299e-01,
303  9.9915782469857550e-01,
304  9.9927476270870086e-01,
305  9.9944318787461484e-01,
306  9.9963571884174962e-01,
307  9.9982787080912117e-01,
308  1.0000000000000000e+00
309  };
310 
311  // setup Function
312  this->setAttributeValue(TT("function"), TT("easeInOutElastic"));
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
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
#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.
TTElasticEaseInOutFunction 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