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).