Jamoma API  0.6.0.a19
TTLowpassTwoPole.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTLowpassTwoPole is a 2-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 "TTLowpassTwoPole.h"
18 
19 #define thisTTClass TTLowpassTwoPole
20 #define thisTTClassName "lowpass.2"
21 #define thisTTClassTags "dspFilterLib, audio, processor, filter, lowpass"
22 
23 
24 TT_AUDIO_CONSTRUCTOR
25 {
26  // register attributes
28  addAttributeProperty(Frequency, range, TTValue(2.0, sr*0.475));
29  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
30 
32 
33  // register methods
34  addMessage(clear);
35 
36  // register for notifications
37  addUpdates(MaxNumChannels);
38  addUpdates(SampleRate);
39 
40  // Set Defaults...
41  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
42  setAttributeValue(TT("frequency"), 1000.0);
43  setAttributeValue(TT("resonance"), 1.0);
44 
45  setCalculateMethod(calculateValue);
46  setProcessMethod(processAudio);
47 }
48 
49 
50 TTLowpassTwoPole::~TTLowpassTwoPole()
51 {
52  ;
53 }
54 
55 
56 TTErr TTLowpassTwoPole::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
57 {
60  clear();
61  return kTTErrNone;
62 }
63 
64 
65 TTErr TTLowpassTwoPole::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
66 {
68  return setFrequency(v);
69 }
70 
71 
73 {
74  mFeedback1.assign(mMaxNumChannels, 0.0);
75  mFeedback2.assign(mMaxNumChannels, 0.0);
76  return kTTErrNone;
77 }
78 
79 
80 TTErr TTLowpassTwoPole::setFrequency(const TTValue& newValue)
81 {
82 
83  mFrequency = newValue;
85  calculateCoefficients();
86  return kTTErrNone;
87 }
88 
89 
90 TTErr TTLowpassTwoPole::setResonance(const TTValue& newValue)
91 {
92  mResonance = TTClip(TTFloat64(newValue), 0.001, 100.0);
94  calculateCoefficients();
95 
96  return kTTErrNone;
97 }
98 
99 
100 void TTLowpassTwoPole::calculateCoefficients()
101 {
102  mCoefficientA = 2.0 * cos(mRadians) * exp(0.5 * mRadians * mNegOneOverResonance);
105 }
106 
107 
109 {
110  y = (mFeedback1[channel] * mCoefficientA) - (mFeedback2[channel] * mCoefficientB) + (x * mCoefficientC);
111  TTZeroDenormal(y);
112  mFeedback2[channel] = mFeedback1[channel];
113  mFeedback1[channel] = y;
114  return kTTErrNone;
115 }
116 
117 
119 {
120  TT_WRAP_CALCULATE_METHOD(calculateValue);
121 }
122 
TTFloat64 mCoefficientC
filter coefficient
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 mFrequency
filter cutoff frequency
TTFloat64 mResonance
filter resonance
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTLowpassTwoPole is a 2-Pole Lowpass Filter Object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTFloat64 mRadians
filter cutoff frequence expressed in radians
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTFloat64 mCoefficientB
filter coefficient
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
TTFloat64 mNegOneOverResonance
-1 / attrResonance
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 hertzToRadians(const TTFloat64 hz)
Convert Hertz to radians.
TTFloat64 mCoefficientA
filter coefficient
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
TTSampleVector mFeedback2
2nd previous output sample for each channel
TTSampleVector mFeedback1
previous output sample for each channel
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
#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
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
[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