Jamoma API  0.6.0.a19
TTHighpassLinkwitzRiley2.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTHighpassLinkwitzRiley2 is a second-order Linkwitz-Riley highpass 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.planetanalog.com/article/printableArticle.jhtml?articleID=12802683
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 
21 
23 
24 #define thisTTClass TTHighpassLinkwitzRiley2
25 #define thisTTClassName "highpass.linkwitzriley.2"
26 #define thisTTClassTags "dspFilterLib, audio, processor, filter, highpass"
27 
28 
29 TT_AUDIO_CONSTRUCTOR
30 {
31  // register attributes
33  addAttributeProperty(Frequency, range, TTValue(10.0, sr*0.475));
34  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
35 
36  // register for notifications from the parent class so we can allocate memory as required
37  addUpdates(MaxNumChannels);
38  // register for notifications from the parent class so we can recalculate coefficients as required
39  addUpdates(SampleRate);
40  // make the clear method available to the outside world
41  addMessage(clear);
42 
43  // Set Defaults...
44  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
45  setAttributeValue(TT("frequency"), 1000.0);
46  setProcessMethod(processAudio);
47  setCalculateMethod(calculateValue);
48 
49 }
50 
51 
52 TTHighpassLinkwitzRiley2::~TTHighpassLinkwitzRiley2()
53 {
54  ;
55 }
56 
57 
59 {
60  mX1.resize(mMaxNumChannels);
61  mX2.resize(mMaxNumChannels);
62  mY1.resize(mMaxNumChannels);
63  mY2.resize(mMaxNumChannels);
64  clear();
65  return kTTErrNone;
66 }
67 
68 
69 TTErr TTHighpassLinkwitzRiley2::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
70 {
72  return setFrequency(v);
73 }
74 
75 
77 {
78  mX1.assign(mMaxNumChannels, 0.0);
79  mX2.assign(mMaxNumChannels, 0.0);
80  mY1.assign(mMaxNumChannels, 0.0);
81  mY2.assign(mMaxNumChannels, 0.0);
82  return kTTErrNone;
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 
96 
97  return kTTErrNone;
98 }
99 void TTHighpassLinkwitzRiley2::calculateCoefficients()
100 {
101  TTFloat64 temp = 2*mRadians*mK;
102 
103  mA0 = (mKSquared)/(mKSquared+mRadiansSquared+temp);
104  mA1 = (-2*mKSquared)/(mKSquared+mRadiansSquared+temp);
105  //mA2 = mA0;//mA2 = (mKSquared)/(mKSquared+mRadiansSquared+temp);
106 
107  mB1 = (-2*mKSquared+2*mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
108  mB2=(-temp+mKSquared+mRadiansSquared)/(mKSquared+mRadiansSquared+temp);
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 }
130 
131 
TTSampleVector mX2
Input sample n-2.
TTFloat64 mFrequency
filter cutoff frequency
TTSampleVector mY2
Output sample n-2.
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
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.
TTErr clear()
This algorithm uses an IIR filter, meaning that it relies on feedback.
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 mB2
filter coefficients for output samples
TTErr setFrequency(const TTValue &value)
Setter for the frequency attribute.
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
A simple container for an array of TTAudioSignal pointers.
TTSampleVector mY1
Output sample n-1.
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Receives notifications when there are changes to the inherited mMaxNumChannels attribute.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTHighpassLinkwitzRiley2 is a second-order Linkwitz-Riley highpass filter.
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
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
TTSampleVector mX1
Input sample n-1.
[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
TTUInt32 sr
Current sample rate being used by this object.