Jamoma API  0.6.0.a19
TTTukeyWindow.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Tukey Window Function Unit for Jamoma DSP
6  *
7  * @details This implements the Tukey window function described here: @n
8 
9  * http://en.wikipedia.org/wiki/File:Window_function_(Tukey;_alpha_%3D_0.5).png @n
10  * This is alternate implementation of what Roads (1996 p 170, 2001 p 88) typically refers to as a quasi-Gaussian window.
11  * It is easier to ensure that x and y values will scale properly with this formula as opposed to the one given by Roads. @n
12  * @n
13  * Where 0. <= x <= 1. and 0. <= mAlpha <= 1.: @n
14  * y = 0.5 * (1 + cos ( pi * ((twoOverAlpha * x) - 1))) : for the attack @n
15  * = 1 : for the sustain @n
16  * = 0.5 * (1 + cos ( pi * ((twoOverAlpha * x) - twoOverAlpha + 1))) : for the release @n
17  *
18  * @authors Nathan Wolek, Tim Place, Trond Lossius
19  *
20  * @copyright Copyright © 2011 by Nathan Wolek @n
21  * This code is licensed under the terms of the "New BSD License" @n
22  * http://creativecommons.org/licenses/BSD/
23  */
24 
25 #include "TTTukeyWindow.h"
26 
27 #define thisTTClass TukeyWindow
28 #define thisTTClassName "tukey"
29 #define thisTTClassTags "dspWindowFunctionLib, audio, processor, function, window"
30 
31 
32 TT_AUDIO_CONSTRUCTOR
33 {
34  // Register Attributes...
35  addAttribute(Alpha, kTypeFloat64);
36  addAttributeProperty(Alpha, range, TTValue(kTTEpsilon, 1.0)); // Avoid dividing by 0
37  addAttributeProperty(Alpha, rangeChecking, TT("clip"));
38 
39  // Set Defaults:
40  setAttributeValue(TT("alpha"), 0.5);
41 
42  setProcessMethod(processAudio);
43  setCalculateMethod(calculateValue);
44 }
45 
46 
47 TukeyWindow::~TukeyWindow()
48 {
49  ;
50 }
51 
52 
54 {
55  TTFloat64 twoOverAlpha = 2. / mAlpha;
56  TTFloat64 alphaOverTwo = mAlpha / 2.;
57 
58  if ( x < alphaOverTwo ) { // attack portion
59 
60  y = 0.5 * (1 + cos( kTTPi * ((twoOverAlpha * x) - 1)));
61 
62  } else if ( x > ( 1 - alphaOverTwo) ) { // release portion
63 
64  y = 0.5 * (1 + cos( kTTPi * ((twoOverAlpha * x) - twoOverAlpha + 1)));
65 
66  } else { // sustain portion
67 
68  y = 1.;
69 
70  }
71 
72  TTLimit(y, 0.0, 1.0 ); // just in case
73 
74  return kTTErrNone;
75 }
76 
77 
79 {
80  TT_WRAP_CALCULATE_METHOD(calculateValue);
81 }
82 
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
#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
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
64-bit floating point
Definition: TTBase.h:272
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
TTFloat64 mAlpha
ratio of window fades to total window duration. 0 <= alpha <= 1., 0 = no fades, 1 = no sustain ...
Definition: TTTukeyWindow.h:47
A simple container for an array of TTAudioSignal pointers.
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
No Error.
Definition: TTBase.h:343
Tukey Window Function Unit for Jamoma DSP.
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
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 calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
Calculate y = f(x) for a single value.