diff --git a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift index 3963e0c..2ca6acc 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift @@ -85,6 +85,32 @@ open class AmpVoicePedal: Pedal { signal } + /// Depth scale for the shared ``tremolo(_:speed:depth:enabled:)`` helper — at full depth the + /// unipolar sine swings over half the normalised range, so the peak gain is `1.0` and the trough + /// is `1 − depth`. + private static let tremoloDepthScale: Double = 0.5 + + /// A unipolar-sine tremolo: `signal ×` an LFO over `[1 − depth·enabled, 1]`. Returns a bit-exact + /// pass-through (a constant-`1.0` LFO) when `depth·enabled == 0`, so a zeroed depth or a + /// footswitch `enabled = 0` is a true identity. Shared by the combo amps' `onboardEffects(_:)`. + /// + /// - Parameters: + /// - signal: The signal to amplitude-modulate. + /// - speed: LFO rate in Hz. + /// - depth: Modulation depth in `[0, 1]`. + /// - enabled: Footswitch gate (`0` or `1`) multiplied into the depth. + /// - Returns: The amplitude-modulated signal. + func tremolo( + _ signal: any ValidGeneratorInput, + speed: any ValidGeneratorInput, + depth: any ValidGeneratorInput, + enabled: any ValidGeneratorInput + ) -> any ValidGeneratorInput { + let swing: any ValidGeneratorInput = (depth * enabled) * AmpVoicePedal.tremoloDepthScale + let lfo: OscSin.Audio = OscSin.Audio(freq: speed, mul: swing, add: 1.0 - swing) + return signal * lfo + } + /// The preamp gain stage — the (post-`inputShaping`) input driven through the first tube stage /// at `Gain`. Default: one `TriodeStage`. A channel-switching amp overrides this to cascade an /// extra stage on its drive channel (call `super.preampStage(_:)` for the clean stage first). diff --git a/Sources/LyrebirdShoeGaze/Pedals/BritishBluesbreakerAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/BritishBluesbreakerAmpPedal.swift index 06c2404..2a8832e 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/BritishBluesbreakerAmpPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/BritishBluesbreakerAmpPedal.swift @@ -21,9 +21,6 @@ public final class BritishBluesbreakerAmpPedal: BritishComboAmpPedal { /// Tremolo footswitch: `1` = engaged, `0` = bypassed (`Speed`/`Intensity` preserved). @UIParam public var tremoloEnabled: Double = 1.0 - /// Tremolo depth scaling — at full `intensity` the LFO swings over half the normalised range so - /// the peak gain is 1.0 and the trough is `1 − intensity`. - private let tremoloDepthScale: Double = 0.5 private let speedRange: ClosedRange = 0.5 ... 12.0 private let intensityRange: ClosedRange = 0.0 ... 1.0 @@ -69,12 +66,7 @@ public final class BritishBluesbreakerAmpPedal: BritishComboAmpPedal { /// Tremolo (gated by the Tremolo footswitch), inserted after the tone stack. public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { - // Footswitch gates depth to 0 → LFO is a constant 1.0 (identity). Unipolar sine over - // [1 − depth, 1]: peak gain 1.0, trough 1 − depth. - let depth: any ValidGeneratorInput = $intensity * $tremoloEnabled - let lfoScale: any ValidGeneratorInput = depth * tremoloDepthScale - let lfoOffset: any ValidGeneratorInput = 1.0 - (depth * tremoloDepthScale) - let lfo: OscSin.Audio = OscSin.Audio(freq: $speed, mul: lfoScale, add: lfoOffset) - return signal * lfo + // Identity when depth·enabled == 0. + tremolo(signal, speed: $speed, depth: $intensity, enabled: $tremoloEnabled) } } diff --git a/Sources/LyrebirdShoeGaze/Pedals/ChimeTopBoostAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/ChimeTopBoostAmpPedal.swift index d48d3a9..c41d73a 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/ChimeTopBoostAmpPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/ChimeTopBoostAmpPedal.swift @@ -47,10 +47,6 @@ public final class ChimeTopBoostAmpPedal: AmpVoicePedal { private let brilliantMaxGainDb: Double = 6.0 /// Brilliant-switch shelf slope. private let brilliantSlope: Double = 0.7 - /// Tremolo depth scaling — at full `intensity` the LFO swings over half the normalised range so - /// the peak gain is 1.0 and the trough is `1 − intensity`. - private let tremoloDepthScale: Double = 0.5 - private let cutRange: ClosedRange = 0.0 ... 1.0 private let speedRange: ClosedRange = 0.5 ... 12.0 private let intensityRange: ClosedRange = 0.0 ... 1.0 @@ -121,13 +117,8 @@ public final class ChimeTopBoostAmpPedal: AmpVoicePedal { /// Tremolo (gated by the Tremolo footswitch), inserted after the tone stack. No onboard reverb. public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { - // Footswitch gates depth to 0 → LFO is a constant 1.0 (identity). Unipolar sine over - // [1 − depth, 1]: peak gain 1.0, trough 1 − depth. - let depth: any ValidGeneratorInput = $intensity * $tremoloEnabled - let lfoScale: any ValidGeneratorInput = depth * tremoloDepthScale - let lfoOffset: any ValidGeneratorInput = 1.0 - (depth * tremoloDepthScale) - let lfo: OscSin.Audio = OscSin.Audio(freq: $speed, mul: lfoScale, add: lfoOffset) - return signal * lfo + // Tremolo gated by the Tremolo footswitch (identity when depth·enabled == 0). + tremolo(signal, speed: $speed, depth: $intensity, enabled: $tremoloEnabled) } /// Cut control: a low-pass whose cutoff sweeps from `cutOpenHz` (bright) down to `cutDarkHz` diff --git a/Sources/LyrebirdShoeGaze/Pedals/FullertonReverbAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/FullertonReverbAmpPedal.swift index e13cda0..6842163 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/FullertonReverbAmpPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/FullertonReverbAmpPedal.swift @@ -49,9 +49,6 @@ open class FullertonReverbAmpPedal: AmpVoicePedal { private let brightMaxGainDb: Double = 6.0 /// Bright-switch shelf slope. private let brightSlope: Double = 0.8 - /// Tremolo depth scaling — at full `intensity` the LFO swings over half the normalised range so - /// the peak gain is 1.0 and the trough is `1 − intensity`. - private let tremoloDepthScale: Double = 0.5 private let reverbRange: ClosedRange = 0.0 ... 1.0 private let speedRange: ClosedRange = 0.5 ... 12.0 @@ -142,12 +139,7 @@ open class FullertonReverbAmpPedal: AmpVoicePedal { let reverbMix: any ValidGeneratorInput = $reverb * $reverbEnabled let reverbed: SpringReverb.Audio = SpringReverb.Audio( input: signal, mix: reverbMix, sampleRate: sampleRate) - // Footswitch gates depth to 0 → LFO is a constant 1.0. Unipolar sine over [1 − depth, 1]: - // peak gain 1.0, trough 1 − depth. - let depth: any ValidGeneratorInput = $intensity * $vibratoEnabled - let lfoScale: any ValidGeneratorInput = depth * tremoloDepthScale - let lfoOffset: any ValidGeneratorInput = 1.0 - (depth * tremoloDepthScale) - let lfo: OscSin.Audio = OscSin.Audio(freq: $speed, mul: lfoScale, add: lfoOffset) - return reverbed * lfo + // Tremolo gated by the vibrato footswitch (identity when depth·enabled == 0). + return tremolo(reverbed, speed: $speed, depth: $intensity, enabled: $vibratoEnabled) } }