Jamoma API  0.6.0.a19
TTBounceEaseInFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTBounceEaseInFunction 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 "TTBounceEaseInFunction.h"
19 
20 
21 /*
22  * Coefficients calculated in Octave using script found
23  * in the OctaveScript subfolder of this extension.
24  */
25 
27 {
28  int errorCount = 0;
29  int testAssertionCount = 0;
30  int badSampleCount = 0;
31  TTAudioSignalPtr input = NULL;
32  TTAudioSignalPtr output = NULL;
33  int N = 128;
34  TTValue v;
35 
36 
37  TTFloat64 inputSignal1[128] = {
38  0.0000000000000000e+00,
39  7.8740157480314960e-03,
40  1.5748031496062992e-02,
41  2.3622047244094488e-02,
42  3.1496062992125984e-02,
43  3.9370078740157480e-02,
44  4.7244094488188976e-02,
45  5.5118110236220472e-02,
46  6.2992125984251968e-02,
47  7.0866141732283464e-02,
48  7.8740157480314960e-02,
49  8.6614173228346455e-02,
50  9.4488188976377951e-02,
51  1.0236220472440945e-01,
52  1.1023622047244094e-01,
53  1.1811023622047244e-01,
54  1.2598425196850394e-01,
55  1.3385826771653542e-01,
56  1.4173228346456693e-01,
57  1.4960629921259844e-01,
58  1.5748031496062992e-01,
59  1.6535433070866140e-01,
60  1.7322834645669291e-01,
61  1.8110236220472442e-01,
62  1.8897637795275590e-01,
63  1.9685039370078738e-01,
64  2.0472440944881889e-01,
65  2.1259842519685040e-01,
66  2.2047244094488189e-01,
67  2.2834645669291337e-01,
68  2.3622047244094488e-01,
69  2.4409448818897639e-01,
70  2.5196850393700787e-01,
71  2.5984251968503935e-01,
72  2.6771653543307083e-01,
73  2.7559055118110237e-01,
74  2.8346456692913385e-01,
75  2.9133858267716534e-01,
76  2.9921259842519687e-01,
77  3.0708661417322836e-01,
78  3.1496062992125984e-01,
79  3.2283464566929132e-01,
80  3.3070866141732280e-01,
81  3.3858267716535434e-01,
82  3.4645669291338582e-01,
83  3.5433070866141730e-01,
84  3.6220472440944884e-01,
85  3.7007874015748032e-01,
86  3.7795275590551181e-01,
87  3.8582677165354329e-01,
88  3.9370078740157477e-01,
89  4.0157480314960631e-01,
90  4.0944881889763779e-01,
91  4.1732283464566927e-01,
92  4.2519685039370081e-01,
93  4.3307086614173229e-01,
94  4.4094488188976377e-01,
95  4.4881889763779526e-01,
96  4.5669291338582674e-01,
97  4.6456692913385828e-01,
98  4.7244094488188976e-01,
99  4.8031496062992124e-01,
100  4.8818897637795278e-01,
101  4.9606299212598426e-01,
102  5.0393700787401574e-01,
103  5.1181102362204722e-01,
104  5.1968503937007871e-01,
105  5.2755905511811019e-01,
106  5.3543307086614167e-01,
107  5.4330708661417326e-01,
108  5.5118110236220474e-01,
109  5.5905511811023623e-01,
110  5.6692913385826771e-01,
111  5.7480314960629919e-01,
112  5.8267716535433067e-01,
113  5.9055118110236215e-01,
114  5.9842519685039375e-01,
115  6.0629921259842523e-01,
116  6.1417322834645671e-01,
117  6.2204724409448819e-01,
118  6.2992125984251968e-01,
119  6.3779527559055116e-01,
120  6.4566929133858264e-01,
121  6.5354330708661412e-01,
122  6.6141732283464560e-01,
123  6.6929133858267720e-01,
124  6.7716535433070868e-01,
125  6.8503937007874016e-01,
126  6.9291338582677164e-01,
127  7.0078740157480313e-01,
128  7.0866141732283461e-01,
129  7.1653543307086609e-01,
130  7.2440944881889768e-01,
131  7.3228346456692917e-01,
132  7.4015748031496065e-01,
133  7.4803149606299213e-01,
134  7.5590551181102361e-01,
135  7.6377952755905509e-01,
136  7.7165354330708658e-01,
137  7.7952755905511806e-01,
138  7.8740157480314954e-01,
139  7.9527559055118113e-01,
140  8.0314960629921262e-01,
141  8.1102362204724410e-01,
142  8.1889763779527558e-01,
143  8.2677165354330706e-01,
144  8.3464566929133854e-01,
145  8.4251968503937003e-01,
146  8.5039370078740162e-01,
147  8.5826771653543310e-01,
148  8.6614173228346458e-01,
149  8.7401574803149606e-01,
150  8.8188976377952755e-01,
151  8.8976377952755903e-01,
152  8.9763779527559051e-01,
153  9.0551181102362199e-01,
154  9.1338582677165348e-01,
155  9.2125984251968507e-01,
156  9.2913385826771655e-01,
157  9.3700787401574803e-01,
158  9.4488188976377951e-01,
159  9.5275590551181100e-01,
160  9.6062992125984248e-01,
161  9.6850393700787396e-01,
162  9.7637795275590555e-01,
163  9.8425196850393704e-01,
164  9.9212598425196852e-01,
165  1.0000000000000000e+00
166  };
167 
168 
169  TTFloat64 expectedSignal1[128] = {
170  -1.7763568394002505e-15,
171  7.8343356686687571e-03,
172  1.4329468658937472e-02,
173  1.9485398970793710e-02,
174  2.3302126604251683e-02,
175  2.5779651559300731e-02,
176  2.6917973835944409e-02,
177  2.6717093434184491e-02,
178  2.5177010354019203e-02,
179  2.2297724595448543e-02,
180  1.8079236158472511e-02,
181  1.2521545043087556e-02,
182  5.6246512493025591e-03,
183  4.8560008477327443e-03,
184  2.0070109946313863e-02,
185  3.3787972285086454e-02,
186  4.6009587864050516e-02,
187  5.6734956683209603e-02,
188  6.5964078742560162e-02,
189  7.3696954042107521e-02,
190  7.9933582581846352e-02,
191  8.4673964361778431e-02,
192  8.7918099381905535e-02,
193  8.9665987642225886e-02,
194  8.9917629142737709e-02,
195  8.8673023883444557e-02,
196  8.5932171864343765e-02,
197  8.1695073085437109e-02,
198  7.5961727546722813e-02,
199  6.8732135248202653e-02,
200  6.0006296189876629e-02,
201  4.9784210371744742e-02,
202  3.8065877793805214e-02,
203  2.4851298456059823e-02,
204  1.0140472358506791e-02,
205  9.3744187488380426e-03,
206  3.4386818773639138e-02,
207  5.8273916547833426e-02,
208  8.1035712071424459e-02,
209  1.0267220534441135e-01,
210  1.2318339636679321e-01,
211  1.4256928513857003e-01,
212  1.6082987165974361e-01,
213  1.7796515593031215e-01,
214  1.9397513795027654e-01,
215  2.0885981771963547e-01,
216  2.2261919523839113e-01,
217  2.3525327050654177e-01,
218  2.4676204352408737e-01,
219  2.5714551429102928e-01,
220  2.6640368280736570e-01,
221  2.7453654907309888e-01,
222  2.8154411308822702e-01,
223  2.8742637485275013e-01,
224  2.9218333436666954e-01,
225  2.9581499162998393e-01,
226  2.9832134664269416e-01,
227  2.9970239940479892e-01,
228  2.9995814991630043e-01,
229  2.9908859817719646e-01,
230  2.9709374418748924e-01,
231  2.9397358794717698e-01,
232  2.8972812945625925e-01,
233  2.8435736871473827e-01,
234  2.7786130572261136e-01,
235  2.7023994047988120e-01,
236  2.6149327298654601e-01,
237  2.5162130324260668e-01,
238  2.4062403124806320e-01,
239  2.2850145700291424e-01,
240  2.1525358050716159e-01,
241  2.0088040176080346e-01,
242  1.8538192076384208e-01,
243  1.6875813751627478e-01,
244  1.5100905201810422e-01,
245  1.3213466426932952e-01,
246  1.1213497426994889e-01,
247  9.1009982019964131e-02,
248  6.8759687519375223e-02,
249  4.5384090768182173e-02,
250  2.0883191766384090e-02,
251  7.8585157170313336e-03,
252  5.0526226052451828e-02,
253  9.2256184512368833e-02,
254  1.3304839109678190e-01,
255  1.7290284580569182e-01,
256  2.1181954863909735e-01,
257  2.4979849959699929e-01,
258  2.8683969867939729e-01,
259  3.2294314588629169e-01,
260  3.5810884121768227e-01,
261  3.9233678467356914e-01,
262  4.2562697625395274e-01,
263  4.5797941595883207e-01,
264  4.8939410378820758e-01,
265  5.1987103974207949e-01,
266  5.4941022382044757e-01,
267  5.7801165602331195e-01,
268  6.0567533635067261e-01,
269  6.3240126480252945e-01,
270  6.5818944137888247e-01,
271  6.8303986607973233e-01,
272  7.0695253890507792e-01,
273  7.2992745985491969e-01,
274  7.5196462892925786e-01,
275  7.7306404612809221e-01,
276  7.9322571145142273e-01,
277  8.1244962489924966e-01,
278  8.3073578647157298e-01,
279  8.4808419616839237e-01,
280  8.6449485398970805e-01,
281  8.7996775993551990e-01,
282  8.9450291400582804e-01,
283  9.0810031620063236e-01,
284  9.2075996651993297e-01,
285  9.3248186496372987e-01,
286  9.4326601153202294e-01,
287  9.5311240622481253e-01,
288  9.6202104904209806e-01,
289  9.6999193998388000e-01,
290  9.7702507905015812e-01,
291  9.8312046624093241e-01,
292  9.8827810155620310e-01,
293  9.9249798499596997e-01,
294  9.9578011656023313e-01,
295  9.9812449624899247e-01,
296  9.9953112406224809e-01,
297  1.0000000000000000e+00
298  };
299 
300  // setup Function
301  this->setAttributeValue(TT("function"), TT("easeInBounce"));
302 
303 
304  // create 1 channel audio signal objects
305  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
306  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
307  input->allocWithVectorSize(N);
308  output->allocWithVectorSize(N);
309 
310  // create a signal to be transformed and then process it)
311  input->clear();
312  for (int i=0; i<N; i++)
313  input->mSampleVectors[0][i] = inputSignal1[i];
314 
315  this->process(input, output);
316 
317  // now test the output
318  for (int n=0; n<N; n++)
319  {
320  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
321  badSampleCount += result;
322  if (result)
323  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
324  }
325 
326  TTTestAssertion("Produces correct function values",
327  badSampleCount == 0,
328  testAssertionCount,
329  errorCount);
330  if (badSampleCount)
331  TTTestLog("badSampleCount is %i", badSampleCount);
332 
333 
334  TTObjectBaseRelease(&input);
335  TTObjectBaseRelease(&output);
336 
337  // wrap up test results and pass back to whoever called test
338  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
339 
340 }
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
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
TTBounceEaseInFunction Unit for Jamoms DSP
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