Jamoma API  0.6.0.a19
TTWindowFunction.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Generalized Window Function Wrapper for Jamoma DSP
6  *
7  * @details More information on window functions can be found here: @n
8  * @n
9  * http://en.wikipedia.org/wiki/Window_function @n
10  * https://ccrma.stanford.edu/~jos/sasp/Spectrum_Analysis_Windows.html
11  *
12  * @authors Tim Place, Nathan Wolek, Trond Lossius,
13  *
14  * @copyright Copyright © 2010 by Timothy Place @n
15  * This code is licensed under the terms of the "New BSD License" @n
16  * http://creativecommons.org/licenses/BSD/
17  */
18 
19 #ifndef __WINDOWFUNCTION_H__
20 #define __WINDOWFUNCTION_H__
21 
22 #include "TTDSP.h"
23 
24 
25 /** Generalized Window Function Wrapper
26  */
29 
30  friend class KaiserWindow; // need this for the unit testing - NW: should protected be before this?
31 
32 protected:
33 
34  TTSymbol mFunction; ///< Name of the window function to use
35  TTAudioObjectBasePtr mFunctionObject; ///< The actual window function object for mFunction
36  TTUInt32 mNumPoints; ///< Number of Points in the lookup table
37  TTSampleVector mLookupTable; ///< Cached table of size mNumPoints
38  TTSymbol mMode; ///< Options: 'generate', 'lookup', 'apply'
39  TTUInt32 mPadding; ///< for generating the lookup table - (e.g. padded welch window padded by 16 zeros on both sides)
40  // further padding references: http://www.dsprelated.com/dspbooks/sasp/Sliding_FFT_Maximum_Overlap.html
41 
42  /** Choose the window function
43  @param function The window function to use.
44  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
45  */
46  TTErr setFunction(const TTValue& function);
47 
48 
49  /** @brief Set the lookup table size.
50  @details The setNumPoints and doSetNumPoints methods perform the same action, and differs only in the type of the argument to the method.
51  @param numPoints The number of points to use.
52  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
53  @see doSetNumPoints
54  */
55  TTErr setNumPoints(const TTValue& numPoints);
56 
57 
58  /** @brief Set the lookup table size.
59  @details The setNumPoints and doSetNumPoints methods perform the same action, and differs only in the type of the argument to the method.
60  @param numPoints The number of points to use.
61  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
62  @see setNumPoints
63  */
64  TTErr doSetNumPoints(const TTUInt32 numPoints);
65 
66 
67  /** Set the process method. The options are 'generate', 'lookup', 'apply'.
68  @param mode The processing mode to use. The options are 'generate', 'lookup', 'apply'.
69  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
70  */
71  TTErr setMode(const TTValue& mode);
72 
73 
74  /** Zero-padding applied to lookup table.
75  @param padding
76  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
77  */
78  TTErr setPadding(const TTValue& padding);
79 
80 
81  /** Internal method for filling the lookup table.
82  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
83  */
84  TTErr fill();
85 
86 
87  /** Return a list of all the available window functions.
88  @param listOfWindowTypesToReturn Pointer to an array that will be filled with a list of all available window functions.
89  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
90  */
91  TTErr getFunctions(const TTValue&, TTValue& listOfWindowTypesToReturn);
92 
93 
94  /** Set an attribute of the internal window object (e.g. the 'beta' parameter to the Kaiser function).
95  @param aParameterValueForTheFunction Some functions have one or more parameters that can be set and that will alter the curve of the function. These parameters can be set using this method.
96  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
97  */
98  TTErr setParameter(const TTValue& aParameterValueForTheFunction, TTValue&);
99 
100 
101  /** Calculate a single window function value y = f(x).
102  @param x The input value that we want to calculate a window function value for.
103  @param y The returned window function y value.
104  @param data Not currently used.
105  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
106  */
107  inline TTErr calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data);
108 
109 
110  /** Lookup a single function value y = f(x) from the stored table of window function values.
111  @param x The input value that we want to calculate a window function value for.
112  @param y The returned window function y value.
113  @param data Not currently used.
114  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
115  */
116  inline TTErr lookupValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data);
117 
118 
119  /** Generate a window function curve by means of calculations.
120  @param inputs The input signal vector.
121  @param outputs The resaulting window function.
122  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
123  */
125 
126 
127  /** Apply window function to the inputs signal using window function values from the stored lookup table.
128  @param inputs The input signal to apply a window function on.
129  @param outputs The resaulting windowed signal.
130  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
131  */
133 
134 
135  /** Apply window function to the inputs signal using window function values that are calculated on the fly.
136  @param inputs The input signal to apply a window function on.
137  @param outputs The resaulting windowed signal.
138  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
139  */
141 
142 };
143 
144 
145 #endif // __WINDOWFUNCTION_H__
TTUInt32 mPadding
for generating the lookup table - (e.g. padded welch window padded by 16 zeros on both sides) ...
TTErr getFunctions(const TTValue &, TTValue &listOfWindowTypesToReturn)
Return a list of all the available window functions.
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.
TTAudioObjectBasePtr mFunctionObject
The actual window function object for mFunction.
TTErr processApply(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Apply window function to the inputs signal using window function values that are calculated on the fl...
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTSymbol mFunction
Name of the window function to use.
TTErr processLookup(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Apply window function to the inputs signal using window function values from the stored lookup table...
Jamoma DSP Library.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr doSetNumPoints(const TTUInt32 numPoints)
Set the lookup table size.
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTSampleVector mLookupTable
Cached table of size mNumPoints.
std::vector< TTSampleValue > TTSampleVector
A TTSampleVector is simply a pointer to the first of an array of TTSampleValues.
Definition: TTBase.h:233
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr setNumPoints(const TTValue &numPoints)
Set the lookup table size.
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
Calculate a single window function value y = f(x).
TTErr setPadding(const TTValue &padding)
Zero-padding applied to lookup table.
TTErr setMode(const TTValue &mode)
Set the process method.
A simple container for an array of TTAudioSignal pointers.
TTSymbol mMode
Options: 'generate', 'lookup', 'apply'.
TTErr lookupValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
Lookup a single function value y = f(x) from the stored table of window function values.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTUInt32 mNumPoints
Number of Points in the lookup table.
Generalized Window Function Wrapper.
TTErr setParameter(const TTValue &aParameterValueForTheFunction, TTValue &)
Set an attribute of the internal window object (e.g.
TTErr fill()
Internal method for filling the lookup table.
TTErr setFunction(const TTValue &function)
Choose the window function.
TTErr processGenerate(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Generate a window function curve by means of calculations.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34