Jamoma API  0.6.0.a19
TTAllpass2a.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTAllpass1b is a second-order allpass filter.
6  *
7  * @details Based on Fredric J. Harris (2004): Multirate Signal Processing for Communication Systems, Prentice Hall, Chapter 10, Figure 35.
8  *
9  * @authors Timothy Place, Trond Lossius
10  *
11  * @copyright Copyright © 2010, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTAllpass2a.h"
18 
19 #define thisTTClass TTAllpass2a
20 #define thisTTClassName "allpass.2a"
21 #define thisTTClassTags "dspFilterLib, audio, processor, filter, allpass"
22 
23 #ifdef TT_PLATFORM_WIN
24 #include <Algorithm>
25 #endif
26 
27 TT_AUDIO_CONSTRUCTOR,
28  mC1(0),
29  mC2(0)
30 {
31  TTChannelCount initialMaxNumChannels = arguments;
32 
35 
36  addMessage(clear);
37  addUpdates(MaxNumChannels);
38 
39  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
40  setProcessMethod(processAudio);
41 }
42 
43 
44 TTAllpass2a::~TTAllpass2a()
45 {
46  ;
47 }
48 
49 
50 TTErr TTAllpass2a::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
51 {
52  mX1.resize(mMaxNumChannels);
53  mX2.resize(mMaxNumChannels);
54  mY1.resize(mMaxNumChannels);
55  mY2.resize(mMaxNumChannels);
56  clear();
57  return kTTErrNone;
58 }
59 
60 
61 TTErr TTAllpass2a::clear()
62 {
63  mX1.assign(mMaxNumChannels, 0.0);
64  mX2.assign(mMaxNumChannels, 0.0);
65  mY1.assign(mMaxNumChannels, 0.0);
66  mY2.assign(mMaxNumChannels, 0.0);
67  return kTTErrNone;
68 }
69 
70 
71 TTErr TTAllpass2a::calculateValue(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt channel)
72 {
73  TTFloat64 w1 = mC1 * (mX1[channel] - mY1[channel]);
74  TTFloat64 w2 = mC2 * (x - mY2[channel]);
75 
76  y = w1 + w2 + mX2[channel];
77 
78  TTZeroDenormal(y);
79 
80  mX2[channel] = mX1[channel];
81  mY2[channel] = mY1[channel];
82  mX1[channel] = x;
83  mY1[channel] = y;
84  return kTTErrNone;
85 }
86 
87 
88 TTErr TTAllpass2a::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
89 {
90  TT_WRAP_CALCULATE_METHOD(calculateValue);
91 }
92 
TTAllpass1b 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.
TTSampleVector mX1
previous input sample (n-1) for each channel
Definition: TTAllpass2a.h:34
TTFloat64 mC1
first coefficient
Definition: TTAllpass2a.h:31
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTFloat64 mC2
second coefficient
Definition: TTAllpass2a.h:32
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
64-bit floating point
Definition: TTBase.h:272
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTSampleVector mX2
previous input sample (n-2) for each channel
Definition: TTAllpass2a.h:35
A simple container for an array of TTAudioSignal pointers.
TTSampleVector mY2
previous output sample (n-2) for each channel
Definition: TTAllpass2a.h:37
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
No Error.
Definition: TTBase.h:343
TTSampleVector mY1
previous output sample (n-1) for each channel
Definition: TTAllpass2a.h:36
[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