Jamoma API  0.6.0.a19
TTElasticEaseOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTElasticEaseOutFunction 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 = sin(-13 * pi * 0.5 * (x + 1)) .* (2 .^ (-10 * x)) + 1
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  6.5329619083725254e-02,
176  1.4937216739555315e-01,
177  2.4790247103184038e-01,
178  3.5673750833773699e-01,
179  4.7184603344578868e-01,
180  5.8944272788628105e-01,
181  7.0606591470464608e-01,
182  8.1863841727331144e-01,
183  9.2451164747930337e-01,
184  1.0214934561920337e+00,
185  1.1078606662671673e+00,
186  1.1823575305614811e+00,
187  1.2441816124762395e+00,
188  1.2929587744091720e+00,
189  1.3287090820063978e+00,
190  1.3518054926847598e+00,
191  1.3629272002961854e+00,
192  1.3630094598486007e+00,
193  1.3531916235006831e+00,
194  1.3347649887625566e+00,
195  1.3091218993987228e+00,
196  1.2777073564325316e+00,
197  1.2419741982259642e+00,
198  1.2033427018464382e+00,
199  1.1631652493297966e+00,
200  1.1226964978802081e+00,
201  1.0830692976703877e+00,
202  1.0452764190927208e+00,
203  1.0101579866150658e+00,
204  9.7839437153194442e-01,
205  9.5050417276897592e-01,
206  9.2684681460370955e-01,
207  9.0762921308085032e-01,
208  8.9291590872445070e-01,
209  8.8264203099123095e-01,
210  8.7662844836714815e-01,
211  8.7459846526633056e-01,
212  8.7619545080568007e-01,
213  8.8100082272573144e-01,
214  8.8855185969083406e-01,
215  8.9835887435136896e-01,
216  9.0992134532569502e-01,
217  9.2274267618242478e-01,
218  9.3634332124020747e-01,
219  9.5027208941014030e-01,
220  9.6411550647345579e-01,
221  9.7750518146117182e-01,
222  9.9012318280694900e-01,
223  1.0017054835893111e+00,
224  1.0120435816605775e+00,
225  1.0209844392515344e+00,
226  1.0284289174812229e+00,
227  1.0343289040720931e+00,
228  1.0386833476731261e+00,
229  1.0415334199191364e+00,
230  1.0429570272557156e+00,
231  1.0430628893172429e+00,
232  1.0419843900382593e+00,
233  1.0398733925500616e+00,
234  1.0368941901444431e+00,
235  1.0332177440630894e+00,
236  1.0290163354654738e+00,
237  1.0244587344726037e+00,
238  1.0197059644535929e+00,
239  1.0149077154190733e+00,
240  1.0101994371279546e+00,
241  1.0057001208275946e+00,
242  1.0015107588605578e+00,
243  9.9771345401345091e-01,
244  9.9437113568697522e-01,
245  9.9152782786961002e-01,
246  9.8920940455073014e-01,
247  9.8742476158271220e-01,
248  9.8616732999499135e-01,
249  9.8541685421431957e-01,
250  9.8514135934272273e-01,
251  9.8529923433656763e-01,
252  9.8584136233713060e-01,
253  9.8671323522766097e-01,
254  9.8785699642884006e-01,
255  9.8921336368970936e-01,
256  9.9072339188994707e-01,
257  9.9233004436365102e-01,
258  9.9397954972873170e-01,
259  9.9562252943082752e-01,
260  9.9721488898796984e-01,
261  9.9871847308640715e-01,
262  1.0001014910972239e+00,
263  1.0013387251597952e+00,
264  1.0024115376468863e+00,
265  1.0033076985540108e+00,
266  1.0040210561381850e+00,
267  1.0045510759904377e+00,
268  1.0049022747071339e+00,
269  1.0050835744914943e+00,
270  1.0051076044483147e+00,
271  1.0049899731232743e+00,
272  1.0047485350829104e+00,
273  1.0044026721363630e+00,
274  1.0039726072706594e+00,
275  1.0034787666110905e+00,
276  1.0029412018262318e+00,
277  1.0023790824657985e+00,
278  1.0018102648327663e+00,
279  1.0012509412230517e+00,
280  1.0007153707797318e+00,
281  1.0002156908559185e+00,
282  9.9976180570100437e-01,
283  9.9936134750740957e-01,
284  9.9901970339643342e-01,
285  9.9874010078908981e-01,
286  9.9852374279805434e-01,
287  9.9836998477874650e-01,
288  9.9827654297245150e-01,
289  9.9823972623754598e-01,
290  9.9825468216686974e-01,
291  9.9831564939715101e-01,
292  9.9841620859502256e-01,
293  9.9854952541740161e-01,
294  9.9870857965577986e-01,
295  9.9888637574922967e-01,
296  9.9907613085656199e-01,
297  9.9927143768349935e-01,
298  9.9946640023860800e-01,
299  9.9965574161824222e-01,
300  9.9983488377597740e-01,
301  1.0000000000000000e+00
302  };
303 
304  // setup Function
305  this->setAttributeValue(TT("function"), TT("easeOutElastic"));
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.
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
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTElasticEaseOutFunction Unit for Jamoms DSP
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