Jamoma API  0.6.0.a19
TTExponentialEaseInFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTExponentialEaseInFunction 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  if (x == 0.0)
26  y = x
27  else
28  y = 2 .^ (10 * (x - 1));
29  endif
30  printf("%.16e,\n", y)
31 
32  x = linspace(0,1,128);
33  y = ((x == 0.0) .* x) + ((x != 0.0) .* (2 .^ (10 * (x - 1))))
34  printf("%.16e,\n", y)
35 
36  */
37 
39 {
40  int errorCount = 0;
41  int testAssertionCount = 0;
42  int badSampleCount = 0;
43  TTAudioSignalPtr input = NULL;
44  TTAudioSignalPtr output = NULL;
45  int N = 128;
46  TTValue v;
47 
48 
49  TTFloat64 inputSignal1[128] = {
50  0.0000000000000000e+00,
51  7.8740157480314960e-03,
52  1.5748031496062992e-02,
53  2.3622047244094488e-02,
54  3.1496062992125984e-02,
55  3.9370078740157480e-02,
56  4.7244094488188976e-02,
57  5.5118110236220472e-02,
58  6.2992125984251968e-02,
59  7.0866141732283464e-02,
60  7.8740157480314960e-02,
61  8.6614173228346455e-02,
62  9.4488188976377951e-02,
63  1.0236220472440945e-01,
64  1.1023622047244094e-01,
65  1.1811023622047244e-01,
66  1.2598425196850394e-01,
67  1.3385826771653542e-01,
68  1.4173228346456693e-01,
69  1.4960629921259844e-01,
70  1.5748031496062992e-01,
71  1.6535433070866140e-01,
72  1.7322834645669291e-01,
73  1.8110236220472442e-01,
74  1.8897637795275590e-01,
75  1.9685039370078738e-01,
76  2.0472440944881889e-01,
77  2.1259842519685040e-01,
78  2.2047244094488189e-01,
79  2.2834645669291337e-01,
80  2.3622047244094488e-01,
81  2.4409448818897639e-01,
82  2.5196850393700787e-01,
83  2.5984251968503935e-01,
84  2.6771653543307083e-01,
85  2.7559055118110237e-01,
86  2.8346456692913385e-01,
87  2.9133858267716534e-01,
88  2.9921259842519687e-01,
89  3.0708661417322836e-01,
90  3.1496062992125984e-01,
91  3.2283464566929132e-01,
92  3.3070866141732280e-01,
93  3.3858267716535434e-01,
94  3.4645669291338582e-01,
95  3.5433070866141730e-01,
96  3.6220472440944884e-01,
97  3.7007874015748032e-01,
98  3.7795275590551181e-01,
99  3.8582677165354329e-01,
100  3.9370078740157477e-01,
101  4.0157480314960631e-01,
102  4.0944881889763779e-01,
103  4.1732283464566927e-01,
104  4.2519685039370081e-01,
105  4.3307086614173229e-01,
106  4.4094488188976377e-01,
107  4.4881889763779526e-01,
108  4.5669291338582674e-01,
109  4.6456692913385828e-01,
110  4.7244094488188976e-01,
111  4.8031496062992124e-01,
112  4.8818897637795278e-01,
113  4.9606299212598426e-01,
114  5.0393700787401574e-01,
115  5.1181102362204722e-01,
116  5.1968503937007871e-01,
117  5.2755905511811019e-01,
118  5.3543307086614167e-01,
119  5.4330708661417326e-01,
120  5.5118110236220474e-01,
121  5.5905511811023623e-01,
122  5.6692913385826771e-01,
123  5.7480314960629919e-01,
124  5.8267716535433067e-01,
125  5.9055118110236215e-01,
126  5.9842519685039375e-01,
127  6.0629921259842523e-01,
128  6.1417322834645671e-01,
129  6.2204724409448819e-01,
130  6.2992125984251968e-01,
131  6.3779527559055116e-01,
132  6.4566929133858264e-01,
133  6.5354330708661412e-01,
134  6.6141732283464560e-01,
135  6.6929133858267720e-01,
136  6.7716535433070868e-01,
137  6.8503937007874016e-01,
138  6.9291338582677164e-01,
139  7.0078740157480313e-01,
140  7.0866141732283461e-01,
141  7.1653543307086609e-01,
142  7.2440944881889768e-01,
143  7.3228346456692917e-01,
144  7.4015748031496065e-01,
145  7.4803149606299213e-01,
146  7.5590551181102361e-01,
147  7.6377952755905509e-01,
148  7.7165354330708658e-01,
149  7.7952755905511806e-01,
150  7.8740157480314954e-01,
151  7.9527559055118113e-01,
152  8.0314960629921262e-01,
153  8.1102362204724410e-01,
154  8.1889763779527558e-01,
155  8.2677165354330706e-01,
156  8.3464566929133854e-01,
157  8.4251968503937003e-01,
158  8.5039370078740162e-01,
159  8.5826771653543310e-01,
160  8.6614173228346458e-01,
161  8.7401574803149606e-01,
162  8.8188976377952755e-01,
163  8.8976377952755903e-01,
164  8.9763779527559051e-01,
165  9.0551181102362199e-01,
166  9.1338582677165348e-01,
167  9.2125984251968507e-01,
168  9.2913385826771655e-01,
169  9.3700787401574803e-01,
170  9.4488188976377951e-01,
171  9.5275590551181100e-01,
172  9.6062992125984248e-01,
173  9.6850393700787396e-01,
174  9.7637795275590555e-01,
175  9.8425196850393704e-01,
176  9.9212598425196852e-01,
177  1.0000000000000000e+00
178  };
179 
180 
181  TTFloat64 expectedSignal1[128] = {
182  0.0000000000000000e+00,
183  1.0313431599800929e-03,
184  1.0891967627650290e-03,
185  1.1502956862977768e-03,
186  1.2148219781302463e-03,
187  1.2829678978438321e-03,
188  1.3549364898972414e-03,
189  1.4309421886084671e-03,
190  1.5112114570734456e-03,
191  1.5959834619251178e-03,
192  1.6855107859433671e-03,
193  1.7800601806390909e-03,
194  1.8799133610547763e-03,
195  1.9853678451497271e-03,
196  2.0967378402709375e-03,
197  2.2143551793509008e-03,
198  2.3385703096218046e-03,
199  2.4697533367920399e-03,
200  2.6082951277962047e-03,
201  2.7546084754043066e-03,
202  2.9091293281601777e-03,
203  3.0723180893137739e-03,
204  3.2446609886175978e-03,
205  3.4266715310745659e-03,
206  3.6188920269540005e-03,
207  3.8218952076344345e-03,
208  4.0362859320877782e-03,
209  4.2627029890893895e-03,
210  4.5018210005238158e-03,
211  4.7543524314572552e-03,
212  5.0210497129657998e-03,
213  5.3027074840445807e-03,
214  5.6001649592776976e-03,
215  5.9143084293235195e-03,
216  6.2460739016657087e-03,
217  6.5964498894982146e-03,
218  6.9664803570538732e-03,
219  7.3572678301523850e-03,
220  7.7699766812357090e-03,
221  8.2058365986788055e-03,
222  8.6661462507127782e-03,
223  9.1522771548771843e-03,
224  9.6656777645308424e-03,
225  1.0207877784597065e-02,
226  1.0780492729402295e-02,
227  1.1385228736188600e-02,
228  1.2023887648641957e-02,
229  1.2698372385583108e-02,
230  1.3410692610817263e-02,
231  1.4162970721036247e-02,
232  1.4957448169614395e-02,
233  1.5796492145140294e-02,
234  1.6682602624583379e-02,
235  1.7618419822110737e-02,
236  1.8606732055748202e-02,
237  1.9650484055324921e-02,
238  2.0752785736455410e-02,
239  2.1916921466701537e-02,
240  2.3146359851523583e-02,
241  2.4444764069178060e-02,
242  2.5816002785355712e-02,
243  2.7264161680080529e-02,
244  2.8793555621214630e-02,
245  3.0408741520840769e-02,
246  3.2114531912828696e-02,
247  3.3916009292040486e-02,
248  3.5818541257899246e-02,
249  3.7827796507442321e-02,
250  3.9949761725511151e-02,
251  4.2190759422403037e-02,
252  4.4557466772132896e-02,
253  4.7056935507435040e-02,
254  4.9696612930782716e-02,
255  5.2484364104029180e-02,
256  5.5428495282785498e-02,
257  5.8537778665359023e-02,
258  6.1821478529993396e-02,
259  6.5289378838287240e-02,
260  6.8951812387037764e-02,
261  7.2819691595368496e-02,
262  7.6904541018872993e-02,
263  8.1218531687652501e-02,
264  8.5774517370559328e-02,
265  9.0586072873697313e-02,
266  9.5667534487291872e-02,
267  1.0103404270144328e-01,
268  1.0670158731803665e-01,
269  1.1268705509322315e-01,
270  1.1900828005242428e-01,
271  1.2568409662777663e-01,
272  1.3273439577634252e-01,
273  1.4018018424629392e-01,
274  1.4804364716765644e-01,
275  1.5634821415410557e-01,
276  1.6511862911277009e-01,
277  1.7438102397004315e-01,
278  1.8416299653307253e-01,
279  1.9449369271892167e-01,
280  2.0540389339640819e-01,
281  2.1692610609936974e-01,
282  2.2909466188462171e-01,
283  2.4194581762320061e-01,
284  2.5551786402967452e-01,
285  2.6985123975140174e-01,
286  2.8498865185767047e-01,
287  3.0097520308772502e-01,
288  3.1785852623681998e-01,
289  3.3568892608071393e-01,
290  3.5451952926147340e-01,
291  3.7440644258117944e-01,
292  3.9540892017518470e-01,
293  4.1758954006301829e-01,
294  4.4101439060298436e-01,
295  4.6575326740600514e-01,
296  4.9187988129542409e-01,
297  5.1947207793239625e-01,
298  5.4861206976125199e-01,
299  5.7938668096592816e-01,
300  6.1188760616732496e-01,
301  6.4621168363239789e-01,
302  6.8246118380901721e-01,
303  7.2074411404630712e-01,
304  7.6117454040839261e-01,
305  8.0387292754041506e-01,
306  8.4896649759946807e-01,
307  8.9658960931990261e-01,
308  9.4688415834245676e-01,
309  1.0000000000000000e+00
310  };
311 
312  // setup Function
313  this->setAttributeValue(TT("function"), TT("easeInExponential"));
314 
315 
316  // create 1 channel audio signal objects
317  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
318  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
319  input->allocWithVectorSize(N);
320  output->allocWithVectorSize(N);
321 
322  // create a signal to be transformed and then process it)
323  input->clear();
324  for (int i=0; i<N; i++)
325  input->mSampleVectors[0][i] = inputSignal1[i];
326 
327  this->process(input, output);
328 
329  // now test the output
330  for (int n=0; n<N; n++)
331  {
332  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
333  badSampleCount += result;
334  if (result)
335  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
336  }
337 
338  TTTestAssertion("Produces correct function values",
339  badSampleCount == 0,
340  testAssertionCount,
341  errorCount);
342  if (badSampleCount)
343  TTTestLog("badSampleCount is %i", badSampleCount);
344 
345 
346  TTObjectBaseRelease(&input);
347  TTObjectBaseRelease(&output);
348 
349  // wrap up test results and pass back to whoever called test
350  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
351 
352 }
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
TTExponentialEaseInFunction Unit for Jamoms DSP
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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