Jamoma API  0.6.0.a19
TTKaiserWindow.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Unot tests for the Kaiser Window Function Unit
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
14  */
15
16
17 #include "TTWindowFunction.h"
18 #include "TTKaiserWindow.h"
19
20
21 /* Reference window table of 128 points, adapted from the Matlab code for the Wikipedia article at:
22  http://commons.wikimedia.org/wiki/File:Window_function_(Kaiser;_alpha_%3D_3_pi).png
23
24  N=128;
25  k=0:N-1;
26  beta = 3 * pi;
27  w = besseli(0, beta * sqrt(1 - (2*k / (N-1) -1 ).^2) ) / besseli(0, beta);
28
29  The use of alpha and beta is inconsistent among sources for many references on this formula.
30  Most often, beta = alpha * pi, and so in this case the adjustment has been made to the original formula.
31  */
32 static TTFloat64 sKaiserB3PiWindowCoefficients128[128] = {
33  0.000612335927796156, 0.00111689329607919, 0.00179402708978792, 0.00267595621116774, 0.00379777893185251, 0.00519739541418763, 0.00691538620877882, 0.00899484496799450,
34  0.0114811641628067, 0.0144217731860963, 0.0178658288623726, 0.0218638590538193, 0.0264673607469130, 0.0317283547130500, 0.0376988995505867, 0.0444305686238845,
35  0.0519738941065314, 0.0603777829998968, 0.0696889106236525, 0.0799510976511257, 0.0912046772790296, 0.103485859568466, 0.116826100363096, 0.131251482472908,
36  0.146782117000954, 0.163431572779949, 0.181206341871096, 0.200105348955726, 0.220119512219747, 0.241231362991256, 0.263414730944525, 0.286634501132081,
37  0.310846448455336, 0.335997154439626, 0.362024010349221, 0.388855309771215, 0.416410432824564, 0.444600123123790, 0.473326857558506, 0.502485307853777,
38  0.531962891766401, 0.561640410663399, 0.591392769136173, 0.621089771241996, 0.650596986948547, 0.679776681401526, 0.708488798753721, 0.736591991499331,
39  0.763944685561660, 0.790406170796288, 0.815837706104752, 0.840103628013463, 0.863072451365011, 0.884617950698585, 0.904620210965353, 0.922966636433854,
40  0.939552906988288, 0.954283871505835, 0.967074368612417, 0.977849965852688, 0.986547609160636, 0.993116175471601, 0.997516922362848, 0.999723829734840,
41  0.999723829734840, 0.997516922362848, 0.993116175471601, 0.986547609160636, 0.977849965852688, 0.967074368612417, 0.954283871505835, 0.939552906988288,
42  0.922966636433854, 0.904620210965353, 0.884617950698585, 0.863072451365011, 0.840103628013463, 0.815837706104752, 0.790406170796288, 0.763944685561660,
43  0.736591991499331, 0.708488798753721, 0.679776681401526, 0.650596986948547, 0.621089771241995, 0.591392769136173, 0.561640410663399, 0.531962891766401,
44  0.502485307853777, 0.473326857558506, 0.444600123123790, 0.416410432824565, 0.388855309771215, 0.362024010349221, 0.335997154439626, 0.310846448455336,
45  0.286634501132081, 0.263414730944525, 0.241231362991256, 0.220119512219747, 0.200105348955725, 0.181206341871096, 0.163431572779949, 0.146782117000954,
46  0.131251482472908, 0.116826100363096, 0.103485859568466, 0.0912046772790296, 0.0799510976511256, 0.0696889106236525, 0.0603777829998968, 0.0519738941065314,
47  0.0444305686238845, 0.0376988995505867, 0.0317283547130501, 0.0264673607469130, 0.0218638590538193, 0.0178658288623726, 0.0144217731860963, 0.0114811641628067,
48  0.00899484496799450, 0.00691538620877882, 0.00519739541418765, 0.00379777893185252, 0.00267595621116773, 0.00179402708978792, 0.00111689329607919, 0.000612335927796156
49 };
50
51
52 TTErr KaiserWindow::test(TTValue& returnedTestInfo)
53 {
54  int errorCount = 0;
55  int testAssertionCount = 0;
57  TTAudioObjectBasePtr windowObject = NULL;
58  TTAudioSignalPtr input = NULL;
59  TTAudioSignalPtr output = NULL;
60  int N = 128;
62
63  // create the object and set the beta parameter
64  TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1));
65  windowObject->setAttributeValue(TT("function"), TT("kaiser"));
66  windowObject->setAttributeValue(TT("mode"), TT("apply"));
67
68  v.resize(2);
69  v[0] = TT("beta");
70  v[1] = 6.0;
72
73  TTTestAssertion("Internal intermediate value 1 (zeroth-order bessel fn of the first kind, taken of beta = 6.0) is correct.",
74  TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 67.2344069764780),
75  testAssertionCount,
76  errorCount);
77
78  // change the alpha parameter and test Bessel function again
79  v.resize(2);
80  v[0] = TT("alpha");
81  v[1] = 2.0;
83
84  TTTestAssertion("Internal intermediate value 2 (zeroth-order bessel fn of the first kind, taken of alpha = 2) is correct.",
85  TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 87.10851065339077),
86  testAssertionCount,
87  errorCount); // added 4/26 by Wolek
88
89  // change the beta parameter and try applying the window
90  v.resize(2);
91  v[0] = TT("beta");
92  v[1] = 3.0 * kTTPi;
94
95  TTTestAssertion("Internal intermediate value 2 (zeroth-order bessel fn of the first kind, taken of beta = 3 * pi) is correct.",
96  TTTestFloatEquivalence(((KaiserWindow*)((WindowFunction*)windowObject)->mFunctionObject)->mBesselIOofBeta, 1633.090522058824),
97  testAssertionCount,
98  errorCount); // added 4/26 by Wolek
99
100  // create 1 channel audio signal objects
101  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
102  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
103  input->allocWithVectorSize(N);
104  output->allocWithVectorSize(N);
105
106  // create a signal to be transformed, and then process it
107  input->fill(1.0);
108  windowObject->process(input, output);
109
110  // now test the output
111  for (int n=0; n<N; n++) {
112  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sKaiserB3PiWindowCoefficients128[n]);
114  if (result)
115  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sKaiserB3PiWindowCoefficients128[n]);
116  }
117
118  TTTestAssertion("Produces correct window shape for beta = 3 pi",
120  testAssertionCount,
121  errorCount);
124
125
126  TTObjectBaseRelease(&input);
127  TTObjectBaseRelease(&output);
128  TTObjectBaseRelease(&windowObject);
129
130  // Wrap up the test results to pass back to whoever called this test
131  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
132 }
133
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
This implements a window function as described @ https://ccrma.stanford.edu/~jos/sasp/Kaiser_Window.html http://en.wikipedia.org/wiki/Window_function#Kaiser_windows.
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
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
Kaiser Window Function Unit for Jamoma DSP.
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.
virtual TTErr test(TTValue &returnedTestInfo)
Unit test for the window function unit.
TTFloat64 mBesselIOofBeta
calculated from the beta attribute
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Generalized Window Function Wrapper.
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
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