Jamoma API  0.6.0.a19
TTBackEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTBackEaseInOutFunction 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  f = 2 * x
27  g = (1 - (2*x - 1))
28 
29  ya = (x < 0.5) .* (0.5 * (f .* f .* f - f .* sin(f * pi)))
30  yb = (x >= 0.5) .* (0.5 * (1 - (g .* g .* g - g .* sin(g * pi))) + 0.5)
31 
32  y = ya + yb
33 
34  printf("%.16e,\n", y)
35  plot (x,y)
36 
37  */
38 
40 {
41  int errorCount = 0;
42  int testAssertionCount = 0;
43  int badSampleCount = 0;
44  TTAudioSignalPtr input = NULL;
45  TTAudioSignalPtr output = NULL;
46  int N = 128;
47  TTValue v;
48 
49 
50  TTFloat64 inputSignal1[128] = {
51  0.0000000000000000e+00,
52  7.8740157480314960e-03,
53  1.5748031496062992e-02,
54  2.3622047244094488e-02,
55  3.1496062992125984e-02,
56  3.9370078740157480e-02,
57  4.7244094488188976e-02,
58  5.5118110236220472e-02,
59  6.2992125984251968e-02,
60  7.0866141732283464e-02,
61  7.8740157480314960e-02,
62  8.6614173228346455e-02,
63  9.4488188976377951e-02,
64  1.0236220472440945e-01,
65  1.1023622047244094e-01,
66  1.1811023622047244e-01,
67  1.2598425196850394e-01,
68  1.3385826771653542e-01,
69  1.4173228346456693e-01,
70  1.4960629921259844e-01,
71  1.5748031496062992e-01,
72  1.6535433070866140e-01,
73  1.7322834645669291e-01,
74  1.8110236220472442e-01,
75  1.8897637795275590e-01,
76  1.9685039370078738e-01,
77  2.0472440944881889e-01,
78  2.1259842519685040e-01,
79  2.2047244094488189e-01,
80  2.2834645669291337e-01,
81  2.3622047244094488e-01,
82  2.4409448818897639e-01,
83  2.5196850393700787e-01,
84  2.5984251968503935e-01,
85  2.6771653543307083e-01,
86  2.7559055118110237e-01,
87  2.8346456692913385e-01,
88  2.9133858267716534e-01,
89  2.9921259842519687e-01,
90  3.0708661417322836e-01,
91  3.1496062992125984e-01,
92  3.2283464566929132e-01,
93  3.3070866141732280e-01,
94  3.3858267716535434e-01,
95  3.4645669291338582e-01,
96  3.5433070866141730e-01,
97  3.6220472440944884e-01,
98  3.7007874015748032e-01,
99  3.7795275590551181e-01,
100  3.8582677165354329e-01,
101  3.9370078740157477e-01,
102  4.0157480314960631e-01,
103  4.0944881889763779e-01,
104  4.1732283464566927e-01,
105  4.2519685039370081e-01,
106  4.3307086614173229e-01,
107  4.4094488188976377e-01,
108  4.4881889763779526e-01,
109  4.5669291338582674e-01,
110  4.6456692913385828e-01,
111  4.7244094488188976e-01,
112  4.8031496062992124e-01,
113  4.8818897637795278e-01,
114  4.9606299212598426e-01,
115  5.0393700787401574e-01,
116  5.1181102362204722e-01,
117  5.1968503937007871e-01,
118  5.2755905511811019e-01,
119  5.3543307086614167e-01,
120  5.4330708661417326e-01,
121  5.5118110236220474e-01,
122  5.5905511811023623e-01,
123  5.6692913385826771e-01,
124  5.7480314960629919e-01,
125  5.8267716535433067e-01,
126  5.9055118110236215e-01,
127  5.9842519685039375e-01,
128  6.0629921259842523e-01,
129  6.1417322834645671e-01,
130  6.2204724409448819e-01,
131  6.2992125984251968e-01,
132  6.3779527559055116e-01,
133  6.4566929133858264e-01,
134  6.5354330708661412e-01,
135  6.6141732283464560e-01,
136  6.6929133858267720e-01,
137  6.7716535433070868e-01,
138  6.8503937007874016e-01,
139  6.9291338582677164e-01,
140  7.0078740157480313e-01,
141  7.0866141732283461e-01,
142  7.1653543307086609e-01,
143  7.2440944881889768e-01,
144  7.3228346456692917e-01,
145  7.4015748031496065e-01,
146  7.4803149606299213e-01,
147  7.5590551181102361e-01,
148  7.6377952755905509e-01,
149  7.7165354330708658e-01,
150  7.7952755905511806e-01,
151  7.8740157480314954e-01,
152  7.9527559055118113e-01,
153  8.0314960629921262e-01,
154  8.1102362204724410e-01,
155  8.1889763779527558e-01,
156  8.2677165354330706e-01,
157  8.3464566929133854e-01,
158  8.4251968503937003e-01,
159  8.5039370078740162e-01,
160  8.5826771653543310e-01,
161  8.6614173228346458e-01,
162  8.7401574803149606e-01,
163  8.8188976377952755e-01,
164  8.8976377952755903e-01,
165  8.9763779527559051e-01,
166  9.0551181102362199e-01,
167  9.1338582677165348e-01,
168  9.2125984251968507e-01,
169  9.2913385826771655e-01,
170  9.3700787401574803e-01,
171  9.4488188976377951e-01,
172  9.5275590551181100e-01,
173  9.6062992125984248e-01,
174  9.6850393700787396e-01,
175  9.7637795275590555e-01,
176  9.8425196850393704e-01,
177  9.9212598425196852e-01,
178  1.0000000000000000e+00
179  };
180 
181 
182  TTFloat64 expectedSignal1[128] = {
183  0.0000000000000000e+00,
184  -3.8744660965935436e-04,
185  -1.5400695483746482e-03,
186  -3.4404417001289763e-03,
187  -6.0673522076621304e-03,
188  -9.3958413379321409e-03,
189  -1.3397249134364181e-02,
190  -1.8039277697074845e-02,
191  -2.3286066887719302e-02,
192  -2.9098283211690352e-02,
193  -3.5433221587237156e-02,
194  -4.2244919668799043e-02,
195  -4.9484284350596243e-02,
196  -5.7099230036412360e-02,
197  -6.5034828222663627e-02,
198  -7.3233467904400884e-02,
199  -8.1635026277943834e-02,
200  -9.0177049179516106e-02,
201  -9.8794940666641559e-02,
202  -1.0742216111827518e-01,
203  -1.1599043320077553e-01,
204  -1.2442995501996683e-01,
205  -1.3266961975477509e-01,
206  -1.4063724104532851e-01,
207  -1.4825978338806403e-01,
208  -1.5546359677234051e-01,
209  -1.6217465477738396e-01,
210  -1.6831879533513577e-01,
211  -1.7382196335378025e-01,
212  -1.7861045438843376e-01,
213  -1.8261115853971163e-01,
214  -1.8575180375767372e-01,
215  -1.8796119772800027e-01,
216  -1.8916946751916980e-01,
217  -1.8930829617390368e-01,
218  -1.8831115543519694e-01,
219  -1.8611353380685455e-01,
220  -1.8265315916057548e-01,
221  -1.7787021511624021e-01,
222  -1.7170755043912267e-01,
223  -1.6411088071721824e-01,
224  -1.5502898160370315e-01,
225  -1.4441387293365451e-01,
226  -1.3222099305050011e-01,
227  -1.1840936270615493e-01,
228  -1.0294173792935854e-01,
229  -8.5784751289269962e-02,
230  -6.6909041015800058e-02,
231  -4.6289367474384946e-02,
232  -2.3904716530801923e-02,
233  2.6161061888618775e-04,
234  2.6221921537240955e-02,
235  5.3984070894904340e-02,
236  8.3551413378805367e-02,
237  1.1492277141272489e-01,
238  1.4809241789828001e-01,
239  1.8305007413802249e-01,
240  2.1978092305527264e-01,
241  2.5826563777771577e-01,
242  2.9848042560375632e-01,
243  3.4039708732235641e-01,
244  3.8398309180867690e-01,
245  4.2920166576946750e-01,
246  4.7601189846393982e-01,
247  5.2398810153606012e-01,
248  5.7079833423053250e-01,
249  6.1601690819132282e-01,
250  6.5960291267764326e-01,
251  7.0151957439624324e-01,
252  7.4173436222228428e-01,
253  7.8021907694472736e-01,
254  8.1694992586197746e-01,
255  8.5190758210172002e-01,
256  8.8507722858727511e-01,
257  9.1644858662119455e-01,
258  9.4601592910509547e-01,
259  9.7377807846275910e-01,
260  9.9973838938111381e-01,
261  1.0239047165308020e+00,
262  1.0462893674743849e+00,
263  1.0669090410158000e+00,
264  1.0857847512892700e+00,
265  1.1029417379293585e+00,
266  1.1184093627061547e+00,
267  1.1322209930505001e+00,
268  1.1444138729336544e+00,
269  1.1550289816037032e+00,
270  1.1641108807172182e+00,
271  1.1717075504391228e+00,
272  1.1778702151162403e+00,
273  1.1826531591605756e+00,
274  1.1861135338068545e+00,
275  1.1883111554351971e+00,
276  1.1893082961739037e+00,
277  1.1891694675191697e+00,
278  1.1879611977280002e+00,
279  1.1857518037576738e+00,
280  1.1826111585397117e+00,
281  1.1786104543884337e+00,
282  1.1738219633537803e+00,
283  1.1683187953351357e+00,
284  1.1621746547773839e+00,
285  1.1554635967723406e+00,
286  1.1482597833880641e+00,
287  1.1406372410453285e+00,
288  1.1326696197547752e+00,
289  1.1244299550199668e+00,
290  1.1159904332007757e+00,
291  1.1074221611182751e+00,
292  1.0987949406666415e+00,
293  1.0901770491795162e+00,
294  1.0816350262779437e+00,
295  1.0732334679044009e+00,
296  1.0650348282226636e+00,
297  1.0570992300364124e+00,
298  1.0494842843505963e+00,
299  1.0422449196687991e+00,
300  1.0354332215872373e+00,
301  1.0290982832116904e+00,
302  1.0232860668877193e+00,
303  1.0180392776970748e+00,
304  1.0133972491343641e+00,
305  1.0093958413379323e+00,
306  1.0060673522076622e+00,
307  1.0034404417001288e+00,
308  1.0015400695483745e+00,
309  1.0003874466096594e+00,
310  1.0000000000000000e+00
311  };
312 
313  // setup Function
314  this->setAttributeValue(TT("function"), TT("easeInOutBack"));
315 
316 
317  // create 1 channel audio signal objects
318  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
319  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
320  input->allocWithVectorSize(N);
321  output->allocWithVectorSize(N);
322 
323  // create a signal to be transformed and then process it)
324  input->clear();
325  for (int i=0; i<N; i++)
326  input->mSampleVectors[0][i] = inputSignal1[i];
327 
328  this->process(input, output);
329 
330  // now test the output
331  for (int n=0; n<N; n++)
332  {
333  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
334  badSampleCount += result;
335  if (result)
336  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
337  }
338 
339  TTTestAssertion("Produces correct function values",
340  badSampleCount == 0,
341  testAssertionCount,
342  errorCount);
343  if (badSampleCount)
344  TTTestLog("badSampleCount is %i", badSampleCount);
345 
346 
347  TTObjectBaseRelease(&input);
348  TTObjectBaseRelease(&output);
349 
350  // wrap up test results and pass back to whoever called test
351  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
352 
353 }
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
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
TTBackEaseInOutFunction Unit for Jamoms DSP