Jamoma API  0.6.0.a19
TTHighpassButterworth1.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTHighpassButterworth1 is a second-order Butterworth highpass filter.
6  *
7  * @details Butterworth filters have maximum flat frequency response in the pass band.
8  * Filter equations from: @n
9  * @n
10  * Second-order IIR Filters will support cascade implementations @n
11  * By Rusty Allred, Texas Instruments, Dallas @n
12  * July 01, 2003
13  * http://www.planetanalog.com/article/printableArticle.jhtml?articleID=12802683
14  .
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 "TTHighpassButterworth1.h"
25 
26 #define thisTTClass TTHighpassButterworth1
27 #define thisTTClassName "highpass.butterworth.1"
28 #define thisTTClassTags "dspFilterLib, audio, processor, filter, highpass, butterworth"
29 
30 
31 TT_AUDIO_CONSTRUCTOR{
32  // register attributes
34  addAttributeProperty(Frequency, range, TTValue(10.0, sr*0.475));
35  addAttributeProperty(Frequency, rangeChecking, TT("clip"));
36 
37  // register for notifications from the parent class so we can allocate memory as required
38  addUpdates(MaxNumChannels);
39  // register for notifications from the parent class so we can recalculate coefficients as required
40  addUpdates(SampleRate);
41  // make the clear method available to the outside world
42  addMessage(clear);
43 
44  // Set Defaults...
45  setAttributeValue(kTTSym_maxNumChannels, arguments); // This attribute is inherited
46  setAttributeValue(TT("frequency"), 1000.0);
47  setProcessMethod(processAudio);
48  setCalculateMethod(calculateValue);
49 }
50 
51 
52 TTHighpassButterworth1::~TTHighpassButterworth1()
53 {
54  ;
55 }
56 
57 
59 {
60  mX1.resize(mMaxNumChannels);
61  mY1.resize(mMaxNumChannels);
62  clear();
63  return kTTErrNone;
64 }
65 
66 
67 TTErr TTHighpassButterworth1::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
68 {
70  return setFrequency(v);
71 }
72 
73 
75 {
76  mX1.assign(mMaxNumChannels, 0.0);
77  mY1.assign(mMaxNumChannels, 0.0);
78  return kTTErrNone;
79 }
80 
81 
83 {
84  mFrequency = newValue;
86  mK = mRadians/tan(kTTPi*mFrequency/sr);
87  calculateCoefficients();
88  return kTTErrNone;
89 }
90 
91 
92 
93 void TTHighpassButterworth1::calculateCoefficients()
94 {
95  mA0 = mK/(mK+mRadians);
96  mA1 = -mA0;//-k/(k+wc);
97  mB1 = (mRadians-mK)/(mK+mRadians);
98 }
99 
100 
102 {
103  //y = TTAntiDenormal(mA0*x + mA1*mX1[channel] - mB1*mY1[channel]);
104  //since mA1 = -mA0, we can simplyfiy to
105  y = mA0*(x - mX1[channel]) - mB1*mY1[channel];
106  TTZeroDenormal(y);
107  mX1[channel] = x;
108  mY1[channel] = y;
109  return kTTErrNone;
110 }
111 
112 
114 {
115  TT_WRAP_CALCULATE_METHOD(calculateValue);
116 }
117 
118 
TTSampleVector mY1
Output sample n-1.
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTFloat64 mRadians
filter coefficients
TTSampleVector mX1
Input sample n-1.
TTHighpassButterworth1 is a second-order Butterworth highpass filter.
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Receives notifications when there are changes to the inherited mMaxNumChannels attribute.
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 clear()
This algorithm uses an IIR filter, meaning that it relies on feedback.
#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 mFrequency
filter cutoff frequency
A simple container for an array of TTAudioSignal pointers.
TTErr setFrequency(const TTValue &value)
Setter for the frequency attribute.
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
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt channel)
Standard single value calculate method as used by DSP objects.
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue 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
TTFloat64 mB1
filter coefficients
TTUInt32 sr
Current sample rate being used by this object.