Jamoma API  0.6.0.a19
TTGaussWindow.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Unit test for the Gauss Window Function Unit for Jamoma DSP
6  *
7  * @details
8  *
9  * @authors Nathan Wolek, Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2011 by Nathan Wolek @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 #include "TTWindowFunction.h"
17 #include "TTGaussWindow.h"
18 
19 
20 /*
21  * coefficients calculated using Octave using these variables and commands:
22  * N = 128
23  * k = 0:N-1
24  * sigma = 0.4
25  * y = exp(-0.5*( (k-(N-1)/2)/(sigma*(N-1)/2) ).^2);
26  */
27 static TTFloat64 sGaussWindowCoefficients128[128] = {
28  0.04393693362340742, 0.04844385382644425, 0.05333035421212484, 0.05861882293983547,
29  0.06433192710868552, 0.07049249318362928, 0.07712337438092012, 0.0842473050332327,
30  0.09188674210444778, 0.100063694185871, 0.1087995384783336, 0.1181148264467149,
31  0.1280290790231343, 0.1385605724303148, 0.1497261158950781, 0.161540822720985,
32  0.1740178763859497, 0.187168293522201, 0.2010006858190279, 0.2155210230600156,
33  0.2307323996625531, 0.2466348072248616, 0.2632249157012795, 0.2804958659167827,
34  0.2984370761936094, 0.3170340658935324, 0.3362682986762221, 0.3561170482350605,
35  0.3765532891949464, 0.397545615740786, 0.4190581903897632, 0.4410507251249852,
36  0.4634784968731615, 0.486292399035766, 0.5094390304734198, 0.5328608229995226,
37  0.5564962080645988, 0.5802798229111972, 0.6041427560549315, 0.6280128315053217,
38  0.6518149306860175, 0.6754713505536563, 0.6989021959543232, 0.7220258038028613,
39  0.744759196229827, 0.7670185594204288, 0.7887197444759794, 0.8097787862677291,
40  0.8301124359315742, 0.8496387023758121, 0.8682773979480479, 0.8859506832361098,
41  0.9025836058652441, 0.9181046281029399, 0.9324461380955926, 0.9455449396390315,
42  0.9573427155278681, 0.9677864597358519, 0.9768288739490784, 0.9844287243031341,
43  0.9905511545602596, 0.9951679523986283, 0.9982577659672924, 0.9998062683808934,
44  0.9998062683808934, 0.9982577659672924, 0.9951679523986283, 0.9905511545602596,
45  0.9844287243031341, 0.9768288739490784, 0.9677864597358519, 0.9573427155278681,
46  0.9455449396390315, 0.9324461380955926, 0.9181046281029399, 0.9025836058652441,
47  0.8859506832361098, 0.8682773979480479, 0.8496387023758121, 0.8301124359315742,
48  0.8097787862677291, 0.7887197444759794, 0.7670185594204288, 0.744759196229827,
49  0.7220258038028613, 0.6989021959543232, 0.6754713505536563, 0.6518149306860175,
50  0.6280128315053217, 0.6041427560549315, 0.5802798229111972, 0.5564962080645988,
51  0.5328608229995226, 0.5094390304734198, 0.486292399035766, 0.4634784968731615,
52  0.4410507251249852, 0.4190581903897632, 0.397545615740786, 0.3765532891949464,
53  0.3561170482350605, 0.3362682986762221, 0.3170340658935324, 0.2984370761936094,
54  0.2804958659167827, 0.2632249157012795, 0.2466348072248616, 0.2307323996625531,
55  0.2155210230600156, 0.2010006858190279, 0.187168293522201, 0.1740178763859497,
56  0.161540822720985, 0.1497261158950781, 0.1385605724303148, 0.1280290790231343,
57  0.1181148264467149, 0.1087995384783336, 0.100063694185871, 0.09188674210444778,
58  0.0842473050332327, 0.07712337438092012, 0.07049249318362928, 0.06433192710868552,
59  0.05861882293983547, 0.05333035421212484, 0.04844385382644425, 0.04393693362340742
60 };
61 
62 TTErr GaussWindow::test(TTValue& returnedTestInfo)
63 {
64  int errorCount = 0;
65  int testAssertionCount = 0;
66  int badSampleCount = 0;
67  TTAudioObjectBasePtr windowObject = NULL;
68  TTAudioSignalPtr input = NULL;
69  TTAudioSignalPtr output = NULL;
70  int N = 128;
71  TTValue v;
72  TTFloat64 testSigma = 0.4;
73 
74  // setup windowObject
75  TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1));
76  windowObject->setAttributeValue(TT("function"), TT("gauss"));
77  windowObject->setAttributeValue(TT("mode"), TT("apply"));
78 
79  // set the value for sigma
80  windowObject->setAttributeValue(TT("sigma"), testSigma);
81  TTTestLog("sigma was set to %.10f for test", testSigma);
82 
83  // create 1 channel audio signal objects
84  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
85  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
86  input->allocWithVectorSize(N);
87  output->allocWithVectorSize(N);
88 
89  // create a signal to be transformed and then process it)
90  input->fill(1.0);
91  windowObject->process(input, output);
92 
93  // now test the output
94  for (int n=0; n<N; n++)
95  {
96  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sGaussWindowCoefficients128[n]);
97  badSampleCount += result;
98  if (result)
99  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sGaussWindowCoefficients128[n]);
100  }
101 
102  TTTestAssertion("Produces correct window coefficients",
103  badSampleCount == 0,
104  testAssertionCount,
105  errorCount);
106  if (badSampleCount)
107  TTTestLog("badSampleCount is %i", badSampleCount);
108 
109 
110  TTObjectBaseRelease(&input);
111  TTObjectBaseRelease(&output);
112  TTObjectBaseRelease(&windowObject);
113 
114 
115  // wrap up test results and pass back to whoever called test
116  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
117 
118 }
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...
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
Gauss Window Function Unit for Jamoma DSP.
#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 test(TTValue &returnedTestInfo)
Unit test for the window function unit.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
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