Jamoma API  0.6.0.a19
TTQuadraticEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTQuadraticEaseInOutFunction 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) .* (2 * x .* x)
27  yb = (x >= 0.5) .* ((-2 * x .* x) + (4 * x) - 1)
28 
29  y = ya + yb
30 
31  printf("%.16e,\n", y)
32 
33  */
34 
36 {
37  int errorCount = 0;
38  int testAssertionCount = 0;
39  int badSampleCount = 0;
40  TTAudioSignalPtr input = NULL;
41  TTAudioSignalPtr output = NULL;
42  int N = 128;
43  TTValue v;
44 
45 
46  TTFloat64 inputSignal1[128] = {
47  0.0000000000000000e+00,
48  7.8740157480314960e-03,
49  1.5748031496062992e-02,
50  2.3622047244094488e-02,
51  3.1496062992125984e-02,
52  3.9370078740157480e-02,
53  4.7244094488188976e-02,
54  5.5118110236220472e-02,
55  6.2992125984251968e-02,
56  7.0866141732283464e-02,
57  7.8740157480314960e-02,
58  8.6614173228346455e-02,
59  9.4488188976377951e-02,
60  1.0236220472440945e-01,
61  1.1023622047244094e-01,
62  1.1811023622047244e-01,
63  1.2598425196850394e-01,
64  1.3385826771653542e-01,
65  1.4173228346456693e-01,
66  1.4960629921259844e-01,
67  1.5748031496062992e-01,
68  1.6535433070866140e-01,
69  1.7322834645669291e-01,
70  1.8110236220472442e-01,
71  1.8897637795275590e-01,
72  1.9685039370078738e-01,
73  2.0472440944881889e-01,
74  2.1259842519685040e-01,
75  2.2047244094488189e-01,
76  2.2834645669291337e-01,
77  2.3622047244094488e-01,
78  2.4409448818897639e-01,
79  2.5196850393700787e-01,
80  2.5984251968503935e-01,
81  2.6771653543307083e-01,
82  2.7559055118110237e-01,
83  2.8346456692913385e-01,
84  2.9133858267716534e-01,
85  2.9921259842519687e-01,
86  3.0708661417322836e-01,
87  3.1496062992125984e-01,
88  3.2283464566929132e-01,
89  3.3070866141732280e-01,
90  3.3858267716535434e-01,
91  3.4645669291338582e-01,
92  3.5433070866141730e-01,
93  3.6220472440944884e-01,
94  3.7007874015748032e-01,
95  3.7795275590551181e-01,
96  3.8582677165354329e-01,
97  3.9370078740157477e-01,
98  4.0157480314960631e-01,
99  4.0944881889763779e-01,
100  4.1732283464566927e-01,
101  4.2519685039370081e-01,
102  4.3307086614173229e-01,
103  4.4094488188976377e-01,
104  4.4881889763779526e-01,
105  4.5669291338582674e-01,
106  4.6456692913385828e-01,
107  4.7244094488188976e-01,
108  4.8031496062992124e-01,
109  4.8818897637795278e-01,
110  4.9606299212598426e-01,
111  5.0393700787401574e-01,
112  5.1181102362204722e-01,
113  5.1968503937007871e-01,
114  5.2755905511811019e-01,
115  5.3543307086614167e-01,
116  5.4330708661417326e-01,
117  5.5118110236220474e-01,
118  5.5905511811023623e-01,
119  5.6692913385826771e-01,
120  5.7480314960629919e-01,
121  5.8267716535433067e-01,
122  5.9055118110236215e-01,
123  5.9842519685039375e-01,
124  6.0629921259842523e-01,
125  6.1417322834645671e-01,
126  6.2204724409448819e-01,
127  6.2992125984251968e-01,
128  6.3779527559055116e-01,
129  6.4566929133858264e-01,
130  6.5354330708661412e-01,
131  6.6141732283464560e-01,
132  6.6929133858267720e-01,
133  6.7716535433070868e-01,
134  6.8503937007874016e-01,
135  6.9291338582677164e-01,
136  7.0078740157480313e-01,
137  7.0866141732283461e-01,
138  7.1653543307086609e-01,
139  7.2440944881889768e-01,
140  7.3228346456692917e-01,
141  7.4015748031496065e-01,
142  7.4803149606299213e-01,
143  7.5590551181102361e-01,
144  7.6377952755905509e-01,
145  7.7165354330708658e-01,
146  7.7952755905511806e-01,
147  7.8740157480314954e-01,
148  7.9527559055118113e-01,
149  8.0314960629921262e-01,
150  8.1102362204724410e-01,
151  8.1889763779527558e-01,
152  8.2677165354330706e-01,
153  8.3464566929133854e-01,
154  8.4251968503937003e-01,
155  8.5039370078740162e-01,
156  8.5826771653543310e-01,
157  8.6614173228346458e-01,
158  8.7401574803149606e-01,
159  8.8188976377952755e-01,
160  8.8976377952755903e-01,
161  8.9763779527559051e-01,
162  9.0551181102362199e-01,
163  9.1338582677165348e-01,
164  9.2125984251968507e-01,
165  9.2913385826771655e-01,
166  9.3700787401574803e-01,
167  9.4488188976377951e-01,
168  9.5275590551181100e-01,
169  9.6062992125984248e-01,
170  9.6850393700787396e-01,
171  9.7637795275590555e-01,
172  9.8425196850393704e-01,
173  9.9212598425196852e-01,
174  1.0000000000000000e+00
175  };
176 
177 
178  TTFloat64 expectedSignal1[128] = {
179  0.0000000000000000e+00,
180  1.2400024800049599e-04,
181  4.9600099200198394e-04,
182  1.1160022320044639e-03,
183  1.9840039680079358e-03,
184  3.1000062000124001e-03,
185  4.4640089280178555e-03,
186  6.0760121520243042e-03,
187  7.9360158720317431e-03,
188  1.0044020088040177e-02,
189  1.2400024800049600e-02,
190  1.5004030008060016e-02,
191  1.7856035712071422e-02,
192  2.0956041912083823e-02,
193  2.4304048608097217e-02,
194  2.7900055800111598e-02,
195  3.1744063488126972e-02,
196  3.5836071672143338e-02,
197  4.0176080352160706e-02,
198  4.4764089528179063e-02,
199  4.9600099200198401e-02,
200  5.4684109368218728e-02,
201  6.0016120032240064e-02,
202  6.5596131192262389e-02,
203  7.1424142848285688e-02,
204  7.7500155000309989e-02,
205  8.3824167648335293e-02,
206  9.0396180792361600e-02,
207  9.7216194432388867e-02,
208  1.0428420856841712e-01,
209  1.1160022320044639e-01,
210  1.1916423832847667e-01,
211  1.2697625395250789e-01,
212  1.3503627007254013e-01,
213  1.4334428668857335e-01,
214  1.5190030380060762e-01,
215  1.6070432140864283e-01,
216  1.6975633951267902e-01,
217  1.7905635811271625e-01,
218  1.8860437720875442e-01,
219  1.9840039680079360e-01,
220  2.0844441688883375e-01,
221  2.1873643747287491e-01,
222  2.2927645855291712e-01,
223  2.4006448012896026e-01,
224  2.5110050220100438e-01,
225  2.6238452476904955e-01,
226  2.7391654783309566e-01,
227  2.8569657139314275e-01,
228  2.9772459544919089e-01,
229  3.1000062000123996e-01,
230  3.2252464504929013e-01,
231  3.3529667059334117e-01,
232  3.4831669663339321e-01,
233  3.6158472316944640e-01,
234  3.7510075020150041e-01,
235  3.8886477772955547e-01,
236  4.0287680575361146e-01,
237  4.1713683427366849e-01,
238  4.3164486328972657e-01,
239  4.4640089280178558e-01,
240  4.6140492280984557e-01,
241  4.7665695331390667e-01,
242  4.9215698431396865e-01,
243  5.0784301568603141e-01,
244  5.2334304668609333e-01,
245  5.3859507719015420e-01,
246  5.5359910719821426e-01,
247  5.6835513671027327e-01,
248  5.8286316572633146e-01,
249  5.9712319424638860e-01,
250  6.1113522227044470e-01,
251  6.2489924979849953e-01,
252  6.3841527683055377e-01,
253  6.5168330336660674e-01,
254  6.6470332940665866e-01,
255  6.7747535495070998e-01,
256  6.8999937999876004e-01,
257  7.0227540455080906e-01,
258  7.1430342860685725e-01,
259  7.2608345216690440e-01,
260  7.3761547523095050e-01,
261  7.4889949779899556e-01,
262  7.5993551987103958e-01,
263  7.7072354144708277e-01,
264  7.8126356252712514e-01,
265  7.9155558311116625e-01,
266  8.0159960319920653e-01,
267  8.1139562279124555e-01,
268  8.2094364188728375e-01,
269  8.3024366048732090e-01,
270  8.3929567859135723e-01,
271  8.4809969619939252e-01,
272  8.5665571331142676e-01,
273  8.6496372992745996e-01,
274  8.7302374604749211e-01,
275  8.8083576167152344e-01,
276  8.8839977679955351e-01,
277  8.9571579143158275e-01,
278  9.0278380556761118e-01,
279  9.0960381920763833e-01,
280  9.1617583235166467e-01,
281  9.2249984499968996e-01,
282  9.2857585715171420e-01,
283  9.3440386880773763e-01,
284  9.3998387996776001e-01,
285  9.4531589063178134e-01,
286  9.5039990079980163e-01,
287  9.5523591047182088e-01,
288  9.5982391964783931e-01,
289  9.6416392832785669e-01,
290  9.6825593651187303e-01,
291  9.7209994419988832e-01,
292  9.7569595139190279e-01,
293  9.7904395808791622e-01,
294  9.8214396428792861e-01,
295  9.8499596999193995e-01,
296  9.8759997519995046e-01,
297  9.8995597991195994e-01,
298  9.9206398412796815e-01,
299  9.9392398784797575e-01,
300  9.9553599107198210e-01,
301  9.9689999379998762e-01,
302  9.9801599603199209e-01,
303  9.9888399776799552e-01,
304  9.9950399900799791e-01,
305  9.9987599975199948e-01,
306  1.0000000000000000e+00
307  };
308 
309  // setup Function
310  this->setAttributeValue(TT("function"), TT("easeInOutQuadratic"));
311 
312 
313  // create 1 channel audio signal objects
314  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
315  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
316  input->allocWithVectorSize(N);
317  output->allocWithVectorSize(N);
318 
319  // create a signal to be transformed and then process it)
320  input->clear();
321  for (int i=0; i<N; i++)
322  input->mSampleVectors[0][i] = inputSignal1[i];
323 
324  this->process(input, output);
325 
326  // now test the output
327  for (int n=0; n<N; n++)
328  {
329  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
330  badSampleCount += result;
331  if (result)
332  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
333  }
334 
335  TTTestAssertion("Produces correct function values",
336  badSampleCount == 0,
337  testAssertionCount,
338  errorCount);
339  if (badSampleCount)
340  TTTestLog("badSampleCount is %i", badSampleCount);
341 
342 
343  TTObjectBaseRelease(&input);
344  TTObjectBaseRelease(&output);
345 
346  // wrap up test results and pass back to whoever called test
347  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
348 
349 }
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.
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTQuadraticEaseInOutFunction 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