Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / AllPassFilter.h
blobbf55823dcb0872befc9f6d3932213a38ca5cb452
1 /*
2 ==============================================================================
3 This file is part of Tal-Reverb by Patrick Kunz.
5 Copyright(c) 2005-2009 Patrick Kunz, TAL
6 Togu Audio Line, Inc.
7 http://kunz.corrupt.ch
9 This file may be licensed under the terms of of the
10 GNU General Public License Version 2 (the ``GPL'').
12 Software distributed under the License is distributed
13 on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14 express or implied. See the GPL for the specific language
15 governing rights and limitations.
17 You should have received a copy of the GPL along with this
18 program. If not, go to http://www.gnu.org/licenses/gpl.html
19 or write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ==============================================================================
25 #if !defined(__AllPassFilter_h)
26 #define __AllPassFilter_h
28 #include "Math.h"
29 #include "AudioUtils.h"
31 class AllPassFilter
33 private:
34 float delay, gain;
35 float* buffer;
36 int bufferLength, writePtr, readPtr1, readPtr2;
37 float z1;
39 AudioUtils audioUtils;
41 public:
42 // delay times in milliseconds
43 AllPassFilter(float delayTime, float feedbackGain, long samplingRate)
45 //OutputDebugString("start init allPass");
46 gain = feedbackGain;
47 delay = delayTime;
49 bufferLength = (int)(delay * samplingRate / 1000.0f);
50 bufferLength = audioUtils.getNextNearPrime(bufferLength);
51 buffer = new float[bufferLength];
53 //zero out the buffer (create silence)
54 for (int i = 0; i < bufferLength; i++)
55 buffer[i] = 0.0f;
57 writePtr = readPtr1 = readPtr2 = 0;
58 z1 = 0.0f;
59 //OutputDebugString("end init allPass");
62 ~AllPassFilter()
64 delete buffer;
67 // all values [0..1]
68 inline float processInterpolated(float input, float delayLength, float diffuse, bool negative)
70 // dynamic interpolated
71 float offset = (bufferLength - 2.0f) * delayLength + 1.0f;
72 readPtr1 = writePtr - (int)floorf(offset);
74 if (readPtr1 < 0)
75 readPtr1 += bufferLength;
77 readPtr2 = readPtr1 - 1;
78 if (readPtr2 < 0)
79 readPtr2 += bufferLength;
81 // interpolate, see paper: http://www.stanford.edu/~dattorro/EffectDesignPart2.pdf
82 float frac = offset - (int)floorf(offset);
83 float temp = buffer[readPtr2] + buffer[readPtr1] * (1-frac) - (1-frac) * z1;
84 z1 = temp;
86 float output;
87 if (!negative)
89 buffer[writePtr] = diffuse * gain * temp + input;
90 output = temp - diffuse * gain * buffer[writePtr];
92 else
94 buffer[writePtr] = diffuse * gain * temp - input;
95 output = temp + diffuse * gain * buffer[writePtr];
98 if (++writePtr >= bufferLength)
99 writePtr = 0;
101 return output;
104 inline float process(float input, float diffuse)
106 float temp = buffer[readPtr1];
107 buffer[readPtr1] = diffuse * gain * temp + input;
108 float output = temp - diffuse * gain * buffer[readPtr1];
110 if (++readPtr1 >= bufferLength)
111 readPtr1 = 0;
113 return output;
116 inline float process(float input)
118 float temp = buffer[readPtr1];
119 buffer[readPtr1] = gain * temp + input;
120 float output = temp - gain * buffer[readPtr1];
122 if (++readPtr1 >= bufferLength)
123 readPtr1 = 0;
125 return output;
128 #endif