Jamoma API  0.6.0.a19
TTAllpass.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTAllpass is a generalized allpass filter wrapper
6  *
7  * @details
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 "TTAllpass.h"
18 
19 #define thisTTClass TTAllpass
20 #define thisTTClassName "allpass"
21 #define thisTTClassTags "dspFilterLib, audio, processor"
22 
23 #ifdef TT_PLATFORM_WIN
24 #include <Algorithm>
25 #endif
26 
27 TT_AUDIO_CONSTRUCTOR,
28  mFilterObject(NULL)
29 {
31 
32  addMessage(clear);
33  addUpdates(SampleRate);
34  addUpdates(MaxNumChannels);
35  addMessageWithArguments(getFilters);
36  addMessageWithArguments(setCoefficients);
37 
38  setAttributeValue(kTTSym_maxNumChannels, arguments);
39  setAttributeValue(TT("filter"), TT("allpass.1a"));
40  setProcessMethod(processAudio);
41 }
42 
43 
44 TTAllpass::~TTAllpass()
45 {
46  delete mFilterObject;
47 }
48 
49 
50 TTErr TTAllpass::setFilter(const TTValue& filter)
51 {
52  TTErr err;
53 
54  mFilter = filter;
56  return err;
57 }
58 
59 
60 TTErr TTAllpass::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
61 {
62  if (mFilterObject)
63  return mFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
64  else
65  return kTTErrNone;
66 }
67 
68 
69 TTErr TTAllpass::setCoefficients(const TTValue& coefficients, TTValue&)
70 {
71  TTErr err = kTTErrGeneric;
72 
73  if (mFilter == TT("allpass.1a") || mFilter == TT("allpass.1b") || mFilter == TT("allpass.1c")) {
74  mFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
75  if (coefficients.size() >= 1) {
76  TTFloat64 alpha;
77 
78  alpha = coefficients[0];
79  err = mFilterObject->setAttributeValue(TT("alpha"), alpha);
80  }
81  }
82  else if (mFilter == TT("allpass.2a") || mFilter == TT("allpass.2b")) {
83  mFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
84  if (coefficients.size() >= 2) {
85  TTFloat64 c1, c2;
86 
87  c1 = coefficients[0];
88  c2 = coefficients[1];
89  err = mFilterObject->setAttributeValue(TT("c1"), c1);
90  err = mFilterObject->setAttributeValue(TT("c2"), c2);
91  }
92  }
93  else if (mFilter == TT("allpass.2c")) {
94  mFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
95  if (coefficients.size() >= 2) {
96  TTFloat64 e1, e2;
97 
98  e1 = coefficients[0];
99  e2 = coefficients[1];
100  err = mFilterObject->setAttributeValue(TT("e1"), e1);
101  err = mFilterObject->setAttributeValue(TT("e2"), e2);
102  }
103  }
104  else if (mFilter == TT("allpass.4a")) {
105  mFilterObject->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
106  if (coefficients.size() >= 4) {
107  TTFloat64 d1, d2, d3, d4;
108 
109  d1 = coefficients[0];
110  d2 = coefficients[1];
111  d3 = coefficients[2];
112  d4 = coefficients[3];
113  err = mFilterObject->setAttributeValue(TT("d1"), d1);
114  err = mFilterObject->setAttributeValue(TT("d2"), d2);
115  err = mFilterObject->setAttributeValue(TT("d3"), d3);
116  err = mFilterObject->setAttributeValue(TT("d4"), d4);
117  }
118  }
119 
120  return err;
121 }
122 
123 
124 TTErr TTAllpass::updateSampleRate(const TTValue& oldSampleRate, TTValue&)
125 {
126  return mFilterObject->setAttributeValue(kTTSym_sampleRate, sr);
127 }
128 
129 
131 {
132  return mFilterObject->sendMessage(TT("clear"));
133 }
134 
135 
136 #if 0
137 #pragma mark -
138 #pragma mark dsp routines
139 #endif
140 
141 
143 {
144  return mFilterObject->calculate(x, y);
145 }
146 
147 
149 {
150  return mFilterObject->process(inputs, outputs);
151 }
152 
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTErr calculateValue(const TTFloat64 &x, TTFloat64 &y, TTPtrSizedInt data)
y = f(x) for a single value
Definition: TTAllpass.cpp:142
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTSymbol mFilter
Name of the filter to use.
Definition: TTAllpass.h:29
size_type size() const noexcept
Return the number of elements.
TTErr calculate(const TTFloat64 &x, TTFloat64 &y)
Calculate a single sample of output for a single sample of input.
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
Filter class.
Definition: Filter.h:22
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
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
TTErr clear()
This algorithm uses an IIR filter, meaning that it relies on feedback.
Definition: TTAllpass.cpp:130
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
A simple container for an array of TTAudioSignal pointers.
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by Jamoma DSP objects.
Definition: TTAllpass.cpp:148
TTAllpass is a generalized allpass filter wrapper
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
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
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTAudioObjectBasePtr mFilterObject
The actual filter object for mFilter.
Definition: TTAllpass.h:30
[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
TTUInt32 sr
Current sample rate being used by this object.