71 const float wetScaleFactor = 3.0f;
72 const float dryScaleFactor = 2.0f;
74 const float wet = newParams.
wetLevel * wetScaleFactor;
79 gain = isFrozen (newParams.
freezeMode) ? 0.0f : 0.015f;
80 parameters = newParams;
90 jassert (sampleRate > 0);
92 static const short combTunings[] = { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 };
93 static const short allPassTunings[] = { 556, 441, 341, 225 };
94 const int stereoSpread = 23;
95 const int intSampleRate = (int) sampleRate;
97 for (
int i = 0; i < numCombs; ++i)
99 comb[0][i].setSize ((intSampleRate * combTunings[i]) / 44100);
100 comb[1][i].setSize ((intSampleRate * (combTunings[i] + stereoSpread)) / 44100);
103 for (
int i = 0; i < numAllPasses; ++i)
105 allPass[0][i].setSize ((intSampleRate * allPassTunings[i]) / 44100);
106 allPass[1][i].setSize ((intSampleRate * (allPassTunings[i] + stereoSpread)) / 44100);
109 const double smoothTime = 0.01;
110 damping .
reset (sampleRate, smoothTime);
111 feedback.
reset (sampleRate, smoothTime);
112 dryGain .
reset (sampleRate, smoothTime);
113 wetGain1.
reset (sampleRate, smoothTime);
114 wetGain2.
reset (sampleRate, smoothTime);
120 for (
int j = 0; j < numChannels; ++j)
122 for (
int i = 0; i < numCombs; ++i)
125 for (
int i = 0; i < numAllPasses; ++i)
126 allPass[j][i].clear();
132 void processStereo (
float*
const left,
float*
const right,
const int numSamples)
noexcept
134 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6011)
135 jassert (left !=
nullptr && right !=
nullptr);
137 for (
int i = 0; i < numSamples; ++i)
140 const float input = (left[i] + right[i]) * gain;
141 float outL = 0, outR = 0;
146 for (
int j = 0; j < numCombs; ++j)
148 outL += comb[0][j].process (input, damp, feedbck);
149 outR += comb[1][j].process (input, damp, feedbck);
152 for (
int j = 0; j < numAllPasses; ++j)
154 outL = allPass[0][j].process (outL);
155 outR = allPass[1][j].process (outR);
162 left[i] = outL * wet1 + outR * wet2 + left[i] * dry;
163 right[i] = outR * wet1 + outL * wet2 + right[i] * dry;
165 JUCE_END_IGNORE_WARNINGS_MSVC
169 void processMono (
float*
const samples,
const int numSamples)
noexcept
171 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6011)
172 jassert (samples !=
nullptr);
174 for (
int i = 0; i < numSamples; ++i)
176 const float input = samples[i] * gain;
182 for (
int j = 0; j < numCombs; ++j)
183 output += comb[0][j].process (input, damp, feedbck);
185 for (
int j = 0; j < numAllPasses; ++j)
186 output = allPass[0][j].process (output);
191 samples[i] = output * wet1 + samples[i] * dry;
193 JUCE_END_IGNORE_WARNINGS_MSVC
198 static bool isFrozen (
const float freezeMode)
noexcept {
return freezeMode >= 0.5f; }
200 void updateDamping() noexcept
202 const float roomScaleFactor = 0.28f;
203 const float roomOffset = 0.7f;
204 const float dampScaleFactor = 0.4f;
207 setDamping (0.0f, 1.0f);
209 setDamping (parameters.
damping * dampScaleFactor,
210 parameters.
roomSize * roomScaleFactor + roomOffset);
213 void setDamping (
const float dampingToUse,
const float roomSizeToUse)
noexcept
223 CombFilter() noexcept {}
225 void setSize (
const int size)
227 if (size != bufferSize)
230 buffer.malloc (size);
237 void clear() noexcept
240 buffer.clear ((
size_t) bufferSize);
243 float process (
const float input,
const float damp,
const float feedbackLevel)
noexcept
245 const float output = buffer[bufferIndex];
246 last = (output * (1.0f - damp)) + (last * damp);
247 JUCE_UNDENORMALISE (last);
249 float temp = input + (last * feedbackLevel);
250 JUCE_UNDENORMALISE (temp);
251 buffer[bufferIndex] = temp;
252 bufferIndex = (bufferIndex + 1) % bufferSize;
257 HeapBlock<float> buffer;
258 int bufferSize = 0, bufferIndex = 0;
261 JUCE_DECLARE_NON_COPYABLE (CombFilter)
268 AllPassFilter() noexcept {}
270 void setSize (
const int size)
272 if (size != bufferSize)
275 buffer.malloc (size);
282 void clear() noexcept
284 buffer.clear ((
size_t) bufferSize);
287 float process (
const float input)
noexcept
289 const float bufferedValue = buffer [bufferIndex];
290 float temp = input + (bufferedValue * 0.5f);
291 JUCE_UNDENORMALISE (temp);
292 buffer [bufferIndex] = temp;
293 bufferIndex = (bufferIndex + 1) % bufferSize;
294 return bufferedValue - input;
298 HeapBlock<float> buffer;
299 int bufferSize = 0, bufferIndex = 0;
301 JUCE_DECLARE_NON_COPYABLE (AllPassFilter)
305 enum { numCombs = 8, numAllPasses = 4, numChannels = 2 };
307 Parameters parameters;
310 CombFilter comb [numChannels][numCombs];
311 AllPassFilter allPass [numChannels][numAllPasses];
313 SmoothedValue<float> damping, feedback, dryGain, wetGain1, wetGain2;
315 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Reverb)
void processMono(float *const samples, const int numSamples) noexcept
void processStereo(float *const left, float *const right, const int numSamples) noexcept
void setParameters(const Parameters &newParams)
const Parameters & getParameters() const noexcept
void setSampleRate(const double sampleRate)
FloatType getNextValue() noexcept
void reset(double sampleRate, double rampLengthInSeconds) noexcept
void setTargetValue(FloatType newValue) noexcept