Jamoma API  0.6.0.a19
TTElasticEaseInFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTElasticEaseInFunction 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  y = sin(13 * pi * 0.5 * x) .* (2 .^ (10 * (x - 1)))
26  printf("%.16e,\n", y)
27  plot (x,y)
28 
29  */
30 
32 {
33  int errorCount = 0;
34  int testAssertionCount = 0;
35  int badSampleCount = 0;
36  TTAudioSignalPtr input = NULL;
37  TTAudioSignalPtr output = NULL;
38  int N = 128;
39  TTValue v;
40 
41 
42  TTFloat64 inputSignal1[128] = {
43  0.0000000000000000e+00,
44  7.8740157480314960e-03,
45  1.5748031496062992e-02,
46  2.3622047244094488e-02,
47  3.1496062992125984e-02,
48  3.9370078740157480e-02,
49  4.7244094488188976e-02,
50  5.5118110236220472e-02,
51  6.2992125984251968e-02,
52  7.0866141732283464e-02,
53  7.8740157480314960e-02,
54  8.6614173228346455e-02,
55  9.4488188976377951e-02,
56  1.0236220472440945e-01,
57  1.1023622047244094e-01,
58  1.1811023622047244e-01,
59  1.2598425196850394e-01,
60  1.3385826771653542e-01,
61  1.4173228346456693e-01,
62  1.4960629921259844e-01,
63  1.5748031496062992e-01,
64  1.6535433070866140e-01,
65  1.7322834645669291e-01,
66  1.8110236220472442e-01,
67  1.8897637795275590e-01,
68  1.9685039370078738e-01,
69  2.0472440944881889e-01,
70  2.1259842519685040e-01,
71  2.2047244094488189e-01,
72  2.2834645669291337e-01,
73  2.3622047244094488e-01,
74  2.4409448818897639e-01,
75  2.5196850393700787e-01,
76  2.5984251968503935e-01,
77  2.6771653543307083e-01,
78  2.7559055118110237e-01,
79  2.8346456692913385e-01,
80  2.9133858267716534e-01,
81  2.9921259842519687e-01,
82  3.0708661417322836e-01,
83  3.1496062992125984e-01,
84  3.2283464566929132e-01,
85  3.3070866141732280e-01,
86  3.3858267716535434e-01,
87  3.4645669291338582e-01,
88  3.5433070866141730e-01,
89  3.6220472440944884e-01,
90  3.7007874015748032e-01,
91  3.7795275590551181e-01,
92  3.8582677165354329e-01,
93  3.9370078740157477e-01,
94  4.0157480314960631e-01,
95  4.0944881889763779e-01,
96  4.1732283464566927e-01,
97  4.2519685039370081e-01,
98  4.3307086614173229e-01,
99  4.4094488188976377e-01,
100  4.4881889763779526e-01,
101  4.5669291338582674e-01,
102  4.6456692913385828e-01,
103  4.7244094488188976e-01,
104  4.8031496062992124e-01,
105  4.8818897637795278e-01,
106  4.9606299212598426e-01,
107  5.0393700787401574e-01,
108  5.1181102362204722e-01,
109  5.1968503937007871e-01,
110  5.2755905511811019e-01,
111  5.3543307086614167e-01,
112  5.4330708661417326e-01,
113  5.5118110236220474e-01,
114  5.5905511811023623e-01,
115  5.6692913385826771e-01,
116  5.7480314960629919e-01,
117  5.8267716535433067e-01,
118  5.9055118110236215e-01,
119  5.9842519685039375e-01,
120  6.0629921259842523e-01,
121  6.1417322834645671e-01,
122  6.2204724409448819e-01,
123  6.2992125984251968e-01,
124  6.3779527559055116e-01,
125  6.4566929133858264e-01,
126  6.5354330708661412e-01,
127  6.6141732283464560e-01,
128  6.6929133858267720e-01,
129  6.7716535433070868e-01,
130  6.8503937007874016e-01,
131  6.9291338582677164e-01,
132  7.0078740157480313e-01,
133  7.0866141732283461e-01,
134  7.1653543307086609e-01,
135  7.2440944881889768e-01,
136  7.3228346456692917e-01,
137  7.4015748031496065e-01,
138  7.4803149606299213e-01,
139  7.5590551181102361e-01,
140  7.6377952755905509e-01,
141  7.7165354330708658e-01,
142  7.7952755905511806e-01,
143  7.8740157480314954e-01,
144  7.9527559055118113e-01,
145  8.0314960629921262e-01,
146  8.1102362204724410e-01,
147  8.1889763779527558e-01,
148  8.2677165354330706e-01,
149  8.3464566929133854e-01,
150  8.4251968503937003e-01,
151  8.5039370078740162e-01,
152  8.5826771653543310e-01,
153  8.6614173228346458e-01,
154  8.7401574803149606e-01,
155  8.8188976377952755e-01,
156  8.8976377952755903e-01,
157  8.9763779527559051e-01,
158  9.0551181102362199e-01,
159  9.1338582677165348e-01,
160  9.2125984251968507e-01,
161  9.2913385826771655e-01,
162  9.3700787401574803e-01,
163  9.4488188976377951e-01,
164  9.5275590551181100e-01,
165  9.6062992125984248e-01,
166  9.6850393700787396e-01,
167  9.7637795275590555e-01,
168  9.8425196850393704e-01,
169  9.9212598425196852e-01,
170  1.0000000000000000e+00
171  };
172 
173 
174  TTFloat64 expectedSignal1[128] = {
175  0.0000000000000000e+00,
176  1.6511622402257687e-04,
177  3.4425838175774440e-04,
178  5.3359976139204398e-04,
179  7.2856231650065553e-04,
180  9.2386914343798969e-04,
181  1.1136242507702868e-03,
182  1.2914203442201755e-03,
183  1.4504745825983582e-03,
184  1.5837914049774921e-03,
185  1.6843506028489832e-03,
186  1.7453178331302852e-03,
187  1.7602737624540146e-03,
188  1.7234570275485020e-03,
189  1.6300152212534943e-03,
190  1.4762572019456665e-03,
191  1.2598992109101746e-03,
192  9.8029660356658156e-04,
193  6.3865249259043456e-04,
194  2.3819429899558386e-04,
195  -2.1569085591851696e-04,
196  -7.1537077973181167e-04,
197  -1.2509412230517125e-03,
198  -1.8102648327662143e-03,
199  -2.3790824657985519e-03,
200  -2.9412018262317545e-03,
201  -3.4787666110905596e-03,
202  -3.9726072706593963e-03,
203  -4.4026721363630873e-03,
204  -4.7485350829104362e-03,
205  -4.9899731232742797e-03,
206  -5.1076044483146796e-03,
207  -5.0835744914944211e-03,
208  -4.9022747071338999e-03,
209  -4.5510759904376762e-03,
210  -4.0210561381850054e-03,
211  -3.3076985540107877e-03,
212  -2.4115376468862122e-03,
213  -1.3387251597950349e-03,
214  -1.0149109722392311e-04,
215  1.2815269135929514e-03,
216  2.7851110120301684e-03,
217  4.3774705691725065e-03,
218  6.0204502712682996e-03,
219  7.6699556363490143e-03,
220  9.2766081100529672e-03,
221  1.0786636310290710e-02,
222  1.2143003571159978e-02,
223  1.3286764772338993e-02,
224  1.4158637662869350e-02,
225  1.4700765663432336e-02,
226  1.4858640657277263e-02,
227  1.4583145785680490e-02,
228  1.3832670005008662e-02,
229  1.2575238417287775e-02,
230  1.0790595449269897e-02,
231  8.4721721303899176e-03,
232  5.6288643130248516e-03,
233  2.2865459865490617e-03,
234  -1.5107588605578100e-03,
235  -5.7001208275947700e-03,
236  -1.0199437127954666e-02,
237  -1.4907715419073287e-02,
238  -1.9705964453592791e-02,
239  -2.4458734472603771e-02,
240  -2.9016335465473775e-02,
241  -3.3217744063089388e-02,
242  -3.6894190144443069e-02,
243  -3.9873392550061539e-02,
244  -4.1984390038259309e-02,
245  -4.3062889317242906e-02,
246  -4.2957027255715471e-02,
247  -4.1533419919136311e-02,
248  -3.8683347673126020e-02,
249  -3.4328904072093248e-02,
250  -2.8428917481222813e-02,
251  -2.0984439251534374e-02,
252  -1.2043581660577365e-02,
253  -1.7054835893109870e-03,
254  9.8768171930511753e-03,
255  2.2494818538828225e-02,
256  3.5884493526544332e-02,
257  4.9727910589859731e-02,
258  6.3656678759792612e-02,
259  7.7257323817575163e-02,
260  9.0078654674304981e-02,
261  1.0164112564863097e-01,
262  1.1144814030916596e-01,
263  1.1899917727426858e-01,
264  1.2380454919431993e-01,
265  1.2540153473366947e-01,
266  1.2337155163285182e-01,
267  1.1735796900876887e-01,
268  1.0708409127554892e-01,
269  9.2370786919149364e-02,
270  7.3153185396289858e-02,
271  4.9495827231023706e-02,
272  2.1605628468054860e-02,
273  -1.0157986615066190e-02,
274  -4.5276419092721711e-02,
275  -8.3069297670388176e-02,
276  -1.2269649788020918e-01,
277  -1.6316524932979778e-01,
278  -2.0334270184643921e-01,
279  -2.4197419822596497e-01,
280  -2.7770735643253130e-01,
281  -3.0912189939872281e-01,
282  -3.3476498876255623e-01,
283  -3.5319162350068317e-01,
284  -3.6300945984860056e-01,
285  -3.6292720029618519e-01,
286  -3.5180549268475941e-01,
287  -3.2870908200639715e-01,
288  -2.9295877440917129e-01,
289  -2.4418161247623857e-01,
290  -1.8235753056148010e-01,
291  -1.0786066626716612e-01,
292  -2.1493456192032547e-02,
293  7.5488352520700033e-02,
294  1.8136158272668765e-01,
295  2.9393408529535514e-01,
296  4.1055727211371790e-01,
297  5.2815396655421210e-01,
298  6.4326249166226201e-01,
299  7.5209752896816062e-01,
300  8.5062783260444752e-01,
301  9.3467038091627519e-01,
302  1.0000000000000000e+00
303  };
304 
305  // setup Function
306  this->setAttributeValue(TT("function"), TT("easeInElastic"));
307 
308 
309  // create 1 channel audio signal objects
310  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
311  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
312  input->allocWithVectorSize(N);
313  output->allocWithVectorSize(N);
314 
315  // create a signal to be transformed and then process it)
316  input->clear();
317  for (int i=0; i<N; i++)
318  input->mSampleVectors[0][i] = inputSignal1[i];
319 
320  this->process(input, output);
321 
322  // now test the output
323  for (int n=0; n<N; n++)
324  {
325  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
326  badSampleCount += result;
327  if (result)
328  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
329  }
330 
331  TTTestAssertion("Produces correct function values",
332  badSampleCount == 0,
333  testAssertionCount,
334  errorCount);
335  if (badSampleCount)
336  TTTestLog("badSampleCount is %i", badSampleCount);
337 
338 
339  TTObjectBaseRelease(&input);
340  TTObjectBaseRelease(&output);
341 
342  // wrap up test results and pass back to whoever called test
343  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
344 
345 }
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
TTElasticEaseInFunction 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
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.