Jamoma API  0.6.0.a19
TTExponentialEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTExponentialEaseInOutFunction 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) .* (0.5 * (2 .^ ((20 * x) - 10)))
27  yb = (x >= 0.5) .* (-0.5 * (2 .^ ((-20 * x) + 10)) + 1)
28 
29  y = ya + yb
30 
31  y(1) = x(1)
32  y(128) = x(128)
33 
34  printf("%.16e,\n", y)
35 
36  plot (x,y)
37 
38  */
39 
41 {
42  int errorCount = 0;
43  int testAssertionCount = 0;
44  int badSampleCount = 0;
45  TTAudioSignalPtr input = NULL;
46  TTAudioSignalPtr output = NULL;
47  int N = 128;
48  TTValue v;
49 
50 
51  TTFloat64 inputSignal1[128] = {
52  0.0000000000000000e+00,
53  7.8740157480314960e-03,
54  1.5748031496062992e-02,
55  2.3622047244094488e-02,
56  3.1496062992125984e-02,
57  3.9370078740157480e-02,
58  4.7244094488188976e-02,
59  5.5118110236220472e-02,
60  6.2992125984251968e-02,
61  7.0866141732283464e-02,
62  7.8740157480314960e-02,
63  8.6614173228346455e-02,
64  9.4488188976377951e-02,
65  1.0236220472440945e-01,
66  1.1023622047244094e-01,
67  1.1811023622047244e-01,
68  1.2598425196850394e-01,
69  1.3385826771653542e-01,
70  1.4173228346456693e-01,
71  1.4960629921259844e-01,
72  1.5748031496062992e-01,
73  1.6535433070866140e-01,
74  1.7322834645669291e-01,
75  1.8110236220472442e-01,
76  1.8897637795275590e-01,
77  1.9685039370078738e-01,
78  2.0472440944881889e-01,
79  2.1259842519685040e-01,
80  2.2047244094488189e-01,
81  2.2834645669291337e-01,
82  2.3622047244094488e-01,
83  2.4409448818897639e-01,
84  2.5196850393700787e-01,
85  2.5984251968503935e-01,
86  2.6771653543307083e-01,
87  2.7559055118110237e-01,
88  2.8346456692913385e-01,
89  2.9133858267716534e-01,
90  2.9921259842519687e-01,
91  3.0708661417322836e-01,
92  3.1496062992125984e-01,
93  3.2283464566929132e-01,
94  3.3070866141732280e-01,
95  3.3858267716535434e-01,
96  3.4645669291338582e-01,
97  3.5433070866141730e-01,
98  3.6220472440944884e-01,
99  3.7007874015748032e-01,
100  3.7795275590551181e-01,
101  3.8582677165354329e-01,
102  3.9370078740157477e-01,
103  4.0157480314960631e-01,
104  4.0944881889763779e-01,
105  4.1732283464566927e-01,
106  4.2519685039370081e-01,
107  4.3307086614173229e-01,
108  4.4094488188976377e-01,
109  4.4881889763779526e-01,
110  4.5669291338582674e-01,
111  4.6456692913385828e-01,
112  4.7244094488188976e-01,
113  4.8031496062992124e-01,
114  4.8818897637795278e-01,
115  4.9606299212598426e-01,
116  5.0393700787401574e-01,
117  5.1181102362204722e-01,
118  5.1968503937007871e-01,
119  5.2755905511811019e-01,
120  5.3543307086614167e-01,
121  5.4330708661417326e-01,
122  5.5118110236220474e-01,
123  5.5905511811023623e-01,
124  5.6692913385826771e-01,
125  5.7480314960629919e-01,
126  5.8267716535433067e-01,
127  5.9055118110236215e-01,
128  5.9842519685039375e-01,
129  6.0629921259842523e-01,
130  6.1417322834645671e-01,
131  6.2204724409448819e-01,
132  6.2992125984251968e-01,
133  6.3779527559055116e-01,
134  6.4566929133858264e-01,
135  6.5354330708661412e-01,
136  6.6141732283464560e-01,
137  6.6929133858267720e-01,
138  6.7716535433070868e-01,
139  6.8503937007874016e-01,
140  6.9291338582677164e-01,
141  7.0078740157480313e-01,
142  7.0866141732283461e-01,
143  7.1653543307086609e-01,
144  7.2440944881889768e-01,
145  7.3228346456692917e-01,
146  7.4015748031496065e-01,
147  7.4803149606299213e-01,
148  7.5590551181102361e-01,
149  7.6377952755905509e-01,
150  7.7165354330708658e-01,
151  7.7952755905511806e-01,
152  7.8740157480314954e-01,
153  7.9527559055118113e-01,
154  8.0314960629921262e-01,
155  8.1102362204724410e-01,
156  8.1889763779527558e-01,
157  8.2677165354330706e-01,
158  8.3464566929133854e-01,
159  8.4251968503937003e-01,
160  8.5039370078740162e-01,
161  8.5826771653543310e-01,
162  8.6614173228346458e-01,
163  8.7401574803149606e-01,
164  8.8188976377952755e-01,
165  8.8976377952755903e-01,
166  8.9763779527559051e-01,
167  9.0551181102362199e-01,
168  9.1338582677165348e-01,
169  9.2125984251968507e-01,
170  9.2913385826771655e-01,
171  9.3700787401574803e-01,
172  9.4488188976377951e-01,
173  9.5275590551181100e-01,
174  9.6062992125984248e-01,
175  9.6850393700787396e-01,
176  9.7637795275590555e-01,
177  9.8425196850393704e-01,
178  9.9212598425196852e-01,
179  1.0000000000000000e+00
180  };
181 
182 
183  TTFloat64 expectedSignal1[128] = {
184  0.0000000000000000e+00,
185  5.4459838138251452e-04,
186  6.0741098906512316e-04,
187  6.7746824494861984e-04,
188  7.5560572853672282e-04,
189  8.4275539297168356e-04,
190  9.3995668052738817e-04,
191  1.0483689201354687e-03,
192  1.1692851548109023e-03,
193  1.3041475638981023e-03,
194  1.4545646640800906e-03,
195  1.6223304943087989e-03,
196  1.8094460134770003e-03,
197  2.0181429660438891e-03,
198  2.2509105002619062e-03,
199  2.5105248564828981e-03,
200  2.8000824796388488e-03,
201  3.1230369508328543e-03,
202  3.4832401785269388e-03,
203  3.8849883406178545e-03,
204  4.3330731253563891e-03,
205  4.8328388822654212e-03,
206  5.3902463647011439e-03,
207  6.0119438243209783e-03,
208  6.7053463054086316e-03,
209  7.4787240848071977e-03,
210  8.3413013122916897e-03,
211  9.3033660278741010e-03,
212  1.0376392868227705e-02,
213  1.1573179925761791e-02,
214  1.2908001392677847e-02,
215  1.4396777810607315e-02,
216  1.6057265956414348e-02,
217  1.7909270628949623e-02,
218  1.9974880862755576e-02,
219  2.2278733386066448e-02,
220  2.4848306465391358e-02,
221  2.7714247641392749e-02,
222  3.0910739264996698e-02,
223  3.4475906193518875e-02,
224  3.8452270509436483e-02,
225  4.2887258685279650e-02,
226  4.7833767243645922e-02,
227  5.3350793659018327e-02,
228  5.9504140026212141e-02,
229  6.6367197888171262e-02,
230  7.4021823583828222e-02,
231  8.2559314556385044e-02,
232  9.2081498266536263e-02,
233  1.0270194669820409e-01,
234  1.1454733094231086e-01,
235  1.2775893201483723e-01,
236  1.4249432592883521e-01,
237  1.5892926311840999e-01,
238  1.7725976463073675e-01,
239  1.9770446008759240e-01,
240  2.2050719530149224e-01,
241  2.4593994064771210e-01,
242  2.7430603488062605e-01,
243  3.0594380308366237e-01,
244  3.4123059190450844e-01,
245  3.8058727020419614e-01,
246  4.2448324879973404e-01,
247  4.7344207917122838e-01,
248  5.2655792082877162e-01,
249  5.7551675120026591e-01,
250  6.1941272979580342e-01,
251  6.5876940809549112e-01,
252  6.9405619691633724e-01,
253  7.2569396511937390e-01,
254  7.5406005935228793e-01,
255  7.7949280469850779e-01,
256  8.0229553991240765e-01,
257  8.2274023536926322e-01,
258  8.4107073688158984e-01,
259  8.5750567407116463e-01,
260  8.7224106798516277e-01,
261  8.8545266905768905e-01,
262  8.9729805330179579e-01,
263  9.0791850173346367e-01,
264  9.1744068544361490e-01,
265  9.2597817641617175e-01,
266  9.3363280211182864e-01,
267  9.4049585997378782e-01,
268  9.4664920634098160e-01,
269  9.5216623275635404e-01,
270  9.5711274131472035e-01,
271  9.6154772949056355e-01,
272  9.6552409380648108e-01,
273  9.6908926073500334e-01,
274  9.7228575235860726e-01,
275  9.7515169353460862e-01,
276  9.7772126661393355e-01,
277  9.8002511913724444e-01,
278  9.8209072937105035e-01,
279  9.8394273404358568e-01,
280  9.8560322218939267e-01,
281  9.8709199860732211e-01,
282  9.8842682007423821e-01,
283  9.8962360713177233e-01,
284  9.9069663397212593e-01,
285  9.9165869868770828e-01,
286  9.9252127591519279e-01,
287  9.9329465369459136e-01,
288  9.9398805617567898e-01,
289  9.9460975363529880e-01,
290  9.9516716111773462e-01,
291  9.9566692687464364e-01,
292  9.9611501165938210e-01,
293  9.9651675982147303e-01,
294  9.9687696304916718e-01,
295  9.9719991752036119e-01,
296  9.9748947514351716e-01,
297  9.9774908949973806e-01,
298  9.9798185703395614e-01,
299  9.9819055398652301e-01,
300  9.9837766950569118e-01,
301  9.9854543533591988e-01,
302  9.9869585243610193e-01,
303  9.9883071484518915e-01,
304  9.9895163107986451e-01,
305  9.9906004331947262e-01,
306  9.9915724460702826e-01,
307  9.9924439427146328e-01,
308  9.9932253175505137e-01,
309  9.9939258901093486e-01,
310  9.9945540161861746e-01,
311  1.0000000000000000e+00
312  };
313 
314  // setup Function
315  this->setAttributeValue(TT("function"), TT("easeInOutExponential"));
316 
317 
318  // create 1 channel audio signal objects
319  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
320  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
321  input->allocWithVectorSize(N);
322  output->allocWithVectorSize(N);
323 
324  // create a signal to be transformed and then process it)
325  input->clear();
326  for (int i=0; i<N; i++)
327  input->mSampleVectors[0][i] = inputSignal1[i];
328 
329  this->process(input, output);
330 
331  // now test the output
332  for (int n=0; n<N; n++)
333  {
334  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
335  badSampleCount += result;
336  if (result)
337  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
338  }
339 
340  TTTestAssertion("Produces correct function values",
341  badSampleCount == 0,
342  testAssertionCount,
343  errorCount);
344  if (badSampleCount)
345  TTTestLog("badSampleCount is %i", badSampleCount);
346 
347 
348  TTObjectBaseRelease(&input);
349  TTObjectBaseRelease(&output);
350 
351  // wrap up test results and pass back to whoever called test
352  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
353 
354 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTExponentialEaseInOutFunction Unit for Jamoms DSP