Jamoma API  0.6.0.a19
TTBounceEaseOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTBounceEaseOutFunction 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 script found
23  * in the OctaveScript subfolder of this extension.
24  */
25 
27 {
28  int errorCount = 0;
29  int testAssertionCount = 0;
30  int badSampleCount = 0;
31  TTAudioSignalPtr input = NULL;
32  TTAudioSignalPtr output = NULL;
33  int N = 128;
34  TTValue v;
35 
36 
37  TTFloat64 inputSignal1[128] = {
38  0.0000000000000000e+00,
39  7.8740157480314960e-03,
40  1.5748031496062992e-02,
41  2.3622047244094488e-02,
42  3.1496062992125984e-02,
43  3.9370078740157480e-02,
44  4.7244094488188976e-02,
45  5.5118110236220472e-02,
46  6.2992125984251968e-02,
47  7.0866141732283464e-02,
48  7.8740157480314960e-02,
49  8.6614173228346455e-02,
50  9.4488188976377951e-02,
51  1.0236220472440945e-01,
52  1.1023622047244094e-01,
53  1.1811023622047244e-01,
54  1.2598425196850394e-01,
55  1.3385826771653542e-01,
56  1.4173228346456693e-01,
57  1.4960629921259844e-01,
58  1.5748031496062992e-01,
59  1.6535433070866140e-01,
60  1.7322834645669291e-01,
61  1.8110236220472442e-01,
62  1.8897637795275590e-01,
63  1.9685039370078738e-01,
64  2.0472440944881889e-01,
65  2.1259842519685040e-01,
66  2.2047244094488189e-01,
67  2.2834645669291337e-01,
68  2.3622047244094488e-01,
69  2.4409448818897639e-01,
70  2.5196850393700787e-01,
71  2.5984251968503935e-01,
72  2.6771653543307083e-01,
73  2.7559055118110237e-01,
74  2.8346456692913385e-01,
75  2.9133858267716534e-01,
76  2.9921259842519687e-01,
77  3.0708661417322836e-01,
78  3.1496062992125984e-01,
79  3.2283464566929132e-01,
80  3.3070866141732280e-01,
81  3.3858267716535434e-01,
82  3.4645669291338582e-01,
83  3.5433070866141730e-01,
84  3.6220472440944884e-01,
85  3.7007874015748032e-01,
86  3.7795275590551181e-01,
87  3.8582677165354329e-01,
88  3.9370078740157477e-01,
89  4.0157480314960631e-01,
90  4.0944881889763779e-01,
91  4.1732283464566927e-01,
92  4.2519685039370081e-01,
93  4.3307086614173229e-01,
94  4.4094488188976377e-01,
95  4.4881889763779526e-01,
96  4.5669291338582674e-01,
97  4.6456692913385828e-01,
98  4.7244094488188976e-01,
99  4.8031496062992124e-01,
100  4.8818897637795278e-01,
101  4.9606299212598426e-01,
102  5.0393700787401574e-01,
103  5.1181102362204722e-01,
104  5.1968503937007871e-01,
105  5.2755905511811019e-01,
106  5.3543307086614167e-01,
107  5.4330708661417326e-01,
108  5.5118110236220474e-01,
109  5.5905511811023623e-01,
110  5.6692913385826771e-01,
111  5.7480314960629919e-01,
112  5.8267716535433067e-01,
113  5.9055118110236215e-01,
114  5.9842519685039375e-01,
115  6.0629921259842523e-01,
116  6.1417322834645671e-01,
117  6.2204724409448819e-01,
118  6.2992125984251968e-01,
119  6.3779527559055116e-01,
120  6.4566929133858264e-01,
121  6.5354330708661412e-01,
122  6.6141732283464560e-01,
123  6.6929133858267720e-01,
124  6.7716535433070868e-01,
125  6.8503937007874016e-01,
126  6.9291338582677164e-01,
127  7.0078740157480313e-01,
128  7.0866141732283461e-01,
129  7.1653543307086609e-01,
130  7.2440944881889768e-01,
131  7.3228346456692917e-01,
132  7.4015748031496065e-01,
133  7.4803149606299213e-01,
134  7.5590551181102361e-01,
135  7.6377952755905509e-01,
136  7.7165354330708658e-01,
137  7.7952755905511806e-01,
138  7.8740157480314954e-01,
139  7.9527559055118113e-01,
140  8.0314960629921262e-01,
141  8.1102362204724410e-01,
142  8.1889763779527558e-01,
143  8.2677165354330706e-01,
144  8.3464566929133854e-01,
145  8.4251968503937003e-01,
146  8.5039370078740162e-01,
147  8.5826771653543310e-01,
148  8.6614173228346458e-01,
149  8.7401574803149606e-01,
150  8.8188976377952755e-01,
151  8.8976377952755903e-01,
152  8.9763779527559051e-01,
153  9.0551181102362199e-01,
154  9.1338582677165348e-01,
155  9.2125984251968507e-01,
156  9.2913385826771655e-01,
157  9.3700787401574803e-01,
158  9.4488188976377951e-01,
159  9.5275590551181100e-01,
160  9.6062992125984248e-01,
161  9.6850393700787396e-01,
162  9.7637795275590555e-01,
163  9.8425196850393704e-01,
164  9.9212598425196852e-01,
165  1.0000000000000000e+00
166  };
167 
168 
169  TTFloat64 expectedSignal1[128] = {
170  0.0000000000000000e+00,
171  4.6887593775187550e-04,
172  1.8755037510075020e-03,
173  4.2198834397668790e-03,
174  7.5020150040300080e-03,
175  1.1721898443796886e-02,
176  1.6879533759067516e-02,
177  2.2974920949841899e-02,
178  3.0008060016120032e-02,
179  3.7978950957901922e-02,
180  4.6887593775187544e-02,
181  5.6733988467976927e-02,
182  6.7518135036270063e-02,
183  7.9240033480066960e-02,
184  9.1899683799367596e-02,
185  1.0549708599417199e-01,
186  1.2003224006448013e-01,
187  1.3550514601029198e-01,
188  1.5191580383160769e-01,
189  1.6926421352842708e-01,
190  1.8755037510075018e-01,
191  2.0677428854857705e-01,
192  2.2693595387190771e-01,
193  2.4803537107074217e-01,
194  2.7007254014508025e-01,
195  2.9304746109492213e-01,
196  3.1696013392026784e-01,
197  3.4181055862111731e-01,
198  3.6759873519747038e-01,
199  3.9432466364932728e-01,
200  4.2198834397668794e-01,
201  4.5058977617955243e-01,
202  4.8012896025792051e-01,
203  5.1060589621179242e-01,
204  5.4202058404116793e-01,
205  5.7437302374604748e-01,
206  6.0766321532643075e-01,
207  6.4189115878231751e-01,
208  6.7705685411370831e-01,
209  7.1316030132060271e-01,
210  7.5020150040300071e-01,
211  7.8818045136090265e-01,
212  8.2709715419430818e-01,
213  8.6695160890321787e-01,
214  9.0774381548763083e-01,
215  9.4947377394754784e-01,
216  9.9214148428296867e-01,
217  9.7911680823361591e-01,
218  9.5461590923181783e-01,
219  9.3124031248062478e-01,
220  9.0899001798003587e-01,
221  8.8786502573005111e-01,
222  8.6786533573067137e-01,
223  8.4899094798189578e-01,
224  8.3124186248372522e-01,
225  8.1461807923615792e-01,
226  7.9911959823919654e-01,
227  7.8474641949283841e-01,
228  7.7149854299708576e-01,
229  7.5937596875193725e-01,
230  7.4837869675739332e-01,
231  7.3850672701345355e-01,
232  7.2976005952011880e-01,
233  7.2213869427738864e-01,
234  7.1564263128526173e-01,
235  7.1027187054374075e-01,
236  7.0602641205282302e-01,
237  7.0290625581251076e-01,
238  7.0091140182280354e-01,
239  7.0004185008369957e-01,
240  7.0029760059520108e-01,
241  7.0167865335730584e-01,
242  7.0418500837001607e-01,
243  7.0781666563333046e-01,
244  7.1257362514724987e-01,
245  7.1845588691177342e-01,
246  7.2546345092690112e-01,
247  7.3359631719263430e-01,
248  7.4285448570897072e-01,
249  7.5323795647591263e-01,
250  7.6474672949345823e-01,
251  7.7738080476160887e-01,
252  7.9114018228036453e-01,
253  8.0602486204972346e-01,
254  8.2203484406968785e-01,
255  8.3917012834025639e-01,
256  8.5743071486142997e-01,
257  8.7681660363320679e-01,
258  8.9732779465558865e-01,
259  9.1896428792857554e-01,
260  9.4172608345216569e-01,
261  9.6561318122636175e-01,
262  9.9062558125116196e-01,
263  9.8985952764149321e-01,
264  9.7514870154394018e-01,
265  9.6193412220619479e-01,
266  9.5021578962825526e-01,
267  9.3999370381012337e-01,
268  9.3126786475179735e-01,
269  9.2403827245327719e-01,
270  9.1830492691456289e-01,
271  9.1406782813565624e-01,
272  9.1132697611655544e-01,
273  9.1008237085726229e-01,
274  9.1033401235777411e-01,
275  9.1208190061809447e-01,
276  9.1532603563821979e-01,
277  9.2006641741815365e-01,
278  9.2630304595789248e-01,
279  9.3403592125743984e-01,
280  9.4326504331679040e-01,
281  9.5399041213594948e-01,
282  9.6621202771491355e-01,
283  9.7992989005368614e-01,
284  9.9514399915226726e-01,
285  9.9437534875069744e-01,
286  9.8747845495691067e-01,
287  9.8192076384152749e-01,
288  9.7770227540455146e-01,
289  9.7482298964598080e-01,
290  9.7328290656581551e-01,
291  9.7308202616405559e-01,
292  9.7422034844069927e-01,
293  9.7669787339574832e-01,
294  9.8051460102920629e-01,
295  9.8567053134106253e-01,
296  9.9216566433133124e-01,
297  1.0000000000000018e+00
298  };
299 
300  // setup Function
301  this->setAttributeValue(TT("function"), TT("easeOutBounce"));
302 
303 
304  // create 1 channel audio signal objects
305  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
306  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
307  input->allocWithVectorSize(N);
308  output->allocWithVectorSize(N);
309 
310  // create a signal to be transformed and then process it)
311  input->clear();
312  for (int i=0; i<N; i++)
313  input->mSampleVectors[0][i] = inputSignal1[i];
314 
315  this->process(input, output);
316 
317  // now test the output
318  for (int n=0; n<N; n++)
319  {
320  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
321  badSampleCount += result;
322  if (result)
323  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
324  }
325 
326  TTTestAssertion("Produces correct function values",
327  badSampleCount == 0,
328  testAssertionCount,
329  errorCount);
330  if (badSampleCount)
331  TTTestLog("badSampleCount is %i", badSampleCount);
332 
333 
334  TTObjectBaseRelease(&input);
335  TTObjectBaseRelease(&output);
336 
337  // wrap up test results and pass back to whoever called test
338  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
339 
340 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
virtual TTErr test(TTValue &returnedTestInfo)
Unit Tests.
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
TTBounceEaseOutFunction Unit for Jamoms 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