Jamoma API  0.6.0.a19
TTAllpass4a.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTAllpass4a is a fourth-order allpass filter.
6  *
7  * @details Essentially the same as #TTAllpass2a, but with some signs flipped.
8  * Based on Fredric J. Harris (2004): Multirate Signal Processing for Communication Systems, Prentice Hall, Chapter 10, Figure 42.
9  *
10  *
11  * @authors Timothy Place, Trond Lossius
12  *
13  * @copyright Copyright © 2010, Timothy Place @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 
19 #include "TTAllpass4a.h"
20 
21 #define thisTTClass TTAllpass4a
22 #define thisTTClassName "allpass.4a"
23 #define thisTTClassTags "dspFilterLib, audio, processor, filter, allpass"
24 
25 #ifdef TT_PLATFORM_WIN
26 #include <Algorithm>
27 #endif
28 
29 TT_AUDIO_CONSTRUCTOR,
30  mD1(0),
31  mD2(0),
32  mD3(0),
33  mD4(0)
34 {
35  TTChannelCount initialMaxNumChannels = arguments;
36 
41 
42  addMessage(clear);
43  addUpdates(MaxNumChannels);
44 
45  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
46  setProcessMethod(processAudio);
47 }
48 
49 
50 TTAllpass4a::~TTAllpass4a()
51 {
52  ;
53 }
54 
55 
56 TTErr TTAllpass4a::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
57 {
58  mX1.resize(mMaxNumChannels);
59  mX2.resize(mMaxNumChannels);
60  mX3.resize(mMaxNumChannels);
61  mX4.resize(mMaxNumChannels);
62  mY1.resize(mMaxNumChannels);
63  mY2.resize(mMaxNumChannels);
64  mY3.resize(mMaxNumChannels);
65  mY4.resize(mMaxNumChannels);
66  clear();
67  return kTTErrNone;
68 }
69 
70 
71 TTErr TTAllpass4a::clear()
72 {
73  mX1.assign(mMaxNumChannels, 0.0);
74  mX2.assign(mMaxNumChannels, 0.0);
75  mX3.assign(mMaxNumChannels, 0.0);
76  mX4.assign(mMaxNumChannels, 0.0);
77  mY1.assign(mMaxNumChannels, 0.0);
78  mY2.assign(mMaxNumChannels, 0.0);
79  mY3.assign(mMaxNumChannels, 0.0);
80  mY4.assign(mMaxNumChannels, 0.0);
81  return kTTErrNone;
82 }
83 
84 
85 TTErr TTAllpass4a::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt channel)
86 {
87  TTFloat64 w1 = mD1 * (mX3[channel] - mY1[channel]);
88  TTFloat64 w2 = mD2 * (mX2[channel] - mY2[channel]);
89  TTFloat64 w3 = mD3 * (mX1[channel] - mY3[channel]);
90  TTFloat64 w4 = mD4 * (x - mY4[channel]);
91 
92  y = w1 + w2 + w3 + w4 + mX4[channel];
93 
94  TTZeroDenormal(y);
95 
96  // TODO: Is there something faster that we can do below rather all of this copying?
97  // If we could have a pointer that just incremented it seems like it would be faster
98  // But then we need some clever bit twiddling to efficiently do the wrapping...
99  mX4[channel] = mX3[channel];
100  mY4[channel] = mY3[channel];
101  mX3[channel] = mX2[channel];
102  mY3[channel] = mY2[channel];
103  mX2[channel] = mX1[channel];
104  mY2[channel] = mY1[channel];
105  mX1[channel] = x;
106  mY1[channel] = y;
107 
108  return kTTErrNone;
109 }
110 
111 
112 TTErr TTAllpass4a::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
113 {
114  TT_WRAP_CALCULATE_METHOD(calculateValue);
115 }
116 
TTSampleVector mY4
previous output sample (n-4) for each channel
Definition: TTAllpass4a.h:45
TTSampleVector mY1
previous output sample (n-1) for each channel
Definition: TTAllpass4a.h:42
#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.
TTSampleVector mY3
previous output sample (n-3) for each channel
Definition: TTAllpass4a.h:44
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTFloat64 mD4
fourth coefficient
Definition: TTAllpass4a.h:36
TTSampleVector mX3
previous input sample (n-3) for each channel
Definition: TTAllpass4a.h:40
64-bit floating point
Definition: TTBase.h:272
TTFloat64 mD1
first coefficient
Definition: TTAllpass4a.h:33
TTFloat64 mD2
second coefficient
Definition: TTAllpass4a.h:34
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTSampleVector mY2
previous output sample (n-2) for each channel
Definition: TTAllpass4a.h:43
TTSampleVector mX4
previous input sample (n-4) for each channel
Definition: TTAllpass4a.h:41
A simple container for an array of TTAudioSignal pointers.
TTSampleVector mX2
previous input sample (n-2) for each channel
Definition: TTAllpass4a.h:39
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 addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
TTAllpass4a is a fourth-order allpass filter.
No Error.
Definition: TTBase.h:343
TTSampleVector mX1
previous input sample (n-1) for each channel
Definition: TTAllpass4a.h:38
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTFloat64 mD3
third coefficient
Definition: TTAllpass4a.h:35
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44