Jamoma API  0.6.0.a19
TTRosenbergGlottalPulseWindow.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Unit tests for the Rosenberg Glottal Pulse Window Function Unit
6  *
7  * @details
8  *
9  * @authors Trond Lossius
10  *
11  * @copyright Copyright © 2013 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 "TTWindowFunction.h"
19 
20 
21 /* The first 61 samples of the below is calculated in Octave as:
22 
23  x = linspace(0, 1., 61);
24  y = 0.5 * ( 1.0 - cos(pi*x) );
25  printf("%.16e,\n", y);
26 
27 
28  Next 41 samples are calculated in Octave as:
29 
30  x = linspace(0, 1., 41);
31  y = cos(0.5*pi*x);
32  printf("%.16e,\n", y);
33 
34  The first of these samples is ignored, and the remaining 40 samples are appended to the previous vector of 61 sample values.
35 
36  */
37 static TTFloat64 expectedResult1[101] = {
38  0.0000000000000000e+00, 6.8523262271308338e-04, 2.7390523158633551e-03, 6.1558297024311148e-03, 1.0926199633097156e-02, 1.7037086855465844e-02, 2.4471741852423234e-02, 3.3209786751399129e-02, 4.3227271178699567e-02, 5.4496737905816106e-02, 6.6987298107780702e-02, 8.0664716027287975e-02, 9.5491502812526274e-02, 1.1142701927151460e-01, 1.2842758726130293e-01, 1.4644660940672621e-01, 1.6543469682057088e-01, 1.8533980447508130e-01, 2.0610737385376343e-01, 2.2768048249248640e-01, 2.5000000000000000e-01, 2.7300475013022663e-01, 2.9663167846209992e-01, 3.2081602522734992e-01, 3.4549150281252627e-01, 3.7059047744873963e-01, 3.9604415459112041e-01, 4.2178276747988463e-01, 4.4773576836617340e-01, 4.7383202187852802e-01, 4.9999999999999994e-01, 5.2616797812147187e-01, 5.5226423163382676e-01, 5.7821723252011548e-01, 6.0395584540887981e-01, 6.2940952255126037e-01, 6.5450849718747373e-01, 6.7918397477265025e-01, 7.0336832153790008e-01, 7.2699524986977337e-01, 7.5000000000000000e-01, 7.7231951750751349e-01, 7.9389262614623646e-01, 8.1466019552491864e-01, 8.3456530317942912e-01, 8.5355339059327373e-01, 8.7157241273869723e-01, 8.8857298072848545e-01, 9.0450849718747373e-01, 9.1933528397271203e-01, 9.3301270189221941e-01, 9.4550326209418389e-01, 9.5677272882130049e-01, 9.6679021324860082e-01, 9.7552825814757682e-01, 9.8296291314453410e-01, 9.8907380036690284e-01, 9.9384417029756889e-01, 9.9726094768413664e-01, 9.9931476737728686e-01, 1.0000000000000000e+00, 9.9922903624072290e-01, 9.9691733373312796e-01, 9.9306845695492629e-01, 9.8768834059513777e-01, 9.8078528040323043e-01, 9.7236992039767656e-01, 9.6245523645364728e-01, 9.5105651629515353e-01, 9.3819133592248416e-01, 9.2387953251128674e-01, 9.0814317382508125e-01, 8.9100652418836779e-01, 8.7249600707279718e-01, 8.5264016435409229e-01, 8.3146961230254524e-01, 8.0901699437494745e-01, 7.8531693088074483e-01, 7.6040596560003104e-01, 7.3432250943568556e-01, 7.0710678118654757e-01, 6.7880074553294178e-01, 6.4944804833018366e-01, 6.1909394930983397e-01, 5.8778525229247314e-01, 5.5557023301960229e-01, 5.2249856471594891e-01, 4.8862124149695502e-01, 4.5399049973954680e-01, 4.1865973753742791e-01, 3.8268343236508984e-01, 3.4611705707749302e-01, 3.0901699437494745e-01, 2.7144044986507432e-01, 2.3344536385590525e-01, 1.9509032201612830e-01, 1.5643446504023092e-01, 1.1753739745783770e-01, 7.8459095727844999e-02, 3.9259815759068450e-02, 6.1232339957367660e-17
39 };
40 
41 
42 /* Likewise the first 81 samples of the below is calculated in Octave as:
43 
44  x = linspace(0, 1., 81);
45  y = 0.5 * ( 1.0 - cos(pi*x) );
46  printf("%.16e,\n", y);
47 
48  The next 21 samples are calculated in Octave as:
49 
50  x = linspace(0, 1., 21);
51  y = cos(0.5*pi*x);
52  printf("%.16e,\n", y);
53 
54  The first of these samples is ignored, and the remaining 20 samples are appended to the previous vector of 81 sample values.
55 
56  */
57 static TTFloat64 expectedResult2[101] = {
58  0.0000000000000000e+00, 3.8548187963854952e-04, 1.5413331334360181e-03, 3.4657715225368535e-03, 6.1558297024311148e-03, 9.6073597983847847e-03, 1.3815039801161721e-02, 1.8772381773176361e-02, 2.4471741852423234e-02, 3.0904332038757920e-02, 3.8060233744356631e-02, 4.5928413087459374e-02, 5.4496737905816106e-02, 6.3751996463601412e-02, 7.3679917822953855e-02, 8.4265193848727382e-02, 9.5491502812526274e-02, 1.0734153455962758e-01, 1.1979701719998448e-01, 1.3283874528215722e-01, 1.4644660940672621e-01, 1.6059962723352911e-01, 1.7527597583490817e-01, 1.9045302534508302e-01, 2.0610737385376343e-01, 2.2221488349019886e-01, 2.3875071764202555e-01, 2.5568937925152246e-01, 2.7300475013022663e-01, 2.9067013123128604e-01, 3.0865828381745508e-01, 3.2694147146125352e-01, 3.4549150281252627e-01, 3.6427977506746284e-01, 3.8327731807204735e-01, 4.0245483899193585e-01, 4.2178276747988452e-01, 4.4123130127108112e-01, 4.6077045213607748e-01, 4.8037009212046577e-01, 4.9999999999999994e-01, 5.1962990787953434e-01, 5.3922954786392241e-01, 5.5876869872891877e-01, 5.7821723252011548e-01, 5.9754516100806410e-01, 6.1672268192795276e-01, 6.3572022493253710e-01, 6.5450849718747373e-01, 6.7305852853874659e-01, 6.9134171618254481e-01, 7.0932986876871418e-01, 7.2699524986977337e-01, 7.4431062074847754e-01, 7.6124928235797440e-01, 7.7778511650980098e-01, 7.9389262614623646e-01, 8.0954697465491710e-01, 8.2472402416509194e-01, 8.3940037276647095e-01, 8.5355339059327373e-01, 8.6716125471784278e-01, 8.8020298280001552e-01, 8.9265846544037253e-01, 9.0450849718747373e-01, 9.1573480615127267e-01, 9.2632008217704609e-01, 9.3624800353639859e-01, 9.4550326209418400e-01, 9.5407158691254068e-01, 9.6193976625564337e-01, 9.6909566796124214e-01, 9.7552825814757682e-01, 9.8122761822682358e-01, 9.8618496019883828e-01, 9.9039264020161522e-01, 9.9384417029756889e-01, 9.9653422847746320e-01, 9.9845866686656404e-01, 9.9961451812036151e-01, 1.0000000000000000e+00, 9.9691733373312796e-01, 9.8768834059513777e-01, 9.7236992039767656e-01, 9.5105651629515353e-01, 9.2387953251128674e-01, 8.9100652418836779e-01, 8.5264016435409229e-01, 8.0901699437494745e-01, 7.6040596560003104e-01, 7.0710678118654757e-01, 6.4944804833018366e-01, 5.8778525229247314e-01, 5.2249856471594891e-01, 4.5399049973954680e-01, 3.8268343236508984e-01, 3.0901699437494745e-01, 2.3344536385590525e-01, 1.5643446504023092e-01, 7.8459095727844999e-02, 6.1232339957367660e-17
59 };
60 
61 
63 {
64  int errorCount = 0;
65  int testAssertionCount = 0;
66 
67  TTAudioObjectBasePtr windowObject = NULL;
68 
69  TTAudioSignalPtr input = NULL;
70  TTAudioSignalPtr output = NULL;
71 
72  int N = 101;
73  TTValue v, aReturnWeDontCareAbout;
74 
75  // create the object, keep the default ratio parameter
76  TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1));
77  windowObject->setAttributeValue(TT("function"), TT("rosenbergGlottalPulse"));
78  windowObject->setAttributeValue(TT("mode"), TT("apply"));
79 
80  // create 1 channel audio signal objects
81  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
82  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
83  input->allocWithVectorSize(N);
84  output->allocWithVectorSize(N);
85 
86  // create a signal to be transformed, and then process it
87  input->fill(1.0);
88  windowObject->process(input, output);
89 
90  // now test the output
91  int badSampleCount = 0;
92  for (int n=0; n<N; n++) {
93  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedResult1[n]);
94  badSampleCount += result;
95  if (result)
96  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedResult1[n]);
97  }
98 
99  TTTestAssertion("Produces correct window shape for with default ratio attribute",
100  badSampleCount == 0,
101  testAssertionCount,
102  errorCount);
103  if (badSampleCount)
104  TTTestLog("badSampleCount is %i", badSampleCount);
105 
106  v.resize(2);
107  v[0] = TT("ratio");
108  v[1] = 0.8;
109  windowObject->sendMessage(TT("setParameter"), v, aReturnWeDontCareAbout);
110 
111  // Again create a signal to be transformed, and then process it
112  input->fill(1.0);
113  windowObject->process(input, output);
114 
115  // now test the output
116  badSampleCount = 0;
117  for (int n=0; n<N; n++) {
118  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], expectedResult2[n]);
119  badSampleCount += result;
120  if (result)
121  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], expectedResult2[n]);
122  }
123 
124  TTTestAssertion("Produces correct window shape for with ratio set to 0.8",
125  badSampleCount == 0,
126  testAssertionCount,
127  errorCount);
128  if (badSampleCount)
129  TTTestLog("badSampleCount is %i", badSampleCount);
130 
131 
132  TTObjectBaseRelease(&input);
133  TTObjectBaseRelease(&output);
134  TTObjectBaseRelease(&windowObject);
135 
136  // Wrap up the test results to pass back to whoever called this test
137  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
138 }
139 
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
virtual TTErr test(TTValue &returnedTestInfo)
Unit test for the window function unit.
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
Generalized Window Function Wrapper for Jamoma DSP.
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 process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Rosenberg Glottal Pulse Window Function Unit for Jamoma DSP.
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34