Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / Filter.h
blobefb94b2488d0b7a62f91a349f502f1b98f77333f
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(__Filter_h)
26 #define __Filter_h
28 #include "Math.h"
30 class Filter
32 private:
33 float f, k, p, scale, r, x;
34 float y1, y2, y3, y4, oldx, oldy1, oldy2, oldy3;
35 float fCutoff, fActualCutoff;
36 float Pi;
38 float sampleRateFactor;
40 public:
42 Filter(float sampleRate)
44 Pi = 3.141592653f;
45 y1 = y2 = y3 = y4 = oldx = oldy1 = oldy2 = oldy3 = 0.0f;
47 if (sampleRate <= 0.0f) sampleRate = 44100.0f;
49 sampleRateFactor= 44100.0f / sampleRate;
50 if (sampleRateFactor > 1.0f)
51 sampleRateFactor = 1.0f;
53 fActualCutoff = -1.0f;
56 inline float process(float input, float fCutoff, float fRes, bool highPass)
58 if (fCutoff != fActualCutoff)
60 fActualCutoff = fCutoff;
61 fCutoff *= sampleRateFactor;
62 updateValues(fCutoff * fCutoff);
64 x = input;
66 // Four cascaded onepole filters (bilinear transform)
67 y1 = (x + oldx) * p - k * y1;
68 y2 = (y1 + oldy1) * p - k * y2;
70 // Save values
71 oldx = x;
72 oldy1 = y1;
73 if (highPass) input = input - y2;
74 else input = y2;
75 return input;
78 void updateValues(float fCutoff)
80 // Filter section MOOG VCF
81 // CSound source code, Stilson/Smith CCRMA paper.
82 f = fCutoff; // [0 - 1]
83 k = 3.6f * f - 1.6f * f * f - 1.0f; // (Empirical tunning) /// !!! original (convex)
85 p = (k + 1.0f) * 0.5f; // scale [0, 1]
86 scale = expf((1.0f - p) * 1.386249f); // original
89 #endif