Jamoma API  0.6.0.a19
TTRectangularWindow.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Unit test for the Rectangular Window Function Unit
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2012, Timothy 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 "TTRectangularWindow.h"
19 
20 
21 /*
22  coefficients calculated using Octave using these variables and commands:
23 
24  octave-3.2.3:2> L = 128;
25  octave-3.2.3:2> w = ones(L,1);
26 
27 */
28 static TTFloat64 sRectangularWindowCoefficients128[128];
29 
30 
32 {
33  int L = 128;
34  for (int l=0; l<L; l++)
35  sRectangularWindowCoefficients128[l] = 1.0;
36 
37  int errorCount = 0;
38  int testAssertionCount = 0;
39  int badSampleCount = 0;
40  TTAudioObjectBasePtr windowObject = NULL;
41  TTAudioSignalPtr input = NULL;
42  TTAudioSignalPtr output = NULL;
43  int N = 128;
44  TTValue v;
45 
46  // setup windowObject
47  TTObjectBaseInstantiate(TT("WindowFunction"), &windowObject, TTValue(1));
48  windowObject->setAttributeValue(TT("function"), TT("rectangular"));
49  windowObject->setAttributeValue(TT("mode"), TT("apply"));
50 
51  // create 1 channel audio signal objects
52  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 1);
53  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 1);
54  input->allocWithVectorSize(N);
55  output->allocWithVectorSize(N);
56 
57  // create a signal to be transformed and then process it)
58  input->fill(1.0);
59  windowObject->process(input, output);
60 
61  // now test the output
62  for (int n=0; n<N; n++)
63  {
64  TTBoolean result = !TTTestFloatEquivalence(output->mSampleVectors[0][n], sRectangularWindowCoefficients128[n]);
65  badSampleCount += result;
66  if (result)
67  TTTestLog("BAD SAMPLE @ n=%i ( value=%.10f expected=%.10f )", n, output->mSampleVectors[0][n], sRectangularWindowCoefficients128[n]);
68  }
69 
70  TTTestAssertion("Produces correct window coefficients",
71  badSampleCount == 0,
72  testAssertionCount,
73  errorCount);
74  if (badSampleCount)
75  TTTestLog("badSampleCount is %i", badSampleCount);
76 
77 
78  TTObjectBaseRelease(&input);
79  TTObjectBaseRelease(&output);
80  TTObjectBaseRelease(&windowObject);
81 
82 
83  // wrap up test results and pass back to whoever called test
84  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
85 
86 }
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.
Rectangular Window Function Unit for Jamomoma DSP.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr test(TTValue &returnedTestInfo)
Unit test for the window function unit.
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