Jamoma API  0.6.0.a19
TTTrapezoidWindow.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspWindowFunctionLib
4  *
5  * @brief Trapezoid Window Function Unit for Jamoma DSP
6  *
7  * @details This implements a Trapezoid window using the following algorthim: @n
8  * @n
9  * Where 0. <= x <= 1. and 0. <= mAlpha <= 1.: @n
10  * y = x * twoOverAlpha : for the attack @n
11  * = 1 : for the sustain @n
12  * = (1 - x) * twoOverAlpha : for the release @n
13  *
14  * @authors Trond Lossius, Nathan Wolek, Tim Place, Nils Peters,
15  *
16  * @copyright Copyright © 2010 by Trond Lossius @n
17  * This code is licensed under the terms of the "New BSD License" @n
18  * http://creativecommons.org/licenses/BSD/
19  */
20 
21 #include "TTTrapezoidWindow.h"
22 
23 #define thisTTClass TrapezoidWindow
24 #define thisTTClassName "trapezoid"
25 #define thisTTClassTags "dspWindowFunctionLib, audio, processor, function, window"
26 
27 
28 TT_AUDIO_CONSTRUCTOR
29 {
30  // Register Attributes...
31  addAttribute(Alpha, kTypeFloat64);
32  addAttributeProperty(Alpha, range, TTValue(kTTEpsilon, 0.5)); // Avoid dividing by 0
33  addAttributeProperty(Alpha, rangeChecking, TT("clip"));
34 
35  // Set Defaults:
36  setAttributeValue(TT("alpha"), 0.4);
37 
38  setProcessMethod(processAudio);
39  setCalculateMethod(calculateValue);
40 }
41 
42 
43 TrapezoidWindow::~TrapezoidWindow()
44 {
45  ;
46 }
47 
48 
50 {
51  TTFloat64 twoOverAlpha = 2. / mAlpha;
52  TTFloat64 alphaOverTwo = mAlpha / 2.;
53 
54  if ( x < alphaOverTwo ) { // attack portion
55 
56  y = x * twoOverAlpha;
57 
58  } else if ( x > ( 1 - alphaOverTwo ) ) { // release portion
59 
60  y = (1 - x) * twoOverAlpha;
61 
62  } else { // sustain portion
63 
64  y = 1.;
65 
66  }
67 
68  TTLimit(y, 0.0, 1.0 );
69 
70  return kTTErrNone;
71 }
72 
73 
75 {
76  TT_WRAP_CALCULATE_METHOD(calculateValue);
77 }
78 
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
Calculate y = f(x) for a single value.
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTFloat64 mAlpha
Set the alpha attribute of the Trapezoid window function.
Trapezoid Window Function Unit for Jamoma DSP.
#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
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
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
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