Jamoma API  0.6.0.a19
TTKaiserWindow.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Kaiser Window Function Unit for Jamoma DSP
6  *
7  * @details This implements a window function as described @n
8  https://ccrma.stanford.edu/~jos/sasp/Kaiser_Window.html @n
9  http://en.wikipedia.org/wiki/Window_function#Kaiser_windows
10  *
11  * @authors Nils Peters, Trond Lossius, Tim Place, Nathan Wolek
12  *
13  * @copyright Copyright © 2010 by Timothy Place @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 #include "TTKaiserWindow.h"
19 
20 
21 #define thisTTClass KaiserWindow
22 #define thisTTClassName "kaiser"
23 #define thisTTClassTags "dspWindowFunctionLib, audio, processor, function, window"
24 
25 
26 TT_AUDIO_CONSTRUCTOR
27 {
30 
31  setAttributeValue(TT("beta"), 6.0);
32 
33  setProcessMethod(processAudio);
34  setCalculateMethod(calculateValue);
35 }
36 
37 
38 KaiserWindow::~KaiserWindow()
39 {
40  ;
41 }
42 
43 
45 {
46  double y = 1.0;
47  double u = 1.0;
48  double halfx = x * 0.5;
49  double temp;
50  long i = 1;
51 
52  while (u > kTTEpsilon) {
53  temp = halfx/(double)i;
54  temp *= temp;
55  u *= temp;
56  y += u;
57  i++;
58  }
59  return y;
60 }
61 
62 
64 {
65  mAlpha = newValue;
66  mBeta = mAlpha * kTTPi;
68  // the following 3 lines can be used for testing; comment out when not in use
69  //TTLogMessage("alpha: %f\n", mAlpha);
70  //TTLogMessage("beta: %f\n", mBeta);
71  //TTLogMessage("besselOfBeta: %f\n", mBesselIOofBeta);
72  return kTTErrNone;
73 }
74 
76 {
77  mBeta = newValue;
78  mAlpha = mBeta / kTTPi;
80  // the following 3 lines can be used for testing; comment out when not in use
81  //TTLogMessage("alpha: %f\n", mAlpha);
82  //TTLogMessage("beta: %f\n", mBeta);
83  //TTLogMessage("besselOfBeta: %f\n", mBesselIOofBeta);
84  return kTTErrNone;
85 }
86 
88 {
89  // rewritten on 26 April 2011 by Nathan Wolek
90 
91  TTFloat64 two_x_minusone = 2.0 * x - 1;
92  TTFloat64 temp = 1.0 - (two_x_minusone * two_x_minusone);
93  TTFloat64 temp2 = sqrt(temp);
94  TTFloat64 temp3 = mBeta * temp2;
95  TTFloat64 temp4 = BesselFunctionI0(temp3);
96 
97  y = temp4 / mBesselIOofBeta;
98  return kTTErrNone;
99 }
100 
101 
103 {
104  TT_WRAP_CALCULATE_METHOD(calculateValue);
105 }
106 
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
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
TTFloat64 mAlpha
alpha and beta atributes are linked to allow congruence with both references above.
TTErr setBeta(const TTValue &newValue)
Set the beta attribute of the Kaiser window function.
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
Kaiser Window Function Unit for Jamoma DSP.
TTFloat64 BesselFunctionI0(TTFloat64 x)
internal use: calculate zeroth-order bessel function of the first kind
64-bit floating point
Definition: TTBase.h:272
TTFloat64 mBeta
attribute: beta parameter for the Kaiser function
TTFloat64 mBesselIOofBeta
calculated from the beta attribute
A simple container for an array of TTAudioSignal pointers.
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
Calculate y = f(x) for a single value.
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
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
TTErr setAlpha(const TTValue &newValue)
Set the alpha attribute of the Kaiser window function.
TTFOUNDATION_EXPORT const TTFloat64 kTTEpsilon
A very very small value, used for float equality comaprisments.
Definition: TTBase.cpp:31
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.