diff --git a/modules/gin_dsp/dsp/gin_oscillators.h b/modules/gin_dsp/dsp/gin_oscillators.h index 169b460e23..92f0af770d 100644 --- a/modules/gin_dsp/dsp/gin_oscillators.h +++ b/modules/gin_dsp/dsp/gin_oscillators.h @@ -64,7 +64,16 @@ class StereoOscillator float asym = 0.0f; }; - void setSampleRate (double sr) { sampleRate = sr; } + void setSampleRate (double sr) + { + sampleRate = sr; + + if (sampleRate > 0) + { + leftGain.reset(sampleRate, 0.05); + rightGain.reset(sampleRate, 0.05); + } + } void noteOn (float p = -1); void process (float note, const Params& params, juce::AudioSampleBuffer& buffer) @@ -84,11 +93,14 @@ class StereoOscillator for (int i = 0; i < samps; i++) { + leftGain.setTargetValue(params.leftGain); + rightGain.setTargetValue(params.rightGain); + auto s = bllt.process (params.wave, note, phase, params.pw); postProcess (params, s); - *l++ += s * params.leftGain; - *r++ += s * params.rightGain; + *l++ += s * leftGain.getNextValue(); + *r++ += s * rightGain.getNextValue(); phase += delta; while (phase >= 1.0f) @@ -113,6 +125,7 @@ class StereoOscillator BandLimitedLookupTables& bllt; double sampleRate = 44100.0; float phase = 0.0f; + juce::SmoothedValue leftGain, rightGain; }; /** diff --git a/modules/gin_dsp/dsp/gin_wtoscillators.h b/modules/gin_dsp/dsp/gin_wtoscillators.h index 984a3192ad..c7d91ba1f5 100644 --- a/modules/gin_dsp/dsp/gin_wtoscillators.h +++ b/modules/gin_dsp/dsp/gin_wtoscillators.h @@ -73,6 +73,12 @@ class WTOscillator blockerR.setSampleRate (float (sr)); blockerL.setCutoff (10.0f); blockerR.setCutoff (10.0f); + + if (sampleRate > 0) + { + leftGain.reset(sampleRate, 0.05); + rightGain.reset(sampleRate, 0.05); + } } void noteOn (float p = -1); @@ -131,6 +137,9 @@ class WTOscillator auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1); samps -= todo; + leftGain.setTargetValue(params.leftGain); + rightGain.setTargetValue(params.rightGain); + #if GIN_HAS_SIMD for (; todo >= 4; todo -= 4) { @@ -156,8 +165,8 @@ class WTOscillator auto s = table->processLinear (note, std::min (almostOne, phase)); postProcess (params, s); - *l++ += s * params.leftGain; - *r++ += s * params.rightGain; + *l++ += s * leftGain.getNextValue(); + *r++ += s * rightGain.getNextValue(); phase += delta; } @@ -192,6 +201,9 @@ class WTOscillator { auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1); samps -= todo; + + leftGain.setTargetValue(params.leftGain); + rightGain.setTargetValue(params.rightGain); #if GIN_HAS_SIMD for (; todo >= 4; todo -= 4) @@ -205,7 +217,7 @@ class WTOscillator lVec += s * params.leftGain; rVec += s * params.rightGain; - + lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -218,8 +230,8 @@ class WTOscillator auto s = table->processLinear (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant)); postProcess (params, s); - *l++ += s * params.leftGain; - *r++ += s * params.rightGain; + *l++ += s * leftGain.getNextValue(); + *r++ += s * rightGain.getNextValue(); phase += delta; } @@ -258,6 +270,9 @@ class WTOscillator { auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1); samps -= todo; + + leftGain.setTargetValue(params.leftGain); + rightGain.setTargetValue(params.rightGain); #if GIN_HAS_SIMD for (; todo >= 4; todo -= 4) @@ -290,8 +305,8 @@ class WTOscillator auto s = s1 * phase + s2 * (1.0f - phase); postProcess (params, s); - *l++ += s * params.leftGain; - *r++ += s * params.rightGain; + *l++ += s * leftGain.getNextValue(); + *r++ += s * rightGain.getNextValue(); phase += delta; } @@ -371,6 +386,8 @@ class WTOscillator DCBlocker blockerL; DCBlocker blockerR; + juce::SmoothedValue leftGain, rightGain; + static constexpr float almostOne = { 1.0f - std::numeric_limits::epsilon() }; };