Jamoma API  0.6.0.a19
TTHammingWindow.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Unit test for the Hamming Window Function Unit
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2011, Tim Place @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"
18 #include "TTHammingWindow.h"
19 
20 
21 // coefficients calculated in Octave using these commands:
22 // n = 0.0:1/127:1.0;
23 // y = 0.54 + 0.46 * cos(2*pi*(n-0.5));
24 static TTFloat64 sHammingWindowCoefficients128[128] = {
25  0.0800000000000000, 0.0805628485414398, 0.0822500167810610, 0.0850573759354599, 0.0889780559263524, 0.0940024621928066, 0.100118299170741, 0.107310600382232,
26  0.115561765060989, 0.124851601224384, 0.135157375086613, 0.146453866692083, 0.158713431632864, 0.171906068699192, 0.185999493297458, 0.200959216456013,
27  0.216748629225465, 0.233329092266912, 0.250660030408878, 0.268699031941561, 0.287401952405387, 0.306723022619904, 0.326614960688639, 0.347029087705815,
28  0.367915446881795, 0.389222925795719, 0.410899381476157, 0.432891768003705, 0.455146266323232, 0.477608415948132, 0.500223248234257, 0.522935420897402,
29  0.545689353445147, 0.568429363191639, 0.591099801522450, 0.613645190076067, 0.636010356508734, 0.658140569510427, 0.679981672741539, 0.701480217362516,
30  0.722583592832128, 0.743240155654278, 0.763399355758289, 0.783011860203399, 0.802029673904734, 0.820406257085326, 0.838096639166739, 0.855057528819616,
31  0.871247419904816, 0.886626693045890, 0.901157712584333, 0.914804918680351, 0.927534914333745, 0.939316547111965, 0.950120985385339, 0.959921788882895,
32  0.968694973396140, 0.976419069472435, 0.983075174954342, 0.988647001236375, 0.993120913125941, 0.996485962210947, 0.998733913652397, 0.999859266336418,
33  0.999859266336418, 0.998733913652397, 0.996485962210947, 0.993120913125941, 0.988647001236375, 0.983075174954342, 0.976419069472435, 0.968694973396140,
34  0.959921788882895, 0.950120985385339, 0.939316547111965, 0.927534914333744, 0.914804918680351, 0.901157712584333, 0.886626693045890, 0.871247419904816,
35  0.855057528819616, 0.838096639166739, 0.820406257085326, 0.802029673904735, 0.783011860203399, 0.763399355758289, 0.743240155654278, 0.722583592832128,
36  0.701480217362516, 0.679981672741539, 0.658140569510427, 0.636010356508734, 0.613645190076067, 0.591099801522450, 0.568429363191639, 0.545689353445147,
37  0.522935420897402, 0.500223248234257, 0.477608415948132, 0.455146266323232, 0.432891768003705, 0.410899381476157, 0.389222925795719, 0.367915446881795,
38  0.347029087705815, 0.326614960688639, 0.306723022619904, 0.287401952405387, 0.268699031941561, 0.250660030408878, 0.233329092266912, 0.216748629225465,
39  0.200959216456013, 0.185999493297458, 0.171906068699192, 0.158713431632864, 0.146453866692083, 0.135157375086613, 0.124851601224384, 0.115561765060989,
40  0.107310600382232, 0.100118299170741, 0.0940024621928066, 0.0889780559263524, 0.0850573759354599, 0.0822500167810610, 0.0805628485414398, 0.0800000000000000
41 };
42 
43 
44 TTErr HammingWindow::test(TTValue& returnedTestInfo)
45 {
46  int errorCount = 0;
47  int testAssertionCount = 0;
48  int badSampleCount = 0;
49  TTAudioObjectBasePtr windowObject = NULL;
50  TTAudioSignalPtr input = NULL;
51  TTAudioSignalPtr output = NULL;
52  int N = 128;
53  TTValue v;
54 
55  TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1));
56  windowObject->setAttributeValue(TT("function"), TT("hamming"));
57  windowObject->setAttributeValue(TT("mode"), TT("apply"));
58 
59  // create 1 channel audio signal objects
60  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
61  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
62  input->allocWithVectorSize(N);
63  output->allocWithVectorSize(N);
64 
65  // create a signal to be transformed, and then process it
66  input->fill(1.0);
67  windowObject->process(input, output);
68 
69  // now test the output
70  for (int n=0; n<N; n++) {
71  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sHammingWindowCoefficients128[n]);
72  badSampleCount += result;
73  if (result)
74  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sHammingWindowCoefficients128[n]);
75  }
76 
77  TTTestAssertion("Produces correct window coefficients",
78  badSampleCount == 0,
79  testAssertionCount,
80  errorCount);
81  if (badSampleCount)
82  TTTestLog("badSampleCount is %i", badSampleCount);
83 
84 
85 
86 
87  TTObjectBaseRelease(&input);
88  TTObjectBaseRelease(&output);
89  TTObjectBaseRelease(&windowObject);
90 
91  // Wrap up the test results to pass back to whoever called this test
92  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
93 }
94 
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
#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.
virtual 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
Hamming 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...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34