Jamoma API  0.6.0.a19
TTLowpassButterworth1.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTLowpassButterworth1 is a first-order Butterworth lowpass filter.
6  *
7  * @details Butterworth filters have maximum flat frequency response in the pass band.
8  * @n
9  * Filter equations from: @n
10  * @n
11  * Second-order IIR Filters will support cascade implementations @n
12  * By Rusty Allred, Texas Instruments, Dallas @n
13  * July 01, 2003 @n
14  * http://www.planetanalog.com/article/printableArticle.jhtml?articleID=12802683
15  *
16  * @authors Trond Lossius, Timothy Place,
17  *
18  * @copyright Copyright © 2008, Trond Lossius @n
19  * This code is licensed under the terms of the "New BSD License" @n
20  * http://creativecommons.org/licenses/BSD/
21  */
22 
23 
24 #include "TTLowpassButterworth1.h"
25 
26 #define thisTTClass TTLowpassButterworth1
27 #define thisTTClassName "lowpass.butterworth.1"
28 #define thisTTClassTags "dspFilterLib, audio, processor, filter, lowpass, butterworth"
29 
30 
31 TT_AUDIO_CONSTRUCTOR
32 {
33  // register attributes
35  addAttributeProperty(Frequency, range, TTValue(10.0, sr*0.475));
36  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
37 
38  // register for notifications from the parent class so we can allocate memory as required
39  addUpdates(MaxNumChannels);
40  // register for notifications from the parent class so we can recalculate coefficients as required
41  addUpdates(SampleRate);
42  // make the clear method available to the outside world
43  addMessage(clear);
44 
45  // Set Defaults...
46  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
47  setAttributeValue(TT("frequency"), 1000.0);
48  setProcessMethod(processAudio);
49  setCalculateMethod(calculateValue);
50 
51 }
52 
53 
54 TTLowpassButterworth1::~TTLowpassButterworth1()
55 {
56  ;
57 }
58 
59 
61 {
62  mX1.resize(mMaxNumChannels);
63  mY1.resize(mMaxNumChannels);
64  clear();
65  return kTTErrNone;
66 }
67 
68 
69 TTErr TTLowpassButterworth1::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
70 {
72  return setFrequency(v);
73 }
74 
75 
77 {
78  mX1.assign(mMaxNumChannels, 0.0);
79  mY1.assign(mMaxNumChannels, 0.0);
80  return kTTErrNone;
81 }
82 
83 
85 {
86  mFrequency = newValue;
88  mK = mRadians/tan(kTTPi*mFrequency/sr);
89  calculateCoefficients();
90  return kTTErrNone;
91 }
92 
93 
94 void TTLowpassButterworth1::calculateCoefficients()
95 {
96  mA0 = mK/(mK+mRadians);
97  //mA1 = mA0;
98  mB1 = (mRadians-mK)/(mK+mRadians);
99 }
100 
101 
103 {
104  // y = mA0*x + mA1*mX1[channel] - mB1*mY1[channel];
105  // since mA0 = mA1, we can simplyfy to
106  y = mA0*(x + mX1[channel]) - mB1*mY1[channel];
107  TTZeroDenormal(y);
108 
109  mX1[channel] = x;
110  mY1[channel] = y;
111  return kTTErrNone;
112 }
113 
114 
116 {
117  TT_WRAP_CALCULATE_METHOD(calculateValue);
118 }
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.
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.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
#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
TTFloat64 mB1
filter coefficients
#define addAttributeProperty(attributeName, propertyName, initialValue)
A convenience macro to be used for registering properties of attributes.
Definition: TTAttribute.h:68
TTFloat64 mFrequency
filter cutoff frequency
TTLowpassButterworth1 is a first-order Butterworth lowpass filter.
TTSampleVector mX1
Input sample n-1.
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 setFrequency(const TTValue &value)
Setter for the frequency attribute.
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
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Receives notifications when there are changes to the inherited mMaxNumChannels attribute.
TTFloat64 mRadians
filter coefficients
TTSampleVector mY1
Output 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.