feat(amp): decouple cabinet — "None (direct)" stop + cabinet as separate block
Phase 12. Split AmpVoicePedal.cabinetAndLimit into cabinet(_:) (the ConvolutionReverb, or a straight pass) + outputLimit(_:) (tanh soft-limit → Clip(±1)). The output limit ALWAYS runs on the amp, so the per-amp ±1 guarantee survives cabinet removal. - Cab selector gains a "None (direct)" stop (value = CabinetVoice.allCases .count, appended last so existing preset cab indices stay stable). isCabinetBypassed skips the convolver at that stop. - With Cab = None the amp emits its limited, cab-less power-amp signal; the player drops the existing standalone Cabinet pedal (shared CabinetVoice / CabinetIRFactory, no DSP dup) after it as a real chain block. Default stays cab-on (backward compatible). Tests: None bypasses the convolver, None still limits to ±1 (limiter survived), the None stop is exposed, and an amp(None) → standalone Cabinet chain renders non-silent/finite. Note: a downstream cab can overshoot ±1 like any post-amp pedal — end-of-chain level is the board's stage, not the amp's. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,8 +19,9 @@ import LyrebirdUI
|
||||
/// → onboardEffects(_:) (subclass hook — e.g. reverb + tremolo; default identity)
|
||||
/// → TriodeStage(power-amp drive) (power-amp warmth)
|
||||
/// → shapeVoice(_:) (subclass signature filter)
|
||||
/// → ConvolutionReverb(cab IR) (speaker cabinet — voice-selectable, rebuild on change)
|
||||
/// → TriodeStage(bias: 0) → Clip(±1) (output soft-limit + hard safety ceiling)
|
||||
/// → ConvolutionReverb(cab IR) (speaker cabinet — voice-selectable, or None for a
|
||||
/// separate cab block; rebuild on change)
|
||||
/// → TriodeStage(bias: 0) → Clip(±1) (output soft-limit + hard safety ceiling — always on)
|
||||
/// ```
|
||||
/// Fully wet (the amp replaces the dry signal); `Level` is the master. Double-width amp-head card.
|
||||
///
|
||||
@@ -234,11 +235,16 @@ open class AmpVoicePedal: Pedal {
|
||||
/// Range for a signature control that maps [0, 1] (Bright / Presence / Cut amount).
|
||||
let signatureRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||
|
||||
/// Cab selector value for the "None (direct)" stop — no speaker convolution. Placed one past the
|
||||
/// last `CabinetVoice` index so every existing voice keeps its saved index (append-only).
|
||||
static let cabinetBypassValue: Double = Double(CabinetVoice.allCases.count)
|
||||
|
||||
private static let cabStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
|
||||
.enumerated()
|
||||
.map { (index: Int, voice: CabinetVoice) in
|
||||
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
||||
}
|
||||
+ [PedalSelectorKnob.Stop(title: "None (direct)", value: cabinetBypassValue)]
|
||||
|
||||
// MARK: - Chrome
|
||||
|
||||
@@ -301,21 +307,19 @@ open class AmpVoicePedal: Pedal {
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Preamp → fixed tone stack → power amp → signature shaping → cabinet → output soft-limit.
|
||||
/// Preamp → fixed tone stack → power amp → signature shaping → cabinet (or None) → output
|
||||
/// soft-limit.
|
||||
///
|
||||
/// > Note: only the voice named by the live `cab` selector is instantiated, so exactly one
|
||||
/// > `ConvolutionReverb` runs. The `cab` selector is `rebuildsOnChange`, so switching cabs
|
||||
/// > rebuilds the board (re-entering `effect(_:)` with the new voice) rather than running every
|
||||
/// > voice at once.
|
||||
/// > Note: at most one `ConvolutionReverb` runs — only the voice named by the live `cab` selector
|
||||
/// > is instantiated, and the "None (direct)" stop instantiates none. The `cab` selector is
|
||||
/// > `rebuildsOnChange`, so switching cabs (or to/from None) rebuilds the board rather than
|
||||
/// > running every voice at once.
|
||||
///
|
||||
/// The closing `TriodeStage(bias: 0)` is a symmetric `tanh` output limiter: the cab convolution
|
||||
/// and signature shelves can push peaks past ±1, which a real analog output would soft-compress
|
||||
/// rather than hard-clip. Unit small-signal gain keeps clean tones intact; peaks soft-limit
|
||||
/// toward ±1. The trailing `Clip(±1)` is a hard safety clamp for the sub-percent overshoot the
|
||||
/// `tanh`'s DC-blocker and the halfband filters can leave — so no sample can clip the DAC.
|
||||
/// The output soft-limit (``outputLimit(_:)``) always runs, cabinet or not, so the ±1 ceiling
|
||||
/// holds even when the cabinet is bypassed for a separate downstream cab block.
|
||||
///
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: The amped, cab-convolved, soft-limited, ceiling-clamped mono output.
|
||||
/// - Returns: The amped, (optionally) cab-convolved, soft-limited, ceiling-clamped mono output.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
cabinetAndLimit(preCabinetCore(dry))
|
||||
}
|
||||
@@ -337,27 +341,62 @@ open class AmpVoicePedal: Pedal {
|
||||
return applySag(shapeVoice(powerAmp))
|
||||
}
|
||||
|
||||
/// The per-channel cabinet + output stage: the selected `CabinetVoice` convolver → `tanh`
|
||||
/// soft-limit → `Clip(±1)` safety clamp. Applied once in mono, or once per channel by a
|
||||
/// widener amp.
|
||||
/// True when the `Cab` selector is on the "None (direct)" stop — the amp emits its limited
|
||||
/// power-amp signal with **no** speaker convolution, so the player can place a separate cabinet
|
||||
/// block (the standalone `Cabinet` pedal, or a future IR loader) downstream. Read at board-build
|
||||
/// time; the selector is `rebuildsOnChange`, so toggling it rebuilds the graph.
|
||||
///
|
||||
/// > Warning: with no cabinet, the amp sounds raw and fizzy (the power-amp `tanh` with no speaker
|
||||
/// > low-pass) — expected; a cabinet is what tames the top end.
|
||||
var isCabinetBypassed: Bool {
|
||||
guard cab.isFinite else { return false }
|
||||
return Int(cab.rounded()) >= CabinetVoice.allCases.count
|
||||
}
|
||||
|
||||
/// The per-channel cabinet + output stage: cabinet convolver (or a straight pass at the "None"
|
||||
/// stop) → `tanh` soft-limit → `Clip(±1)` safety clamp. Applied once in mono, or once per channel
|
||||
/// by a widener amp.
|
||||
///
|
||||
/// - Parameter signal: The post-core signal for one channel.
|
||||
/// - Returns: The cab-convolved, soft-limited, ceiling-clamped signal.
|
||||
/// - Returns: The (optionally) cab-convolved, soft-limited, ceiling-clamped signal.
|
||||
func cabinetAndLimit(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
outputLimit(cabinet(signal))
|
||||
}
|
||||
|
||||
/// The selected `CabinetVoice` speaker convolver, or `signal` unchanged when the `Cab` selector
|
||||
/// is on "None (direct)". Only the voice named by the live `cab` selector is instantiated, so at
|
||||
/// most one `ConvolutionReverb` runs.
|
||||
///
|
||||
/// - Parameter signal: The post-core signal for one channel.
|
||||
/// - Returns: The cab-convolved signal, or `signal` unchanged when the cabinet is bypassed.
|
||||
func cabinet(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
guard !isCabinetBypassed else { return signal }
|
||||
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cab)
|
||||
let cabinet: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
|
||||
return ConvolutionReverb.Audio(
|
||||
input: signal,
|
||||
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate),
|
||||
mix: cabinetMix
|
||||
)
|
||||
}
|
||||
|
||||
/// The output soft-limit + hard `Clip(±1)` safety ceiling — **always** applied on the amp,
|
||||
/// cabinet or not, so the ±1 guarantee holds even at the "None (direct)" stop.
|
||||
///
|
||||
/// The `TriodeStage(bias: 0)` is a symmetric `tanh` output limiter: cab convolution and signature
|
||||
/// shelves can push peaks past ±1, which a real analog output soft-compresses rather than
|
||||
/// hard-clips. Unit small-signal gain keeps clean tones intact; peaks soft-limit toward ±1. The
|
||||
/// trailing `Clip(±1)` hard-clamps the sub-percent overshoot the `tanh`'s DC-blocker and the
|
||||
/// halfband filters can leave, so no sample can clip the DAC.
|
||||
///
|
||||
/// - Parameter signal: The (optionally cab-convolved) signal for one channel.
|
||||
/// - Returns: The soft-limited, ceiling-clamped signal.
|
||||
func outputLimit(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let softLimited: TriodeStage = TriodeStage(
|
||||
input: cabinet,
|
||||
input: signal,
|
||||
drive: outputStageDrive,
|
||||
bias: outputStageBias,
|
||||
oversample: outputStageOversample
|
||||
)
|
||||
// Hard safety clamp: the tanh keeps the signal near ±1, but its DC-blocker and the halfband
|
||||
// filters can leave a sub-percent transient overshoot — clamp it so no sample can clip the DAC.
|
||||
return Clip.Audio(softLimited, lo: -outputCeiling, hi: outputCeiling)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user