Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/AnaheimAmpPedal.swift
T
josh d32caf6262 docs(amps): Phase 8 review nits — Magna bipolar sweep, Anaheim latency note
- MagnaVibrato depth doc: the LFO is bipolar (±maxSweepSeconds around base).
- Anaheim: note the LookAheadLimiter stays in-chain both states (only ceiling
  changes), so its ~5 ms look-ahead latency is constant, not toggled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 15:40:15 -07:00

129 lines
5.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// AnaheimAmpPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// American **hybrid combo** — the Anaheim voice (Music Man lineage): a solid-state-flavoured
/// preamp into a tube power stage, with huge clean headroom, a **Bright** switch, a **Deep**
/// low-end switch, and a built-in **Limiter**.
///
/// Distinct from the all-tube voices: the preamp stage runs symmetric (grid `bias 0`) — no
/// even-harmonic tube warmth, for the cleaner/more clinical solid-state character — and a
/// `LookAheadLimiter` (the amp's onboard limiter) can be switched into the output.
///
/// > Note: the aggressive hard-knee solid-state clipping when pushed is approximated here by the
/// > symmetric preamp + high headroom; a true oversampled hard-clipper is a Lyrebird 1.7.x follow-up.
public final class AnaheimAmpPedal: AmpVoicePedal {
/// Bright switch: `0` = flat, `1` = treble shelf engaged.
@UIParam public var bright: Double = 0.0
/// Deep switch: `0` = flat, `1` = low-end resonance boost engaged.
@UIParam public var deep: Double = 0.0
/// Limiter footswitch: `1` = the built-in output limiter is engaged, `0` = bypassed.
@UIParam public var limiter: Double = 1.0
/// Symmetric preamp bias (solid-state character — no even-harmonic tube warmth).
private let ssPreampBias: Double = 0.0
private let brightFreqHz: Double = 3200.0
private let brightMaxGainDb: Double = 6.0
private let brightSlope: Double = 1.0
private let deepFreqHz: Double = 100.0
private let deepMaxGainDb: Double = 6.0
private let deepSlope: Double = 0.7
/// Limiter ceiling when engaged — below full scale, so it actually tames peaks (a peak
/// compressor, the amp's built-in limiter); when bypassed the ceiling is raised so it never acts.
private let limiterOnCeiling: Double = 0.5
private let limiterOffCeiling: Double = 10.0
private let limiterLookAhead: Double = 0.005
private let limiterRelease: Double = 0.050
public override var toneStackModel: ToneStackModel { .fender }
public override var summaryText: String {
"American hybrid combo — solid-state-flavoured clean, huge headroom, Bright / Deep / Limiter."
}
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Bright",
node: $bright,
options: [
PedalSwitch.Option(title: "Off", value: switchOffValue),
PedalSwitch.Option(title: "On", value: switchOnValue),
]
),
PedalSwitch(
label: "Deep",
node: $deep,
options: [
PedalSwitch.Option(title: "Off", value: switchOffValue),
PedalSwitch.Option(title: "On", value: switchOnValue),
]
),
PedalSwitch(
label: "Limiter",
node: $limiter,
options: [
PedalSwitch.Option(title: "Off", value: switchOffValue),
PedalSwitch.Option(title: "On", value: switchOnValue),
]
),
]
}
/// Wider card for the three switches.
public override var widthUnits: Int { 3 }
/// Creates an Anaheim amp.
///
/// - Parameters:
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
public init(inputBus: Int = 0, outputBus: Int = 0) {
super.init(name: "Anaheim", inputBus: inputBus, outputBus: outputBus)
gain = 3.0 // huge clean headroom
cab = 0.0 // American 1×12
}
/// Bright switch: a high-shelf lift ahead of the preamp (identity when off).
public override func inputShaping(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let shelfGainDb: any ValidGeneratorInput = $bright * brightMaxGainDb
return RBJHighShelf.Audio(
input: signal, freq: brightFreqHz, gain: shelfGainDb, slope: brightSlope)
}
/// Symmetric (solid-state-flavoured) preamp stage — `bias 0`, no even-harmonic tube warmth.
public override func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
TriodeStage(input: signal, drive: $gain, bias: ssPreampBias, oversample: preampOversample)
}
/// The built-in limiter, gated by the Limiter switch — placed *before* the power-amp stage (so
/// it limits the driven preamp/tone-stack signal, which can exceed the ceiling, rather than a
/// signal the power-amp `tanh` has already bounded). Off raises the ceiling so it never acts.
///
/// > Note: the `LookAheadLimiter` stays in the chain in both states (only its ceiling changes),
/// > so the amp carries its ~5 ms look-ahead latency whether or not the Limiter is engaged —
/// > a constant, not something the switch toggles.
public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let ceiling: LinLin.Audio = LinLin.Audio(
$limiter, inLo: 0.0, inHi: 1.0, outLo: limiterOffCeiling, outHi: limiterOnCeiling)
return LookAheadLimiter(
in: signal,
maxAmplitude: ceiling,
lookAheadTime: limiterLookAhead,
releaseTime: limiterRelease,
sampleRate: sampleRate
)
}
/// Deep low-shelf (gated by the Deep switch), post power amp.
public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let deepGainDb: any ValidGeneratorInput = $deep * deepMaxGainDb
return RBJLowShelf.Audio(input: signal, freq: deepFreqHz, gain: deepGainDb, slope: deepSlope)
}
}