25 #ifndef JUCE_REVERB_H_INCLUDED 26 #define JUCE_REVERB_H_INCLUDED 81 const float wetScaleFactor = 3.0f;
82 const float dryScaleFactor = 2.0f;
84 const float wet = newParams.
wetLevel * wetScaleFactor;
85 dryGain.setValue (newParams.
dryLevel * dryScaleFactor);
86 wetGain1.setValue (0.5f * wet * (1.0f + newParams.
width));
87 wetGain2.setValue (0.5f * wet * (1.0f - newParams.
width));
89 gain = isFrozen (newParams.
freezeMode) ? 0.0f : 0.015f;
90 parameters = newParams;
102 static const short combTunings[] = { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 };
103 static const short allPassTunings[] = { 556, 441, 341, 225 };
104 const int stereoSpread = 23;
105 const int intSampleRate = (int) sampleRate;
107 for (
int i = 0; i < numCombs; ++i)
109 comb[0][i].setSize ((intSampleRate * combTunings[i]) / 44100);
110 comb[1][i].setSize ((intSampleRate * (combTunings[i] + stereoSpread)) / 44100);
113 for (
int i = 0; i < numAllPasses; ++i)
115 allPass[0][i].setSize ((intSampleRate * allPassTunings[i]) / 44100);
116 allPass[1][i].setSize ((intSampleRate * (allPassTunings[i] + stereoSpread)) / 44100);
119 const double smoothTime = 0.01;
120 damping .reset (sampleRate, smoothTime);
121 feedback.reset (sampleRate, smoothTime);
122 dryGain .reset (sampleRate, smoothTime);
123 wetGain1.reset (sampleRate, smoothTime);
124 wetGain2.reset (sampleRate, smoothTime);
130 for (
int j = 0; j < numChannels; ++j)
132 for (
int i = 0; i < numCombs; ++i)
135 for (
int i = 0; i < numAllPasses; ++i)
136 allPass[j][i].clear();
144 jassert (left !=
nullptr && right !=
nullptr);
146 for (
int i = 0; i < numSamples; ++i)
148 const float input = (left[i] + right[i]) * gain;
149 float outL = 0, outR = 0;
151 const float damp =
damping.getNextValue();
152 const float feedbck = feedback.getNextValue();
154 for (
int j = 0; j < numCombs; ++j)
156 outL += comb[0][j].process (input, damp, feedbck);
157 outR += comb[1][j].process (input, damp, feedbck);
160 for (
int j = 0; j < numAllPasses; ++j)
162 outL = allPass[0][j].process (outL);
163 outR = allPass[1][j].process (outR);
166 const float dry = dryGain.getNextValue();
167 const float wet1 = wetGain1.getNextValue();
168 const float wet2 = wetGain2.getNextValue();
170 left[i] = outL * wet1 + outR * wet2 + left[i] * dry;
171 right[i] = outR * wet1 + outL * wet2 + right[i] * dry;
180 for (
int i = 0; i < numSamples; ++i)
182 const float input = samples[i] * gain;
185 const float damp =
damping.getNextValue();
186 const float feedbck = feedback.getNextValue();
188 for (
int j = 0; j < numCombs; ++j)
189 output += comb[0][j].process (input, damp, feedbck);
191 for (
int j = 0; j < numAllPasses; ++j)
192 output = allPass[0][j].process (output);
194 const float dry = dryGain.getNextValue();
195 const float wet1 = wetGain1.getNextValue();
197 samples[i] = output * wet1 + samples[i] * dry;
207 const float roomScaleFactor = 0.28f;
208 const float roomOffset = 0.7f;
209 const float dampScaleFactor = 0.4f;
211 if (isFrozen (parameters.freezeMode))
212 setDamping (0.0f, 1.0f);
214 setDamping (parameters.damping * dampScaleFactor,
215 parameters.roomSize * roomScaleFactor + roomOffset);
218 void setDamping (
const float dampingToUse,
const float roomSizeToUse)
noexcept 220 damping.setValue (dampingToUse);
221 feedback.setValue (roomSizeToUse);
228 CombFilter()
noexcept : bufferSize (0), bufferIndex (0), last (0) {}
230 void setSize (
const int size)
232 if (size != bufferSize)
235 buffer.malloc ((
size_t) size);
245 buffer.clear ((
size_t) bufferSize);
248 float process (
const float input,
const float damp,
const float feedbackLevel)
noexcept 250 const float output =
buffer[bufferIndex];
251 last = (output * (1.0f - damp)) + (last * damp);
254 float temp = input + (last * feedbackLevel);
256 buffer[bufferIndex] = temp;
257 bufferIndex = (bufferIndex + 1) % bufferSize;
263 int bufferSize, bufferIndex;
273 AllPassFilter()
noexcept : bufferSize (0), bufferIndex (0) {}
275 void setSize (
const int size)
277 if (size != bufferSize)
280 buffer.malloc ((
size_t) size);
289 buffer.clear ((
size_t) bufferSize);
292 float process (
const float input)
noexcept 294 const float bufferedValue =
buffer [bufferIndex];
295 float temp = input + (bufferedValue * 0.5f);
297 buffer [bufferIndex] = temp;
298 bufferIndex = (bufferIndex + 1) % bufferSize;
299 return bufferedValue - input;
304 int bufferSize, bufferIndex;
310 class LinearSmoothedValue
314 : currentValue (0), target (0), step (0), countdown (0), stepsToTarget (0)
318 void reset (
double sampleRate,
double fadeLengthSeconds)
noexcept 320 jassert (sampleRate > 0 && fadeLengthSeconds >= 0);
321 stepsToTarget = (int) std::floor (fadeLengthSeconds * sampleRate);
322 currentValue = target;
326 void setValue (
float newValue)
noexcept 328 if (target != newValue)
331 countdown = stepsToTarget;
334 currentValue = target;
336 step = (target - currentValue) / (
float) countdown;
346 currentValue += step;
351 float currentValue, target, step;
352 int countdown, stepsToTarget;
358 enum { numCombs = 8, numAllPasses = 4, numChannels = 2 };
363 CombFilter comb [numChannels][numCombs];
364 AllPassFilter allPass [numChannels][numAllPasses];
366 LinearSmoothedValue
damping, feedback, dryGain, wetGain1, wetGain2;
372 #endif // JUCE_REVERB_H_INCLUDED float freezeMode
Definition: juce_Reverb.h:67
float damping
Definition: juce_Reverb.h:63
Reverb()
Definition: juce_Reverb.h:43
void processMono(float *const samples, const int numSamples) noexcept
Definition: juce_Reverb.h:176
#define noexcept
Definition: juce_CompilerSupport.h:141
Parameters() noexcept
Definition: juce_Reverb.h:53
void processStereo(float *const left, float *const right, const int numSamples) noexcept
Definition: juce_Reverb.h:142
#define JUCE_UNDENORMALISE(x)
JOCTET * buffer
Definition: juce_JPEGLoader.cpp:302
float roomSize
Definition: juce_Reverb.h:62
Definition: juce_Reverb.h:39
float width
Definition: juce_Reverb.h:66
void setParameters(const Parameters &newParams)
Definition: juce_Reverb.h:79
void reset()
Definition: juce_Reverb.h:128
float wetLevel
Definition: juce_Reverb.h:64
Definition: juce_HeapBlock.h:90
Definition: juce_Reverb.h:51
const Parameters & getParameters() const noexcept
Definition: juce_Reverb.h:73
void setSampleRate(const double sampleRate)
Definition: juce_Reverb.h:98
float dryLevel
Definition: juce_Reverb.h:65