Add TAL-Reverb-II plugin to test
[juce-lv2.git] / tal-reverb-2-juce / src / Engine / ReverbEngine.h
blob212d55d9aca144e171f14982e5df99d5e2c6d620
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(__ReverbEngine_h)
26 #define __ReverbEngine_h
28 #include "Reverb.h"
29 #include "AudioUtils.h"
30 #include "Params.h"
31 #include "ParamChangeUtil.h"
32 #include "NoiseGenerator.h"
34 class ReverbEngine
36 public:
37 float *param;
38 TalReverb* reverb;
40 ParamChangeUtil* dryParamChange;
41 ParamChangeUtil* wetParamChange;
43 NoiseGenerator *noiseGenerator;
45 float dry;
46 float wet;
47 float stereoWidth;
49 AudioUtils audioUtils;
51 ReverbEngine(float sampleRate)
53 Params *params= new Params();
54 this->param= params->parameters;
55 initialize(sampleRate);
58 ~ReverbEngine()
60 delete reverb;
62 delete noiseGenerator;
65 void setDry(float dry)
67 this->dry = audioUtils.getLogScaledVolume(dry, 2.0f);
70 void setWet(float wet)
72 this->wet = audioUtils.getLogScaledVolume(wet, 2.0f);
75 void setDecayTime(float decayTime)
77 reverb->setDecayTime(decayTime);
80 void setPreDelay(float preDelay)
82 reverb->setPreDelay(preDelay);
85 void setLowShelfGain(float lowShelfGain)
87 reverb->setLowShelfGain(lowShelfGain);
90 void setHighShelfGain(float highShelfGain)
92 reverb->setHighShelfGain(highShelfGain);
95 void setLowShelfFrequency(float lowShelfFrequency)
97 reverb->setLowShelfFrequency(lowShelfFrequency);
100 void setHighShelfFrequency(float highShelfFrequency)
102 reverb->setHighShelfFrequency(highShelfFrequency);
105 void setPeakFrequency(float peakFrequency)
107 reverb->setPeakFrequency(peakFrequency);
110 void setPeakGain(float peakGain)
112 reverb->setPeakGain(peakGain);
115 void setStereoWidth(float stereoWidth)
117 this->stereoWidth = stereoWidth;
120 void setStereoMode(float stereoMode)
122 reverb->setStereoMode(stereoMode > 0.0f ? true : false);
125 void setSampleRate(float sampleRate)
127 initialize(sampleRate);
130 void initialize(float sampleRate)
132 if (sampleRate <= 0)
134 sampleRate = 44100.0f;
137 reverb = new TalReverb((int)sampleRate);
139 dryParamChange = new ParamChangeUtil(sampleRate, 300.0f);
140 wetParamChange = new ParamChangeUtil(sampleRate, 300.0f);
142 noiseGenerator = new NoiseGenerator(sampleRate);
144 dry = 1.0f;
145 wet = 0.5f;
146 stereoWidth = 1.0f;
149 void process(float *sampleL, float *sampleR)
151 // avoid cpu spikes
152 float noise = noiseGenerator->tickNoise() * 0.000000001f;
154 *sampleL += noise;
155 *sampleR += noise;
157 float drysampleL = *sampleL;
158 float drysampleR = *sampleR;
160 reverb->process(sampleL, sampleR);
162 // Process Stereo
163 float actualDryValue = dryParamChange->tick(dry);
164 float wet1 = wet * (stereoWidth * 0.5f + 0.5f);
165 float wet2 = wet * ((1.0f - stereoWidth) * 0.5f);
166 float resultL = *sampleL * wet1 + *sampleR * wet2 + drysampleL * actualDryValue;
167 float resultR = *sampleR * wet1 + *sampleL * wet2 + drysampleR * actualDryValue;
168 *sampleL = resultL;
169 *sampleR = resultR;
172 #endif