Jamoma API  0.6.0.a19
TTCircularEaseInOutFunction.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFunctionLib
4  *
5  * @brief Unit tests for the Jamoma DSP #TTCircularEaseInOutFunction 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 .* (1 - sqrt(1 - 4 * (x .* x))))
27  yb = (x >= 0.5) .* (0.5 * (sqrt(-((2 * x) - 3) .* ((2 * x) - 1)) + 1))
28 
29  y = ya + yb
30 
31  printf("%.16e,\n", y)
32  plot (x,y)
33 
34  */
35 
37 {
38  int errorCount = 0;
39  int testAssertionCount = 0;
40  int badSampleCount = 0;
41  TTAudioSignalPtr input = NULL;
42  TTAudioSignalPtr output = NULL;
43  int N = 128;
44  TTValue v;
45 
46 
47  TTFloat64 inputSignal1[128] = {
48  0.0000000000000000e+00,
49  7.8740157480314960e-03,
50  1.5748031496062992e-02,
51  2.3622047244094488e-02,
52  3.1496062992125984e-02,
53  3.9370078740157480e-02,
54  4.7244094488188976e-02,
55  5.5118110236220472e-02,
56  6.2992125984251968e-02,
57  7.0866141732283464e-02,
58  7.8740157480314960e-02,
59  8.6614173228346455e-02,
60  9.4488188976377951e-02,
61  1.0236220472440945e-01,
62  1.1023622047244094e-01,
63  1.1811023622047244e-01,
64  1.2598425196850394e-01,
65  1.3385826771653542e-01,
66  1.4173228346456693e-01,
67  1.4960629921259844e-01,
68  1.5748031496062992e-01,
69  1.6535433070866140e-01,
70  1.7322834645669291e-01,
71  1.8110236220472442e-01,
72  1.8897637795275590e-01,
73  1.9685039370078738e-01,
74  2.0472440944881889e-01,
75  2.1259842519685040e-01,
76  2.2047244094488189e-01,
77  2.2834645669291337e-01,
78  2.3622047244094488e-01,
79  2.4409448818897639e-01,
80  2.5196850393700787e-01,
81  2.5984251968503935e-01,
82  2.6771653543307083e-01,
83  2.7559055118110237e-01,
84  2.8346456692913385e-01,
85  2.9133858267716534e-01,
86  2.9921259842519687e-01,
87  3.0708661417322836e-01,
88  3.1496062992125984e-01,
89  3.2283464566929132e-01,
90  3.3070866141732280e-01,
91  3.3858267716535434e-01,
92  3.4645669291338582e-01,
93  3.5433070866141730e-01,
94  3.6220472440944884e-01,
95  3.7007874015748032e-01,
96  3.7795275590551181e-01,
97  3.8582677165354329e-01,
98  3.9370078740157477e-01,
99  4.0157480314960631e-01,
100  4.0944881889763779e-01,
101  4.1732283464566927e-01,
102  4.2519685039370081e-01,
103  4.3307086614173229e-01,
104  4.4094488188976377e-01,
105  4.4881889763779526e-01,
106  4.5669291338582674e-01,
107  4.6456692913385828e-01,
108  4.7244094488188976e-01,
109  4.8031496062992124e-01,
110  4.8818897637795278e-01,
111  4.9606299212598426e-01,
112  5.0393700787401574e-01,
113  5.1181102362204722e-01,
114  5.1968503937007871e-01,
115  5.2755905511811019e-01,
116  5.3543307086614167e-01,
117  5.4330708661417326e-01,
118  5.5118110236220474e-01,
119  5.5905511811023623e-01,
120  5.6692913385826771e-01,
121  5.7480314960629919e-01,
122  5.8267716535433067e-01,
123  5.9055118110236215e-01,
124  5.9842519685039375e-01,
125  6.0629921259842523e-01,
126  6.1417322834645671e-01,
127  6.2204724409448819e-01,
128  6.2992125984251968e-01,
129  6.3779527559055116e-01,
130  6.4566929133858264e-01,
131  6.5354330708661412e-01,
132  6.6141732283464560e-01,
133  6.6929133858267720e-01,
134  6.7716535433070868e-01,
135  6.8503937007874016e-01,
136  6.9291338582677164e-01,
137  7.0078740157480313e-01,
138  7.0866141732283461e-01,
139  7.1653543307086609e-01,
140  7.2440944881889768e-01,
141  7.3228346456692917e-01,
142  7.4015748031496065e-01,
143  7.4803149606299213e-01,
144  7.5590551181102361e-01,
145  7.6377952755905509e-01,
146  7.7165354330708658e-01,
147  7.7952755905511806e-01,
148  7.8740157480314954e-01,
149  7.9527559055118113e-01,
150  8.0314960629921262e-01,
151  8.1102362204724410e-01,
152  8.1889763779527558e-01,
153  8.2677165354330706e-01,
154  8.3464566929133854e-01,
155  8.4251968503937003e-01,
156  8.5039370078740162e-01,
157  8.5826771653543310e-01,
158  8.6614173228346458e-01,
159  8.7401574803149606e-01,
160  8.8188976377952755e-01,
161  8.8976377952755903e-01,
162  8.9763779527559051e-01,
163  9.0551181102362199e-01,
164  9.1338582677165348e-01,
165  9.2125984251968507e-01,
166  9.2913385826771655e-01,
167  9.3700787401574803e-01,
168  9.4488188976377951e-01,
169  9.5275590551181100e-01,
170  9.6062992125984248e-01,
171  9.6850393700787396e-01,
172  9.7637795275590555e-01,
173  9.8425196850393704e-01,
174  9.9212598425196852e-01,
175  1.0000000000000000e+00
176  };
177 
178 
179  TTFloat64 expectedSignal1[128] = {
180  0.0000000000000000e+00,
181  6.2003968492374550e-05,
182  2.4806203077210043e-04,
183  5.5831282921753322e-04,
184  9.9298800919034313e-04,
185  1.5524130863970309e-03,
186  2.2370086718066506e-03,
187  3.0472920649411983e-03,
188  3.9838792297329784e-03,
189  5.0474871707590907e-03,
190  6.2389367315652811e-03,
191  7.5591558410594284e-03,
192  9.0091832386635096e-03,
193  1.0590172714157631e-02,
194  1.2303397904033564e-02,
195  1.4150257692829293e-02,
196  1.6132282275479248e-02,
197  1.8251139945377415e-02,
198  2.0508644682805943e-02,
199  2.2906764629899157e-02,
200  2.5447631551689776e-02,
201  2.8133551398395518e-02,
202  3.0967016102406764e-02,
203  3.3950716764987621e-02,
204  3.7087558413194999e-02,
205  4.0380676537805915e-02,
206  4.3833455659194165e-02,
207  4.7449550211449698e-02,
208  5.1232908087273432e-02,
209  5.5187797249455606e-02,
210  5.9318835891778998e-02,
211  6.3631026726507889e-02,
212  6.8129796091758565e-02,
213  7.2821038715938258e-02,
214  7.7711169155856852e-02,
215  8.2807181150374776e-02,
216  8.8116716416314633e-02,
217  9.3648144776401321e-02,
218  9.9410657975474992e-02,
219  1.0541438014592730e-01,
220  1.1167049867463946e-01,
221  1.1819142026981228e-01,
222  1.2499095842425006e-01,
223  1.3208456036265420e-01,
224  1.3948958415113738e-01,
225  1.4722564024649154e-01,
226  1.5531501684077498e-01,
227  1.6378321564286508e-01,
228  1.7265963538935714e-01,
229  1.8197845627158438e-01,
230  1.9177980273937267e-01,
231  2.0211130018855206e-01,
232  2.1303020245445792e-01,
233  2.2460636956657221e-01,
234  2.3692655319231321e-01,
235  2.5010077051089213e-01,
236  2.6427216724531177e-01,
237  2.7963303985580262e-01,
238  2.9645250465022727e-01,
239  3.1512823808072604e-01,
240  3.3629430798195437e-01,
241  3.6108441917813106e-01,
242  3.9196517532273834e-01,
243  4.3737805621816206e-01,
244  5.6262194378183805e-01,
245  6.0803482467726166e-01,
246  6.3891558082186872e-01,
247  6.6370569201804552e-01,
248  6.8487176191927379e-01,
249  7.0354749534977268e-01,
250  7.2036696014419732e-01,
251  7.3572783275468823e-01,
252  7.4989922948910781e-01,
253  7.6307344680768674e-01,
254  7.7539363043342768e-01,
255  7.8696979754554208e-01,
256  7.9788869981144805e-01,
257  8.0822019726062733e-01,
258  8.1802154372841562e-01,
259  8.2734036461064286e-01,
260  8.3621678435713487e-01,
261  8.4468498315922491e-01,
262  8.5277435975350846e-01,
263  8.6051041584886256e-01,
264  8.6791543963734574e-01,
265  8.7500904157574988e-01,
266  8.8180857973018778e-01,
267  8.8832950132536048e-01,
268  8.9458561985407270e-01,
269  9.0058934202452501e-01,
270  9.0635185522359862e-01,
271  9.1188328358368542e-01,
272  9.1719281884962522e-01,
273  9.2228883084414315e-01,
274  9.2717896128406174e-01,
275  9.3187020390824138e-01,
276  9.3636897327349211e-01,
277  9.4068116410822089e-01,
278  9.4481220275054434e-01,
279  9.4876709191272646e-01,
280  9.5255044978855030e-01,
281  9.5616654434080584e-01,
282  9.5961932346219414e-01,
283  9.6291244158680500e-01,
284  9.6604928323501238e-01,
285  9.6903298389759329e-01,
286  9.7186644860160443e-01,
287  9.7455236844831017e-01,
288  9.7709323537010095e-01,
289  9.7949135531719400e-01,
290  9.8174886005462259e-01,
291  9.8386771772452075e-01,
292  9.8584974230717071e-01,
293  9.8769660209596644e-01,
294  9.8940982728584237e-01,
295  9.9099081676133638e-01,
296  9.9244084415894052e-01,
297  9.9376106326843472e-01,
298  9.9495251282924091e-01,
299  9.9601612077026702e-01,
300  9.9695270793505886e-01,
301  9.9776299132819335e-01,
302  9.9844758691360291e-01,
303  9.9900701199080966e-01,
304  9.9944168717078252e-01,
305  9.9975193796922790e-01,
306  9.9993799603150757e-01,
307  1.0000000000000000e+00
308  };
309 
310  // setup Function
311  this->setAttributeValue(TT("function"), TT("easeInOutCircular"));
312 
313 
314  // create 1 channel audio signal objects
315  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
316  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
317  input->allocWithVectorSize(N);
318  output->allocWithVectorSize(N);
319 
320  // create a signal to be transformed and then process it)
321  input->clear();
322  for (int i=0; i<N; i++)
323  input->mSampleVectors[0][i] = inputSignal1[i];
324 
325  this->process(input, output);
326 
327  // now test the output
328  for (int n=0; n<N; n++)
329  {
330  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedSignal1[n]);
331  badSampleCount += result;
332  if (result)
333  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedSignal1[n]);
334  }
335 
336  TTTestAssertion("Produces correct function values",
337  badSampleCount == 0,
338  testAssertionCount,
339  errorCount);
340  if (badSampleCount)
341  TTTestLog("badSampleCount is %i", badSampleCount);
342 
343 
344  TTObjectBaseRelease(&input);
345  TTObjectBaseRelease(&output);
346 
347  // wrap up test results and pass back to whoever called test
348  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
349 
350 }
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.
TTCircularEaseInOutFunction Unit for Jamoms DSP
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
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