Jamoma API  0.6.0.a19
TTCubicEaseOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTCubicEaseOutFunction 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"
18 #include "TTCubicEaseOutFunction.h"
19 
20 
21 /*
22  * coefficients calculated in Octave using:
23 
24  x = linspace(0,1,128);
25  f = (x - 1);
26  y = f .* f .* f + 1;
27  printf("%.16e,\n", y)
28  plot (x,y)
29 
30  */
31 
33 {
34  int errorCount = 0;
35  int testAssertionCount = 0;
36  int badSampleCount = 0;
37  TTAudioSignalPtr input = NULL;
38  TTAudioSignalPtr output = NULL;
39  int N = 128;
40  TTValue v;
41 
42 
43  TTFloat64 inputSignal1[128] = {
44  0.0000000000000000e+00,
45  7.8740157480314960e-03,
46  1.5748031496062992e-02,
47  2.3622047244094488e-02,
48  3.1496062992125984e-02,
49  3.9370078740157480e-02,
50  4.7244094488188976e-02,
51  5.5118110236220472e-02,
52  6.2992125984251968e-02,
53  7.0866141732283464e-02,
54  7.8740157480314960e-02,
55  8.6614173228346455e-02,
56  9.4488188976377951e-02,
57  1.0236220472440945e-01,
58  1.1023622047244094e-01,
59  1.1811023622047244e-01,
60  1.2598425196850394e-01,
61  1.3385826771653542e-01,
62  1.4173228346456693e-01,
63  1.4960629921259844e-01,
64  1.5748031496062992e-01,
65  1.6535433070866140e-01,
66  1.7322834645669291e-01,
67  1.8110236220472442e-01,
68  1.8897637795275590e-01,
69  1.9685039370078738e-01,
70  2.0472440944881889e-01,
71  2.1259842519685040e-01,
72  2.2047244094488189e-01,
73  2.2834645669291337e-01,
74  2.3622047244094488e-01,
75  2.4409448818897639e-01,
76  2.5196850393700787e-01,
77  2.5984251968503935e-01,
78  2.6771653543307083e-01,
79  2.7559055118110237e-01,
80  2.8346456692913385e-01,
81  2.9133858267716534e-01,
82  2.9921259842519687e-01,
83  3.0708661417322836e-01,
84  3.1496062992125984e-01,
85  3.2283464566929132e-01,
86  3.3070866141732280e-01,
87  3.3858267716535434e-01,
88  3.4645669291338582e-01,
89  3.5433070866141730e-01,
90  3.6220472440944884e-01,
91  3.7007874015748032e-01,
92  3.7795275590551181e-01,
93  3.8582677165354329e-01,
94  3.9370078740157477e-01,
95  4.0157480314960631e-01,
96  4.0944881889763779e-01,
97  4.1732283464566927e-01,
98  4.2519685039370081e-01,
99  4.3307086614173229e-01,
100  4.4094488188976377e-01,
101  4.4881889763779526e-01,
102  4.5669291338582674e-01,
103  4.6456692913385828e-01,
104  4.7244094488188976e-01,
105  4.8031496062992124e-01,
106  4.8818897637795278e-01,
107  4.9606299212598426e-01,
108  5.0393700787401574e-01,
109  5.1181102362204722e-01,
110  5.1968503937007871e-01,
111  5.2755905511811019e-01,
112  5.3543307086614167e-01,
113  5.4330708661417326e-01,
114  5.5118110236220474e-01,
115  5.5905511811023623e-01,
116  5.6692913385826771e-01,
117  5.7480314960629919e-01,
118  5.8267716535433067e-01,
119  5.9055118110236215e-01,
120  5.9842519685039375e-01,
121  6.0629921259842523e-01,
122  6.1417322834645671e-01,
123  6.2204724409448819e-01,
124  6.2992125984251968e-01,
125  6.3779527559055116e-01,
126  6.4566929133858264e-01,
127  6.5354330708661412e-01,
128  6.6141732283464560e-01,
129  6.6929133858267720e-01,
130  6.7716535433070868e-01,
131  6.8503937007874016e-01,
132  6.9291338582677164e-01,
133  7.0078740157480313e-01,
134  7.0866141732283461e-01,
135  7.1653543307086609e-01,
136  7.2440944881889768e-01,
137  7.3228346456692917e-01,
138  7.4015748031496065e-01,
139  7.4803149606299213e-01,
140  7.5590551181102361e-01,
141  7.6377952755905509e-01,
142  7.7165354330708658e-01,
143  7.7952755905511806e-01,
144  7.8740157480314954e-01,
145  7.9527559055118113e-01,
146  8.0314960629921262e-01,
147  8.1102362204724410e-01,
148  8.1889763779527558e-01,
149  8.2677165354330706e-01,
150  8.3464566929133854e-01,
151  8.4251968503937003e-01,
152  8.5039370078740162e-01,
153  8.5826771653543310e-01,
154  8.6614173228346458e-01,
155  8.7401574803149606e-01,
156  8.8188976377952755e-01,
157  8.8976377952755903e-01,
158  8.9763779527559051e-01,
159  9.0551181102362199e-01,
160  9.1338582677165348e-01,
161  9.2125984251968507e-01,
162  9.2913385826771655e-01,
163  9.3700787401574803e-01,
164  9.4488188976377951e-01,
165  9.5275590551181100e-01,
166  9.6062992125984248e-01,
167  9.6850393700787396e-01,
168  9.7637795275590555e-01,
169  9.8425196850393704e-01,
170  9.9212598425196852e-01,
171  1.0000000000000000e+00
172  };
173 
174 
175  TTFloat64 expectedSignal1[128] = {
176  0.0000000000000000e+00,
177  2.3436535062046460e-02,
178  4.6503998519807910e-02,
179  6.9205319513001129e-02,
180  9.1543427181342452e-02,
181  1.1352125066454866e-01,
182  1.3514171910233586e-01,
183  1.5640776163442094e-01,
184  1.7732230740052024e-01,
185  1.9788828554035065e-01,
186  2.1810862519362828e-01,
187  2.3798625550006991e-01,
188  2.5752410559939243e-01,
189  2.7672510463131172e-01,
190  2.9559218173554469e-01,
191  3.1412826605180766e-01,
192  3.3233628671981752e-01,
193  3.5021917287929061e-01,
194  3.6777985366994348e-01,
195  3.8502125823149269e-01,
196  4.0194631570365491e-01,
197  4.1855795522614658e-01,
198  4.3485910593868438e-01,
199  4.5085269698098451e-01,
200  4.6654165749276377e-01,
201  4.8192891661373871e-01,
202  4.9701740348362577e-01,
203  5.1181004724214185e-01,
204  5.2630977702900306e-01,
205  5.4051952198392583e-01,
206  5.5444221124662718e-01,
207  5.6808077395682355e-01,
208  5.8143813925423127e-01,
209  5.9451723627856712e-01,
210  6.0732099416954743e-01,
211  6.1985234206688888e-01,
212  6.3211420911030791e-01,
213  6.4410952443952119e-01,
214  6.5584121719424537e-01,
215  6.6731221651419681e-01,
216  6.7852545153909205e-01,
217  6.8948385140864765e-01,
218  7.0019034526258028e-01,
219  7.1064786224060650e-01,
220  7.2085933148244252e-01,
221  7.3082768212780524e-01,
222  7.4055584331641100e-01,
223  7.5004674418797657e-01,
224  7.5930331388221828e-01,
225  7.6832848153885280e-01,
226  7.7712517629759659e-01,
227  7.8569632729816630e-01,
228  7.9404486368027849e-01,
229  8.0217371458364961e-01,
230  8.1008580914799633e-01,
231  8.1778407651303486e-01,
232  8.2527144581848222e-01,
233  8.3255084620405462e-01,
234  8.3962520680946873e-01,
235  8.4649745677444121e-01,
236  8.5317052523868830e-01,
237  8.5964734134192677e-01,
238  8.6593083422387318e-01,
239  8.7202393302424408e-01,
240  8.7792956688275581e-01,
241  8.8365066493912514e-01,
242  8.8919015633306853e-01,
243  8.9455097020430263e-01,
244  8.9973603569254379e-01,
245  9.0474828193750878e-01,
246  9.0959063807891394e-01,
247  9.1426603325647593e-01,
248  9.1877739660991131e-01,
249  9.2312765727893664e-01,
250  9.2731974440326836e-01,
251  9.3135658712262304e-01,
252  9.3524111457671733e-01,
253  9.3897625590526768e-01,
254  9.4256494024799076e-01,
255  9.4601009674460290e-01,
256  9.4931465453482089e-01,
257  9.5248154275836105e-01,
258  9.5551369055494018e-01,
259  9.5841402706427459e-01,
260  9.6118548142608096e-01,
261  9.6383098278007584e-01,
262  9.6635346026597568e-01,
263  9.6875584302349704e-01,
264  9.7104106019235659e-01,
265  9.7321204091227076e-01,
266  9.7527171432295623e-01,
267  9.7722300956412933e-01,
268  9.7906885577550684e-01,
269  9.8081218209680510e-01,
270  9.8245591766774087e-01,
271  9.8400299162803051e-01,
272  9.8545633311739067e-01,
273  9.8681887127553780e-01,
274  9.8809353524218857e-01,
275  9.8928325415705953e-01,
276  9.9039095715986702e-01,
277  9.9141957339032794e-01,
278  9.9237203198815849e-01,
279  9.9325126209307535e-01,
280  9.9406019284479519e-01,
281  9.9480175338303434e-01,
282  9.9547887284750947e-01,
283  9.9609448037793713e-01,
284  9.9665150511403389e-01,
285  9.9715287619551618e-01,
286  9.9760152276210068e-01,
287  9.9800037395350383e-01,
288  9.9835235890944218e-01,
289  9.9866040676963241e-01,
290  9.9892744667379096e-01,
291  9.9915640776163439e-01,
292  9.9935021917287925e-01,
293  9.9951181004724210e-01,
294  9.9964410952443949e-01,
295  9.9975004674418799e-01,
296  9.9983255084620404e-01,
297  9.9989455097020430e-01,
298  9.9993897625590522e-01,
299  9.9996875584302347e-01,
300  9.9998681887127550e-01,
301  9.9999609448037796e-01,
302  9.9999951181004720e-01,
303  1.0000000000000000e+00
304  };
305 
306  // setup Function
307  this->setAttributeValue(TT("function"), TT("easeOutCubic"));
308 
309 
310  // create 1 channel audio signal objects
311  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
312  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
313  input->allocWithVectorSize(N);
314  output->allocWithVectorSize(N);
315 
316  // create a signal to be transformed and then process it)
317  input->clear();
318  for (int i=0; i<N; i++)
319  input->mSampleVectors[0][i] = inputSignal1[i];
320 
321  this->process(input, output);
322 
323  // now test the output
324  for (int n=0; n<N; n++)
325  {
326  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
327  badSampleCount += result;
328  if (result)
329  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
330  }
331 
332  TTTestAssertion("Produces correct function values",
333  badSampleCount == 0,
334  testAssertionCount,
335  errorCount);
336  if (badSampleCount)
337  TTTestLog("badSampleCount is %i", badSampleCount);
338 
339 
340  TTObjectBaseRelease(&input);
341  TTObjectBaseRelease(&output);
342 
343  // wrap up test results and pass back to whoever called test
344  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
345 
346 }
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
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTCubicEaseOutFunction Unit for Jamoms DSP
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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