Jamoma API  0.6.0.a19
TTLowpassLinkwitzRiley2.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTLowpassLinkwitzRiley2 is a second-order Linkwitz-Riley lowpass filter.
6  *
7  * @details Filter equations from: @n
8  * @n
9  * Second-order IIR Filters will support cascade implementations @n
10  * By Rusty Allred, Texas Instruments, Dallas @n
11  * July 01, 2003 @n
12  * http://www.eetimes.com/document.asp?doc_id=1272177
13  *
14  * @authors Trond Lossius, Timothy Place,
15  *
16  * @copyright Copyright © 2008, 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 
22 
23 #define thisTTClass TTLowpassLinkwitzRiley2
24 #define thisTTClassName "lowpass.linkwitzriley.2"
25 #define thisTTClassTags "dspFilterLib, audio, processor, filter, lowpass"
26 
27 
28 TT_AUDIO_CONSTRUCTOR
29 {
30  // register attributes
32  addAttributeProperty(Frequency, range, TTValue(10.0, sr*0.475));
33  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
34 
35  // register for notifications from the parent class so we can allocate memory as required
36  addUpdates(MaxNumChannels);
37  // register for notifications from the parent class so we can recalculate coefficients as required
38  addUpdates(SampleRate);
39  // make the clear method available to the outside world
40  addMessage(clear);
41 
42  // Set Defaults...
43  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
44  setAttributeValue(TT("frequency"), 1000.0);
45  setProcessMethod(processAudio);
46  setCalculateMethod(calculateValue);
47 
48 }
49 
50 
51 TTLowpassLinkwitzRiley2::~TTLowpassLinkwitzRiley2()
52 {
53  ;
54 }
55 
56 
58 {
59  mX1.resize(mMaxNumChannels);
60  mX2.resize(mMaxNumChannels);
61  mY1.resize(mMaxNumChannels);
62  mY2.resize(mMaxNumChannels);
63  clear();
64  return kTTErrNone;
65 }
66 
67 
68 TTErr TTLowpassLinkwitzRiley2::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
69 {
71  return setFrequency(v);
72 }
73 
74 
76 {
77  mX1.assign(mMaxNumChannels, 0.0);
78  mX2.assign(mMaxNumChannels, 0.0);
79  mY1.assign(mMaxNumChannels, 0.0);
80  mY2.assign(mMaxNumChannels, 0.0);
81  return kTTErrNone;
82 
83 }
84 
85 
87 {
88  mFrequency = newValue;
89 
90  mRadians = kTTTwoPi*mFrequency;
91  mK = mRadians/tan(kTTPi*mFrequency/sr); // kTTTwoPi*frequency/tan(kTTPi*frequency/sr);
92  mRadiansSquared = mRadians * mRadians;
93  mKSquared = mK * mK;
94  calculateCoefficients();
95  return kTTErrNone;
96 }
97 
98 void TTLowpassLinkwitzRiley2::calculateCoefficients()
99 {
100  TTFloat64 temp = 2*mRadians*mK;
101 
102  mA0 = (mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
103  mA1 = (2*mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
104  //mA2 = mA0; //mA2 = (mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
105 
106  mB1 = (-2*mKSquared+2*mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
107  mB2 = (-temp+mKSquared+mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
108 }
109 
110 
112 {
113  //y = TTAntiDenormal(mA0*x + mA1*mX1[channel] + mA2*mX2[channel] - mB1*mY1[channel] - mB2*mY2[channel]);
114  //since mA2 = mA0, we write
115  y = mA0* (x + mX2[channel]) + mA1*mX1[channel] - mB1*mY1[channel] - mB2*mY2[channel];
116  TTZeroDenormal(y);
117  mX2[channel] = mX1[channel];
118  mX1[channel] = x;
119  mY2[channel] = mY1[channel];
120  mY1[channel] = y;
121  return kTTErrNone;
122 }
123 
124 
125 
127 {
128  TT_WRAP_CALCULATE_METHOD(calculateValue);
129 }
TTErr clear()
This algorithm uses an IIR filter, meaning that it relies on feedback.
TTFloat64 mFrequency
filter cutoff frequency
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTFOUNDATION_EXPORT const TTFloat64 kTTTwoPi
Pre-calculated value of pi * 2.
Definition: TTBase.cpp:24
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTSampleVector mY2
Output sample n-2.
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTSampleVector mX2
Input sample n-2.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTFloat64 mB2
filter coefficients for output samples
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
TTSampleVector mX1
Input sample n-1.
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Receives notifications when there are changes to the inherited mMaxNumChannels attribute.
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
TTErr setFrequency(const TTValue &value)
Setter for the frequency attribute.
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
TTSampleVector mY1
Output sample n-1.
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
No Error.
Definition: TTBase.h:343
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44
TTLowpassLinkwitzRiley2 is a second-order Linkwitz-Riley lowpass filter.
TTUInt32 sr
Current sample rate being used by this object.