Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8b858f1aa | |||
| 9daffbbdf3 |
@@ -19,8 +19,9 @@ import LyrebirdUI
|
|||||||
/// → onboardEffects(_:) (subclass hook — e.g. reverb + tremolo; default identity)
|
/// → onboardEffects(_:) (subclass hook — e.g. reverb + tremolo; default identity)
|
||||||
/// → TriodeStage(power-amp drive) (power-amp warmth)
|
/// → TriodeStage(power-amp drive) (power-amp warmth)
|
||||||
/// → shapeVoice(_:) (subclass signature filter)
|
/// → shapeVoice(_:) (subclass signature filter)
|
||||||
/// → ConvolutionReverb(cab IR) (speaker cabinet — voice-selectable, rebuild on change)
|
/// → ConvolutionReverb(cab IR) (speaker cabinet — voice-selectable, or None for a
|
||||||
/// → TriodeStage(bias: 0) → Clip(±1) (output soft-limit + hard safety ceiling)
|
/// 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.
|
/// 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).
|
/// Range for a signature control that maps [0, 1] (Bright / Presence / Cut amount).
|
||||||
let signatureRange: ClosedRange<Double> = 0.0 ... 1.0
|
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
|
private static let cabStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
|
||||||
.enumerated()
|
.enumerated()
|
||||||
.map { (index: Int, voice: CabinetVoice) in
|
.map { (index: Int, voice: CabinetVoice) in
|
||||||
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
||||||
}
|
}
|
||||||
|
+ [PedalSelectorKnob.Stop(title: "None (direct)", value: cabinetBypassValue)]
|
||||||
|
|
||||||
// MARK: - Chrome
|
// MARK: - Chrome
|
||||||
|
|
||||||
@@ -301,21 +307,19 @@ open class AmpVoicePedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Effect
|
// 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
|
/// > Note: at most one `ConvolutionReverb` runs — only the voice named by the live `cab` selector
|
||||||
/// > `ConvolutionReverb` runs. The `cab` selector is `rebuildsOnChange`, so switching cabs
|
/// > is instantiated, and the "None (direct)" stop instantiates none. The `cab` selector is
|
||||||
/// > rebuilds the board (re-entering `effect(_:)` with the new voice) rather than running every
|
/// > `rebuildsOnChange`, so switching cabs (or to/from None) rebuilds the board rather than
|
||||||
/// > voice at once.
|
/// > running every voice at once.
|
||||||
///
|
///
|
||||||
/// The closing `TriodeStage(bias: 0)` is a symmetric `tanh` output limiter: the cab convolution
|
/// The output soft-limit (``outputLimit(_:)``) always runs, cabinet or not, so the ±1 ceiling
|
||||||
/// and signature shelves can push peaks past ±1, which a real analog output would soft-compress
|
/// holds even when the cabinet is bypassed for a separate downstream cab block.
|
||||||
/// 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.
|
|
||||||
///
|
///
|
||||||
/// - Parameter dry: Dry mono input signal.
|
/// - 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 {
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
cabinetAndLimit(preCabinetCore(dry))
|
cabinetAndLimit(preCabinetCore(dry))
|
||||||
}
|
}
|
||||||
@@ -337,27 +341,65 @@ open class AmpVoicePedal: Pedal {
|
|||||||
return applySag(shapeVoice(powerAmp))
|
return applySag(shapeVoice(powerAmp))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The per-channel cabinet + output stage: the selected `CabinetVoice` convolver → `tanh`
|
/// True when the `Cab` selector is on the "None (direct)" stop — the amp emits its limited
|
||||||
/// soft-limit → `Clip(±1)` safety clamp. Applied once in mono, or once per channel by a
|
/// power-amp signal with **no** speaker convolution, so the player can place a separate cabinet
|
||||||
/// widener amp.
|
/// 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 }
|
||||||
|
// Clamp in Double space before converting: a huge finite `cab` (from a corrupted/hand-edited
|
||||||
|
// rig) would otherwise trap `Int(_:)` — same defense as `CabinetVoice.voice(atSelectorValue:)`.
|
||||||
|
let bounded: Double = Swift.min(Swift.max(cab, 0.0), Double(CabinetVoice.allCases.count))
|
||||||
|
return Int(bounded.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.
|
/// - 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 {
|
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 voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cab)
|
||||||
let cabinet: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
|
return ConvolutionReverb.Audio(
|
||||||
input: signal,
|
input: signal,
|
||||||
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate),
|
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate),
|
||||||
mix: cabinetMix
|
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(
|
let softLimited: TriodeStage = TriodeStage(
|
||||||
input: cabinet,
|
input: signal,
|
||||||
drive: outputStageDrive,
|
drive: outputStageDrive,
|
||||||
bias: outputStageBias,
|
bias: outputStageBias,
|
||||||
oversample: outputStageOversample
|
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)
|
return Clip.Audio(softLimited, lo: -outputCeiling, hi: outputCeiling)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,6 +259,83 @@ struct AmpVoicePedalTests {
|
|||||||
#expect(restored.sag == 0.7 && restored.bias == 0.2, "Sag/Bias did not round-trip through state")
|
#expect(restored.sag == 0.7 && restored.bias == 0.2, "Sag/Bias did not round-trip through state")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Cabinet decoupling
|
||||||
|
|
||||||
|
@Test func cabNoneBypassesConvolution() throws {
|
||||||
|
for voice in voices {
|
||||||
|
let withCab: [Float] = try render(voice.make) { $0.cab = 0.0 }
|
||||||
|
let none: [Float] = try render(voice.make) { $0.cab = AmpVoicePedal.cabinetBypassValue }
|
||||||
|
#expect(hasNonSilentOutput(none) && none.allSatisfy { $0.isFinite },
|
||||||
|
"\(voice.name) None-cab output silent or non-finite")
|
||||||
|
#expect(windowedSSD(withCab, none) > 0, "\(voice.name) None did not bypass the cabinet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func cabNoneStillLimitsToCeiling() throws {
|
||||||
|
// With the cabinet bypassed the output soft-limit must still run — the ±1 ceiling has to hold.
|
||||||
|
let ceilingEpsilon: Double = 1.0e-4
|
||||||
|
for voice in voices {
|
||||||
|
let hot: [Float] = try render(voice.make) { (pedal: AmpVoicePedal) in
|
||||||
|
pedal.gain = 30.0; pedal.bass = 1.0; pedal.treble = 1.0
|
||||||
|
pedal.cab = AmpVoicePedal.cabinetBypassValue
|
||||||
|
}
|
||||||
|
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||||
|
#expect(peak <= 1.0 + ceilingEpsilon,
|
||||||
|
"\(voice.name) None-cab peak \(peak) exceeds ±1 (output limiter lost)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func extremeCabValuesDoNotTrap() throws {
|
||||||
|
// A corrupted/hand-edited rig can restore any Double into `cab`. Neither the bypass check nor
|
||||||
|
// the voice lookup may trap `Int(_:)` — every value must resolve to a defined, finite render.
|
||||||
|
let extremes: [Double] = [.infinity, -.infinity, 1.0e20, -1.0e20, .nan, 999.0]
|
||||||
|
for cabValue: Double in extremes {
|
||||||
|
let out: [Float] = try render({ CaliforniaAmpPedal() }) { $0.cab = cabValue }
|
||||||
|
#expect(out.allSatisfy { $0.isFinite }, "cab=\(cabValue) produced non-finite output")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func cabSelectorExposesNoneStop() throws {
|
||||||
|
let stops: [PedalSelectorKnob.Stop] = CaliforniaAmpPedal().effectSelectors
|
||||||
|
.first { $0.label == "Cab" }?.stops ?? []
|
||||||
|
#expect(stops.last?.title == "None (direct)", "Cab selector missing the None stop")
|
||||||
|
#expect(stops.last?.value == AmpVoicePedal.cabinetBypassValue, "None stop has the wrong value")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func ampWithNoneCabIntoStandaloneCabinetWorks() throws {
|
||||||
|
// Decoupled chain: amp (Cab = None) → standalone Cabinet pedal. The amp emits its limited,
|
||||||
|
// cab-less signal; the separate Cabinet block does the speaker convolution downstream.
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||||
|
duration: 0.2, sampleRate: sampleRate, numAudioBuses: 64)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let midBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(midBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstBus)
|
||||||
|
}
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let amp: CaliforniaAmpPedal = CaliforniaAmpPedal(inputBus: srcBus.index, outputBus: midBus.index)
|
||||||
|
amp.sampleRate = sampleRate
|
||||||
|
amp.cab = AmpVoicePedal.cabinetBypassValue
|
||||||
|
let cabinet: CabinetPedal = CabinetPedal(inputBus: midBus.index, outputBus: dstBus.index)
|
||||||
|
cabinet.sampleRate = sampleRate
|
||||||
|
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(amp, position: NodePosition.after(source))
|
||||||
|
try engine.add(cabinet, position: NodePosition.after(amp))
|
||||||
|
try engine.add(master, position: NodePosition.after(cabinet))
|
||||||
|
try engine.start()
|
||||||
|
let out: [Float] = readStereoCAF(url: url, sampleRate: sampleRate)
|
||||||
|
#expect(hasNonSilentOutput(out) && out.allSatisfy { $0.isFinite }, "decoupled amp+cabinet silent/non-finite")
|
||||||
|
// Note: the amp guarantees its OWN output ≤ ±1 (see `cabNoneStillLimitsToCeiling`), but a
|
||||||
|
// downstream standalone Cabinet convolves that signal and — like any post-amp pedal — may
|
||||||
|
// overshoot ±1. The board's final output stage, not the amp, owns end-of-chain level. So this
|
||||||
|
// asserts the decoupled chain works (non-silent, finite), not a ±1 ceiling it never promised.
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Chrome / config
|
// MARK: - Chrome / config
|
||||||
|
|
||||||
@Test func exposesControls() throws {
|
@Test func exposesControls() throws {
|
||||||
|
|||||||
Reference in New Issue
Block a user