Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / CombFilter.h
blob517930eccd36addc88f0c4dc55914cd8c3ca1543
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(__CombFilter_h)
26 #define __CombFilter_h
28 #include "Math.h"
29 #include "AudioUtils.h"
31 class CombFilter
33 private:
34 float gain, minDamp;
35 float* buffer;
36 int readPtr1, readPtr2, writePtr;
37 float z1;
38 int bufferLengthDelay;
39 float filterStore;
41 AudioUtils audioUtils;
43 public:
44 // delay times in milliseconds
45 CombFilter(float delayTime, float minDamp, long samplingRate)
47 //OutputDebugString("start init combfilter");
48 bufferLengthDelay = (int)(delayTime * samplingRate / 1000);
49 bufferLengthDelay = audioUtils.getNextNearPrime(bufferLengthDelay);
50 buffer = new float[bufferLengthDelay];
52 // Print out samples
53 //File *file = new File("d:/delaytimes.txt");
54 //String myXmlDoc = String((const int)bufferLengthDelay) << "\n";
55 //file->appendText(myXmlDoc);
57 //zero out the buffer (silence)
58 for (int i = 0; i < bufferLengthDelay; i++)
59 buffer[i] = 0.0f;
61 writePtr = 0;
63 //set read pointer to start of buffer
64 readPtr1 = 0;
65 z1 = filterStore = 0.0f;
66 this->minDamp = minDamp;
67 //OutputDebugString("end init combfilter");
70 ~CombFilter()
72 delete buffer;
75 // delayIntensity [0..1]
76 inline float processInterpolated(float input, float damp, float feedback, float delay)
78 float offset = (bufferLengthDelay - 2) * delay + 1.0f;
79 readPtr1 = writePtr - (int)floorf(offset);
81 if (readPtr1 < 0)
82 readPtr1 += bufferLengthDelay;
84 readPtr2 = readPtr1 - 1;
85 if (readPtr2 < 0)
86 readPtr2 += bufferLengthDelay;
88 // interpolate, see paper: http://www.stanford.edu/~dattorro/EffectDesignPart2.pdf
89 float frac = offset - (int)floorf(offset);
90 float output = buffer[readPtr2] + buffer[readPtr1] * (1-frac) - (1-frac) * z1;
91 z1 = output;
93 damp = minDamp * damp;
94 filterStore = output * (1.0f - damp) + filterStore * damp;
95 buffer[writePtr] = input + (filterStore * feedback);
97 if (++writePtr >= bufferLengthDelay)
98 writePtr = 0;
99 return output;
102 inline float process(float input, float damp, float feedback, float delay)
104 float offset = (bufferLengthDelay - 2) * delay + 1.0f;
105 readPtr1 = writePtr - (int)floorf(offset);
107 if (readPtr1 < 0)
108 readPtr1 += bufferLengthDelay;
110 float output = buffer[readPtr1];
111 filterStore = output * (1.0f - damp) + filterStore * damp;
112 buffer[writePtr] = input + (filterStore * feedback);
114 if (++writePtr >= bufferLengthDelay)
115 writePtr = 0;
116 return output;
119 #endif