Jamoma API  0.6.0.a19
TTHalfbandLinear33.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTHalfbandLinear33 is a 33-Pole Halfband filter built up from a 2-path allpass structure.
6  *
7  * @details Same magnitude response with respect to frequency as #TTHalfband9, but with nearly linear phase response. @n
8  * @n
9  * The coefficients can be calculated using the "lineardesign_2.m" Matlab script. To generate the particular set of coefficients currently hard-coded into this filter, choose the following settings (yields a roughly -60dB stopband attenuation): @n
10  * - iterations: 100 (iterations bring the filter toward equiripple in the stopband) @n
11  * - wc = 0.2895 (this is the normalized frequency of the start of the stopband) @n
12  * - number of paths = 2 @n
13  * - number of coefficients = 8 @n
14  * @n
15  * The result is: @n
16  * @n
17  * Roots = @n
18  * @n
19  * -0.832302165608369
20  * -0.338171398434493 + 0.342959068350197i
21  * -0.338171398434493 - 0.342959068350197i
22  * -0.001794835916660 + 0.437771696086791i
23  * -0.001794835916660 - 0.437771696086791i
24  * 0.421285425003053
25  * 0.298484480776670 + 0.301855022798834i
26  * 0.298484480776670 - 0.301855022798834i
27  * @n
28  * branch 1 - type1 coefficient 0.8323021656083688 -0.4212854250030528 @n
29  * branch 1 - type2 1st coefficient 0.6763427968689864 0.003589671833320152 -0.59696896155334 @n
30  * branch 1 - type2 2nd coefficient 0.2319808172827758 0.1916472793306732 0.1802094400534031 @n
31  *
32  * The ordering of the coefficients may not be at first obvious. The first line of coefficients are the two alpha coefficients for the first two (first-order) allpass filters, F0 and F1. @n
33  * @n
34  @ The second and third lines together provide the coefficient pairs for the remaining (second-order) filters. Thus, 0.6763427968689864 and 0.2319808172827758 are the coefficient pair for the first filter 0.003589671833320152 and 0.1916472793306732 are the coefficient pair for the second filter, and so on.
35  *
36  * @authors Timothy Place, Trond Lossius
37  *
38  * @copyright Copyright © 2010, Timothy Place @n
39  * This code is licensed under the terms of the "New BSD License" @n
40  * http://creativecommons.org/licenses/BSD/
41  */
42 
43 
44 #include "TTHalfbandLinear33.h"
45 
46 #define thisTTClass TTHalfbandLinear33
47 #define thisTTClassName "halfband.linear.33"
48 #define thisTTClassTags "dspFilterLib, audio, processor, filter, lowpass, highpass"
49 
50 #ifdef TT_PLATFORM_WIN
51 #include <Algorithm>
52 #endif
53 
54 TT_AUDIO_CONSTRUCTOR,
55  mP0Delay("delay"),
56  mP1Delay("allpass.1a"),
57  mF0("allpass.1b"),
58  mF1("allpass.1b"),
59  mF2("allpass.2b"),
60  mF3("allpass.2b"),
61  mF4("allpass.2b")
62 {
63  TTChannelCount initialMaxNumChannels = arguments;
64 
66  addMessage(clear);
67  addUpdates(MaxNumChannels);
68 
69  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
70  setAttributeValue(TT("mode"), TT("lowpass"));
71 
72  mP0Delay.set("delayMaxInSamples", 16);
73  mP0Delay.set("delayInSamples", 16);
74 
75  mP1Delay.set("alpha", 0.0);
76  mF0.set("alpha", 0.832280776);
77  mF1.set("alpha", -0.421241137);
78  mF2.set("c1", 0.67623706);
79  mF2.set("c2", 0.23192313);
80  mF3.set("c1", 0.00359228);
81  mF3.set("c2", 0.19159423);
82  mF4.set("c1", -0.59689082);
83  mF4.set("c2", 0.18016931);
84 }
85 
86 
87 TTHalfbandLinear33::~TTHalfbandLinear33()
88 {
89 }
90 
91 
92 TTErr TTHalfbandLinear33::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
93 {
94  // update internal filters
95  mF0.set(kTTSym_maxNumChannels, mMaxNumChannels);
96  mF1.set(kTTSym_maxNumChannels, mMaxNumChannels);
97  mF2.set(kTTSym_maxNumChannels, mMaxNumChannels);
98  mF3.set(kTTSym_maxNumChannels, mMaxNumChannels);
99  mF4.set(kTTSym_maxNumChannels, mMaxNumChannels);
100  mP0Delay.set(kTTSym_maxNumChannels, mMaxNumChannels);
101  mP1Delay.set(kTTSym_maxNumChannels, mMaxNumChannels);
102 
103  clear();
104  return kTTErrNone;
105 }
106 
107 
108 TTErr TTHalfbandLinear33::clear()
109 {
110  mF0.send(kTTSym_clear);
111  mF1.send(kTTSym_clear);
112  mF2.send(kTTSym_clear);
113  mF3.send(kTTSym_clear);
114  mF4.send(kTTSym_clear);
115  mP0Delay.send(kTTSym_clear);
116  mP1Delay.send(kTTSym_clear);
117  return kTTErrNone;
118 }
119 
120 
121 TTErr TTHalfbandLinear33::setMode(const TTValue& newValue)
122 {
123  TTSymbol newMode = newValue;
124 
125  if (newMode == TT("highpass")) {
126  mMode = TT("highpass");
127  setCalculateMethod(calculateHighpass);
128  setProcessMethod(processHighpass);
129  }
130  else { // lowpass
131  mMode = TT("lowpass");
132  setCalculateMethod(calculateLowpass);
133  setProcessMethod(processLowpass);
134  }
135  return kTTErrNone;
136 }
137 
138 
139 inline void TTHalfbandLinear33::filterKernel(const TTFloat64& input, TTFloat64& outputPath0, TTFloat64& outputPath1, TTPtrSizedInt channel)
140 {
141  TTFloat64 temp1, temp2;
142 
143  TTBASE(mP0Delay, TTDelay)->calculateNoInterpolation(input, outputPath0, channel);
144 
145  TTBASE(mP1Delay, TTAllpass1a)->calculateValue(input, temp2, channel);
146  TTBASE(mF0, TTAllpass1b)->calculateValue(temp2, temp1, channel);
147  TTBASE(mF1, TTAllpass1b)->calculateValue(temp1, temp2, channel);
148  TTBASE(mF2, TTAllpass2b)->calculateValue(temp2, temp1, channel);
149  TTBASE(mF3, TTAllpass2b)->calculateValue(temp1, temp2, channel);
150  TTBASE(mF4, TTAllpass2b)->calculateValue(temp2, outputPath1, channel);
151 }
152 
153 
154 TTErr TTHalfbandLinear33::calculateLowpass(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt channel)
155 {
156  TTFloat64 outputFromPath0 = 0;
157  TTFloat64 outputFromPath1;
158 
159  filterKernel(x, outputFromPath0, outputFromPath1, channel);
160  y = (outputFromPath0 + outputFromPath1) * 0.5;
161  return kTTErrNone;
162 }
163 
164 
165 TTErr TTHalfbandLinear33::calculateHighpass(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt channel)
166 {
167  TTFloat64 outputFromPath0;
168  TTFloat64 outputFromPath1;
169 
170  filterKernel(x, outputFromPath0, outputFromPath1, channel);
171  y = (outputFromPath0 - outputFromPath1) * 0.5;
172  return kTTErrNone;
173 }
174 
175 
176 TTErr TTHalfbandLinear33::processLowpass(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
177 {
178  TT_WRAP_CALCULATE_METHOD(calculateLowpass);
179 }
180 
181 
182 TTErr TTHalfbandLinear33::processHighpass(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
183 {
184  TT_WRAP_CALCULATE_METHOD(calculateHighpass);
185 }
186 
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTSymbol mMode
Attribute: lowpass or highpass.
#define TTBASE(instance_, class_)
Macro to access the actual C++ class that is contained inside of the TTObject as a pointer...
Definition: TTObject.h:211
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTAudioObject mP1Delay
path1
TTAudioObject mF3
path1
Symbol type.
Definition: TTBase.h:282
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
TTHalfbandLinear33 is a 33-Pole Halfband filter built up from a 2-path allpass structure.
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
TTAudioObject mF0
path1
TTAudioObject mF4
path1
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTAudioObject mF2
path1
A first-order building-block allpass filter.
Definition: TTAllpass1a.h:25
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
A simple container for an array of TTAudioSignal pointers.
Delay a signal.
Definition: TTDelay.h:22
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
A first-order building-block allpass filter.
Definition: TTAllpass1b.h:25
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
A second-order Z^2 building-block allpass filter.
Definition: TTAllpass2b.h:27
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
TTAudioObject mF1
path1
No Error.
Definition: TTBase.h:343
[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
TTAudioObject mP0Delay
path0, pure delay, 16 samples