Jamoma API  0.6.0.a19
TTHilbertLinear33.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspFilterLib
4  *
5  * @brief #TTHilbertLinear33 is a 33rd-order Hilbert Transform filter built up from a 2-path allpass structure with linear phase relationship to the input signal.
6  *
7  * @details See notes on TTHilbert9 for information about the structure of this filter. @n
8  * @n
9  * See notes on TTHalfband33 for information regarding coefficient calculations, remembering that we need to flip signs to perform the Hilbert Transform. Note however, that we flip signs for the Z^(-2) terms because i^2 = -1. The caveat is that in this filter we also have Z^(-4) terms in the second-order allpass filters, and i^4 = 1, meaning we don't flip those signs. This may seem obvious after reading this, however it is easy to miss, especially as the general rule is stated as "flip all of the signs".
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 "TTHilbertLinear33.h"
20 
21 #define thisTTClass TTHilbertLinear33
22 #define thisTTClassName "hilbert.linear.33"
23 #define thisTTClassTags "dspFilterLib, audio, processor, hilbert"
24 // no "filter" tag because this is a special case that produces two outputs for one input and doesn't fit the general filter schema
25 
26 #ifdef TT_PLATFORM_WIN
27 #include <Algorithm>
28 #endif
29 
30 TT_AUDIO_CONSTRUCTOR,
31  mP0Delay("delay"),
32  mP1Delay("allpass.1a"),
33  mF0("allpass.1b"),
34  mF1("allpass.1b"),
35  mF2("allpass.2b"),
36  mF3("allpass.2b"),
37  mF4("allpass.2b")
38 {
39  TTChannelCount initialMaxNumChannels = arguments;
40 
41  addMessage(clear);
42  addUpdates(MaxNumChannels);
43 
44  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
45 
46  mP0Delay.set(TT("delayMaxInSamples"), 16);
47  mP0Delay.set(TT("delayInSamples"), 16);
48 
49  mP1Delay.set(TT("alpha"), 0.0);
50  mF0.set(TT("alpha"), -0.8323021656083688);
51  mF1.set(TT("alpha"), 0.4212854250030528);
52  mF2.set(TT("c1"), -0.6763427968689864);
53  mF2.set(TT("c2"), 0.2319808172827758);
54  mF3.set(TT("c1"), -0.003589671833320152);
55  mF3.set(TT("c2"), 0.1916472793306732);
56  mF4.set(TT("c1"), 0.59696896155334);
57  mF4.set(TT("c2"), 0.1802094400534031);
58 
59  setProcessMethod(processAudio);
60 }
61 
62 
63 TTHilbertLinear33::~TTHilbertLinear33()
64 {
65 }
66 
67 
68 TTErr TTHilbertLinear33::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
69 {
70  mF0.set(kTTSym_maxNumChannels, mMaxNumChannels);
71  mF1.set(kTTSym_maxNumChannels, mMaxNumChannels);
72  mF2.set(kTTSym_maxNumChannels, mMaxNumChannels);
73  mF3.set(kTTSym_maxNumChannels, mMaxNumChannels);
74  mF4.set(kTTSym_maxNumChannels, mMaxNumChannels);
75  mP0Delay.set(kTTSym_maxNumChannels, mMaxNumChannels);
76  mP1Delay.set(kTTSym_maxNumChannels, mMaxNumChannels);
77 
78  clear();
79  return kTTErrNone;
80 }
81 
82 
83 TTErr TTHilbertLinear33::clear()
84 {
85  mF0.send(kTTSym_clear);
86  mF1.send(kTTSym_clear);
87  mF2.send(kTTSym_clear);
88  mF3.send(kTTSym_clear);
89  mF4.send(kTTSym_clear);
90  mP0Delay.send(kTTSym_clear);
91  mP1Delay.send(kTTSym_clear);
92  return kTTErrNone;
93 }
94 
95 
96 inline void TTHilbertLinear33::filterKernel(const TTFloat64& input, TTFloat64& outputPath0, TTFloat64& outputPath1, TTPtrSizedInt channel)
97 {
98  TTFloat64 temp1, temp2;
99 
100  TTBASE(mP0Delay, TTDelay)->calculateNoInterpolation(input, outputPath0, channel);
101 
102  TTBASE(mP1Delay, TTAllpass1a)->calculateValue(input, temp2, channel);
103  TTBASE(mF0, TTAllpass1b)->calculateValue(temp2, temp1, channel);
104  TTBASE(mF1, TTAllpass1b)->calculateValue(temp1, temp2, channel);
105  TTBASE(mF2, TTAllpass2b)->calculateValue(temp2, temp1, channel);
106  TTBASE(mF3, TTAllpass2b)->calculateValue(temp1, temp2, channel);
107  TTBASE(mF4, TTAllpass2b)->calculateValue(temp2, outputPath1, channel);
108 }
109 
110 
111 TTErr TTHilbertLinear33::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
112 {
113  TTAudioSignal& in = inputs->getSignal(0);
114  TTAudioSignal& outReal = outputs->getSignal(0);
115  TTAudioSignal& outImaginary = outputs->getSignal(1);
116  TTSampleValue* inSample;
117  TTSampleValue* outRealSample;
118  TTSampleValue* outImaginarySample;
119  TTChannelCount numChannels = TTAudioSignal::getMinChannelCount(in, outReal, outImaginary);
120  TTPtrSizedInt channel;
121  TTUInt16 n;
122 
123  for (channel=0; channel<numChannels; channel++) {
124  n = in.getVectorSizeAsInt();
125 
126  inSample = in.mSampleVectors[channel];
127  outRealSample = outReal.mSampleVectors[channel];
128  outImaginarySample = outImaginary.mSampleVectors[channel];
129 
130  while (n--) {
131  filterKernel(*inSample++, *outRealSample++, *outImaginarySample++, channel);
132  }
133  }
134  return kTTErrNone;
135 }
136 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTAudioObject mF4
path1
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
TTAudioObject mP1Delay
path1
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTHilbertLinear33 is a 33rd-order Hilbert Transform filter built up from a 2-path allpass structure w...
#define TTBASE(instance_, class_)
Macro to access the actual C++ class that is contained inside of the TTObject as a pointer...
Definition: TTObject.h:211
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTAudioObject mF2
path1
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTAudioObject mF1
path1
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
A first-order building-block allpass filter.
Definition: TTAllpass1a.h:25
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTAudioObject mF3
path1
TTAudioObject mF0
path1
A simple container for an array of TTAudioSignal pointers.
Delay a signal.
Definition: TTDelay.h:22
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
A first-order building-block allpass filter.
Definition: TTAllpass1b.h:25
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
A second-order Z^2 building-block allpass filter.
Definition: TTAllpass2b.h:27
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
No Error.
Definition: TTBase.h:343
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTAudioObject mP0Delay
path0, pure delay, 16 samples
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44