Jamoma API  0.6.0.a19
TTAllpass2b.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTAllpass2b is a second-order allpass filter.
6  *
7  * @details A second-order Z^2 building-block allpass filter.
8  * This allpass filter uses a fixed delay of 2 samples (M=2). *
9  *
10  * @authors Timothy Place, Trond Lossius
11  *
12  * @copyright Copyright © 2010, Timothy Place @n
13  * This code is licensed under the terms of the "New BSD License" @n
14  * http://creativecommons.org/licenses/BSD/
15  */
16 
17 
18 #include "TTAllpass2b.h"
19 
20 #define thisTTClass TTAllpass2b
21 #define thisTTClassName "allpass.2b"
22 #define thisTTClassTags "dspFilterLib, audio, processor, filter, allpass"
23 
24 #ifdef TT_PLATFORM_WIN
25 #include <Algorithm>
26 #endif
27 
28 TT_AUDIO_CONSTRUCTOR,
29  mC1(0),
30  mC2(0)
31 {
32  TTChannelCount initialMaxNumChannels = arguments;
33 
36 
37  addMessage(clear);
38  addUpdates(MaxNumChannels);
39 
40  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
41  setProcessMethod(processAudio);
42 }
43 
44 
45 TTAllpass2b::~TTAllpass2b()
46 {
47  ;
48 }
49 
50 
51 TTErr TTAllpass2b::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
52 {
53  mX1.resize(mMaxNumChannels);
54  mX2.resize(mMaxNumChannels);
55  mX3.resize(mMaxNumChannels);
56  mX4.resize(mMaxNumChannels);
57  mY1.resize(mMaxNumChannels);
58  mY2.resize(mMaxNumChannels);
59  mY3.resize(mMaxNumChannels);
60  mY4.resize(mMaxNumChannels);
61  clear();
62  return kTTErrNone;
63 }
64 
65 
66 TTErr TTAllpass2b::clear()
67 {
68  mX1.assign(mMaxNumChannels, 0.0);
69  mX2.assign(mMaxNumChannels, 0.0);
70  mX3.assign(mMaxNumChannels, 0.0);
71  mX4.assign(mMaxNumChannels, 0.0);
72  mY1.assign(mMaxNumChannels, 0.0);
73  mY2.assign(mMaxNumChannels, 0.0);
74  mY3.assign(mMaxNumChannels, 0.0);
75  mY4.assign(mMaxNumChannels, 0.0);
76  return kTTErrNone;
77 }
78 
79 
80 TTErr TTAllpass2b::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt channel)
81 {
82  TTFloat64 w1 = mC1 * (mX2[channel] - mY2[channel]);
83  TTFloat64 w2 = mC2 * (x - mY4[channel]);
84 
85  y = w1 + w2 + mX4[channel];
86 
87  TTZeroDenormal(y);
88 
89  mX4[channel] = mX3[channel];
90  mY4[channel] = mY3[channel];
91  mX3[channel] = mX2[channel];
92  mY3[channel] = mY2[channel];
93  mX2[channel] = mX1[channel];
94  mY2[channel] = mY1[channel];
95  mX1[channel] = x;
96  mY1[channel] = y;
97  return kTTErrNone;
98 }
99 
100 
101 TTErr TTAllpass2b::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
102 {
103  TT_WRAP_CALCULATE_METHOD(calculateValue);
104 }
105 
TTSampleVector mY3
previous output sample (n-3) for each channel
Definition: TTAllpass2b.h:41
TTSampleVector mY1
previous output sample (n-1) for each channel
Definition: TTAllpass2b.h:39
TTAllpass2b is a second-order allpass filter.
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
#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
64-bit floating point
Definition: TTBase.h:272
TTSampleVector mX1
previous input sample (n-1) for each channel
Definition: TTAllpass2b.h:35
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.
TTSampleVector mX2
previous input sample (n-2) for each channel
Definition: TTAllpass2b.h:36
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTFloat64 mC1
first coefficient
Definition: TTAllpass2b.h:32
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTSampleVector mY2
previous output sample (n-2) for each channel
Definition: TTAllpass2b.h:40
TTSampleVector mX3
previous input sample (n-3) for each channel
Definition: TTAllpass2b.h:37
TTSampleVector mX4
previous input sample (n-4) for each channel
Definition: TTAllpass2b.h:38
TTFloat64 mC2
second coefficient
Definition: TTAllpass2b.h:33
TTSampleVector mY4
previous output sample (n-4) for each channel
Definition: TTAllpass2b.h:42
[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