Jamoma API  0.6.0.a19
TTLowpassFourPole.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTLowpassFourPole is a 4-Pole Lowpass Filter Object.
6  *
7  * @details
8  *
9  * @authors Timothy Place, Trond Lossius
10  *
11  * @copyright Copyright © 2008, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTLowpassFourPole.h"
18 
19 #define thisTTClass TTLowpassFourPole
20 #define thisTTClassName "lowpass.4"
21 #define thisTTClassDescription "Four-pole resonant lowpass filter"
22 #define thisTTClassTags "dspFilterLib, audio, processor, filter, lowpass"
23 
24 
25 TT_AUDIO_CONSTRUCTOR
26 {
27  // register attributes
29  addAttributeProperty(Frequency, range, TTValue(2.0, sr*0.475));
30  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
31  addAttributeProperty(Frequency, description, TT("Cutoff Frequency in Hertz"));
32 
34  addAttributeProperty(Q, range, TTValue(0.01, 100.0));
35  addAttributeProperty(Q, rangeChecking, TT("cliplow"));
36  addAttributeProperty(Q, description, TT("Strength of Resonance Near the Cutoff Frequency"));
37 
38  // register methods
39  addMessage(clear);
40  addMessageProperty(clear, description, TT("Reset the Filter History"));
41 
42  // register for notifications
43  addUpdates(MaxNumChannels);
44  addUpdates(SampleRate);
45 
46  // Set Defaults...
47  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
48  setAttributeValue(TT("frequency"), 1000.0);
49  setAttributeValue(TT("resonance"), 1.0);
50 
51  setCalculateMethod(calculateValue);
52  setProcessMethod(processAudio);
53 }
54 
55 
56 TTLowpassFourPole::~TTLowpassFourPole()
57 {
58  ;
59 }
60 
61 
62 TTErr TTLowpassFourPole::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
63 {
64  mX1.resize(mMaxNumChannels);
65  mX2.resize(mMaxNumChannels);
66  mX3.resize(mMaxNumChannels);
67  mX4.resize(mMaxNumChannels);
68  mY1.resize(mMaxNumChannels);
69  mY2.resize(mMaxNumChannels);
70  mY3.resize(mMaxNumChannels);
71  mY4.resize(mMaxNumChannels);
72  clear();
73  return kTTErrNone;
74 }
75 
76 
77 TTErr TTLowpassFourPole::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
78 {
80  return setFrequency(v);
81 }
82 
83 
85 {
86  mX1.assign(mMaxNumChannels, 0.0);
87  mX2.assign(mMaxNumChannels, 0.0);
88  mX3.assign(mMaxNumChannels, 0.0);
89  mX4.assign(mMaxNumChannels, 0.0);
90  mY1.assign(mMaxNumChannels, 0.0);
91  mY2.assign(mMaxNumChannels, 0.0);
92  mY3.assign(mMaxNumChannels, 0.0);
93  mY4.assign(mMaxNumChannels, 0.0);
94  return kTTErrNone;
95 }
96 
97 
98 TTErr TTLowpassFourPole::setFrequency(const TTValue& newValue)
99 {
100  TTFloat64 radians;
101 
102  mFrequency = newValue;
103  radians = hertzToRadians(mFrequency);
104  mCoefficientF = radians * 1.16;
107  calculateCoefficients();
108  return kTTErrNone;
109 }
110 
111 
112 TTErr TTLowpassFourPole::setQ(const TTValue& newValue)
113 {
114  mQ = newValue;
115  mDeciResonance = mQ * 0.1;
116  calculateCoefficients();
117  return kTTErrNone;
118 }
119 
120 
121 void TTLowpassFourPole::calculateCoefficients()
122 {
124  mCoefficientG = TTAntiDenormal(0.35013 * (mCoefficientSquaredF * mCoefficientSquaredF));
125 }
126 
127 
129 {
130  TTSampleValue tempSample = x;
131 
132  tempSample -= mY4[channel] * mCoefficientFB;
133  TTZeroDenormal(tempSample);
134  tempSample *= mCoefficientG;
135 
136  mY1[channel] = tempSample + 0.3 * mX1[channel] + mOneMinusCoefficientF * mY1[channel];
137  TTZeroDenormal(mY1[channel]);
138  mX1[channel] = tempSample;
139  mY2[channel] = mY1[channel] + 0.3 * mX2[channel] + mOneMinusCoefficientF * mY2[channel];
140  TTZeroDenormal(mY2[channel]);
141  mX2[channel] = mY1[channel];
142  mY3[channel] = mY2[channel] + 0.3 * mX3[channel] + mOneMinusCoefficientF * mY3[channel];
143  TTZeroDenormal(mY3[channel] );
144  mX3[channel] = mY2[channel];
145  mY4[channel] = mY3[channel] + 0.3 * mX4[channel] + mOneMinusCoefficientF * mY4[channel];
146  TTZeroDenormal(mY4[channel]);
147  mX4[channel] = mY3[channel];
148  tempSample = mY4[channel];
149 
150  y = tempSample;
151  return kTTErrNone;
152 }
153 
154 
156 {
157  TT_WRAP_CALCULATE_METHOD(calculateValue);
158 }
159 
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
TTErr clear()
This algorithm uses an IIR filter, meaning that it relies on feedback.
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTFloat64 mCoefficientG
filter coefficient
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTFloat64 mFrequency
filter cutoff frequency
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTLowpassFourPole is a 4-Pole Lowpass Filter Object.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTSampleVector mY4
4th previous output sample for each channel
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
TTFloat64 mQ
filter resonance – range is best between 1.0 and 16.0
TTFloat64 mOneMinusCoefficientF
1 - mCoefficientF
64-bit floating point
Definition: TTBase.h:272
TTFloat64 mCoefficientF
filter coefficient
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
TTSampleVector mY3
3rd previous output sample for each channel
TTSampleVector mX3
3rd previous input sample for each channel
TTSampleVector mX4
4th previous input sample for each channel
TTFloat64 hertzToRadians(const TTFloat64 hz)
Convert Hertz to radians.
A simple container for an array of TTAudioSignal pointers.
TTFloat64 mCoefficientSquaredF
mCoefficientF * mCoefficientF
TTSampleVector mX2
2nd previous input sample for each channel
TTFloat64 mDeciResonance
attrResonance * 0.1
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
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
TTSampleVector mX1
previous input sample for each channel
TTSampleVector mY2
2nd previous output sample for each channel
No Error.
Definition: TTBase.h:343
TTSampleVector mY1
previous output sample for each channel
TTFloat64 mCoefficientFB
filter coefficient
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[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
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.
Definition: TTMessage.h:37