1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

DSP: Fix Chorus not allocating a large enough DelayLine

This commit is contained in:
attila 2021-06-21 21:44:47 +02:00 committed by Attila Szarvas
parent ecfa339032
commit 7a592bd6c2
2 changed files with 14 additions and 6 deletions

View file

@ -50,7 +50,7 @@ void Chorus<SampleType>::setRate (SampleType newRateHz)
template <typename SampleType>
void Chorus<SampleType>::setDepth (SampleType newDepth)
{
jassert (isPositiveAndNotGreaterThan (newDepth, static_cast<SampleType> (1.0)));
jassert (isPositiveAndNotGreaterThan (newDepth, maxDepth));
depth = newDepth;
update();
@ -59,9 +59,9 @@ void Chorus<SampleType>::setDepth (SampleType newDepth)
template <typename SampleType>
void Chorus<SampleType>::setCentreDelay (SampleType newDelayMs)
{
jassert (isPositiveAndBelow (newDelayMs, static_cast<SampleType> (100.0)));
jassert (isPositiveAndBelow (newDelayMs, maxCentreDelayMs));
centreDelay = jlimit (static_cast<SampleType> (1.0), static_cast<SampleType> (100.0), newDelayMs);
centreDelay = jlimit (static_cast<SampleType> (1.0), maxCentreDelayMs, newDelayMs);
}
template <typename SampleType>
@ -91,6 +91,9 @@ void Chorus<SampleType>::prepare (const ProcessSpec& spec)
sampleRate = spec.sampleRate;
const auto maxPossibleDelay = std::ceil ((maximumDelayModulation * maxDepth * oscVolumeMultiplier + maxCentreDelayMs)
* sampleRate / 1000.0);
delay = DelayLine<SampleType, DelayLineInterpolationTypes::Linear>{ static_cast<int> (maxPossibleDelay) };
delay.prepare (spec);
dryWet.prepare (spec);
@ -123,7 +126,7 @@ template <typename SampleType>
void Chorus<SampleType>::update()
{
osc.setFrequency (rate);
oscVolume.setTargetValue (depth * (SampleType) 0.5);
oscVolume.setTargetValue (depth * oscVolumeMultiplier);
dryWet.setWetMixProportion (mix);
for (auto& vol : feedbackVolume)

View file

@ -148,7 +148,7 @@ private:
//==============================================================================
Oscillator<SampleType> osc;
DelayLine<SampleType, DelayLineInterpolationTypes::Linear> delay { 5000 };
DelayLine<SampleType, DelayLineInterpolationTypes::Linear> delay;
SmoothedValue<SampleType, ValueSmoothingTypes::Linear> oscVolume;
std::vector<SmoothedValue<SampleType, ValueSmoothingTypes::Linear>> feedbackVolume { 2 };
DryWetMixer<SampleType> dryWet;
@ -157,7 +157,12 @@ private:
double sampleRate = 44100.0;
SampleType rate = 1.0, depth = 0.25, feedback = 0.0, mix = 0.5,
centreDelay = 7.0, maximumDelayModulation = 20.0;
centreDelay = 7.0;
static constexpr SampleType maxDepth = 1.0,
maxCentreDelayMs = 100.0,
oscVolumeMultiplier = 0.5,
maximumDelayModulation = 20.0;
};
} // namespace dsp