From bfffe36602cb97400164b96fede6d53dbca16a67 Mon Sep 17 00:00:00 2001 From: KottV Date: Thu, 27 Mar 2025 14:54:33 -0700 Subject: [PATCH 1/4] Smooth oscillators' gain --- modules/gin_dsp/dsp/gin_oscillators.h | 19 ++++++++++-- modules/gin_dsp/dsp/gin_wtoscillators.h | 41 +++++++++++++++++-------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/modules/gin_dsp/dsp/gin_oscillators.h b/modules/gin_dsp/dsp/gin_oscillators.h index 3e083d7fe23..7da23f4cd8e 100644 --- a/modules/gin_dsp/dsp/gin_oscillators.h +++ b/modules/gin_dsp/dsp/gin_oscillators.h @@ -27,7 +27,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) @@ -47,11 +56,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) @@ -76,6 +88,7 @@ class StereoOscillator BandLimitedLookupTables& bllt; double sampleRate = 44100.0; float phase = 0.0f; + juce::SmoothedValue leftGain, rightGain; }; struct VoicedOscillatorParams diff --git a/modules/gin_dsp/dsp/gin_wtoscillators.h b/modules/gin_dsp/dsp/gin_wtoscillators.h index a161188db41..43280f3a45a 100644 --- a/modules/gin_dsp/dsp/gin_wtoscillators.h +++ b/modules/gin_dsp/dsp/gin_wtoscillators.h @@ -80,6 +80,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); @@ -138,6 +144,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) { @@ -148,8 +157,8 @@ class WTOscillator auto s = table->processLinear (note, math::min (almostOne, phaseVec)); postProcess (params, s); - lVec += s * params.leftGain; - rVec += s * params.rightGain; + lVec += s * leftGain.getNextValue(); + rVec += s * rightGain.getNextValue(); lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -163,8 +172,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; } @@ -199,6 +208,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) @@ -210,8 +222,8 @@ class WTOscillator auto s = table->processLinear (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant)); postProcess (params, s); - lVec += s * params.leftGain; - rVec += s * params.rightGain; + lVec += s * leftGain.getNextValue(); + rVec += s * rightGain.getNextValue(); lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -225,8 +237,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; } @@ -265,6 +277,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) @@ -279,8 +294,8 @@ class WTOscillator auto s = s1 * phase + s2 * (1.0f - phase); postProcess (params, s); - lVec += s * params.leftGain; - rVec += s * params.rightGain; + lVec += s * leftGain.getNextValue(); + rVec += s * rightGain.getNextValue(); lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -297,8 +312,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; } @@ -378,6 +393,8 @@ class WTOscillator DCBlocker blockerL; DCBlocker blockerR; + juce::SmoothedValue leftGain, rightGain; + static constexpr float almostOne = { 1.0f - std::numeric_limits::epsilon() }; }; From 2bd63ae8699d351fef11986775f19b1655d8bd03 Mon Sep 17 00:00:00 2001 From: KottV Date: Thu, 27 Mar 2025 22:09:55 -0700 Subject: [PATCH 2/4] Don't touch SIMD parts in wtoscillator --- modules/gin_dsp/dsp/gin_wtoscillators.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/gin_dsp/dsp/gin_wtoscillators.h b/modules/gin_dsp/dsp/gin_wtoscillators.h index 43280f3a45a..63f25f1fce8 100644 --- a/modules/gin_dsp/dsp/gin_wtoscillators.h +++ b/modules/gin_dsp/dsp/gin_wtoscillators.h @@ -157,8 +157,8 @@ class WTOscillator auto s = table->processLinear (note, math::min (almostOne, phaseVec)); postProcess (params, s); - lVec += s * leftGain.getNextValue(); - rVec += s * rightGain.getNextValue(); + lVec += s * params.leftGain; + rVec += s * params.rightGain; lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -222,9 +222,8 @@ class WTOscillator auto s = table->processLinear (note, phaseDistortion (math::min (almostOne, phaseVec), params.bend, params.formant)); postProcess (params, s); - lVec += s * leftGain.getNextValue(); - rVec += s * rightGain.getNextValue(); - + lVec += s * params.leftGain; + rVec += s * params.rightGain; lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -294,9 +293,8 @@ class WTOscillator auto s = s1 * phase + s2 * (1.0f - phase); postProcess (params, s); - lVec += s * leftGain.getNextValue(); - rVec += s * rightGain.getNextValue(); - + lVec += s * params.leftGain; + rVec += s * params.rightGain; lVec.store (l); l += 4; rVec.store (r); r += 4; From 80273914924b79b252289d7b6cfde44ea515fce3 Mon Sep 17 00:00:00 2001 From: KottV Date: Thu, 27 Mar 2025 22:14:05 -0700 Subject: [PATCH 3/4] Empty line --- modules/gin_dsp/dsp/gin_wtoscillators.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/gin_dsp/dsp/gin_wtoscillators.h b/modules/gin_dsp/dsp/gin_wtoscillators.h index 63f25f1fce8..071695397a7 100644 --- a/modules/gin_dsp/dsp/gin_wtoscillators.h +++ b/modules/gin_dsp/dsp/gin_wtoscillators.h @@ -224,6 +224,7 @@ class WTOscillator lVec += s * params.leftGain; rVec += s * params.rightGain; + lVec.store (l); l += 4; rVec.store (r); r += 4; @@ -295,6 +296,7 @@ class WTOscillator lVec += s * params.leftGain; rVec += s * params.rightGain; + lVec.store (l); l += 4; rVec.store (r); r += 4; From f3be8f789d0db8aa7330fb8ca0c2736853c46d3b Mon Sep 17 00:00:00 2001 From: KottV Date: Thu, 27 Mar 2025 22:15:17 -0700 Subject: [PATCH 4/4] Empty line --- modules/gin_dsp/dsp/gin_wtoscillators.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gin_dsp/dsp/gin_wtoscillators.h b/modules/gin_dsp/dsp/gin_wtoscillators.h index 071695397a7..26e4043d2b9 100644 --- a/modules/gin_dsp/dsp/gin_wtoscillators.h +++ b/modules/gin_dsp/dsp/gin_wtoscillators.h @@ -296,7 +296,7 @@ class WTOscillator lVec += s * params.leftGain; rVec += s * params.rightGain; - + lVec.store (l); l += 4; rVec.store (r); r += 4;