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