refactor(amps): shared tremolo helper (dedup across 3 combo amps)

Factor the duplicated unipolar-sine tremolo block out of Fullerton Reverb,
Chime Top Boost, and British Bluesbreaker onboardEffects into one shared
AmpVoicePedal.tremolo(_:speed:depth:enabled:) — signal × LFO over
[1 − depth·enabled, 1], a bit-exact identity when depth·enabled == 0. The 0.5
depth scale is a single named constant on the base. Same expression tree as
before, so no behavior change — the footswitch bit-exact bypass tests and the
full 589-test suite stay green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 13:16:56 -07:00
parent e88db04686
commit a7534a29db
4 changed files with 32 additions and 31 deletions
@@ -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).
@@ -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<Double> = 0.5 ... 12.0
private let intensityRange: ClosedRange<Double> = 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)
}
}
@@ -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<Double> = 0.0 ... 1.0
private let speedRange: ClosedRange<Double> = 0.5 ... 12.0
private let intensityRange: ClosedRange<Double> = 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`
@@ -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<Double> = 0.0 ... 1.0
private let speedRange: ClosedRange<Double> = 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)
}
}