Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29b1747533 | |||
| 102715ded1 |
@@ -48,6 +48,7 @@ public extension PedalType {
|
|||||||
static let british = PedalType("British")
|
static let british = PedalType("British")
|
||||||
static let chime = PedalType("Chime")
|
static let chime = PedalType("Chime")
|
||||||
static let fullertonReverb = PedalType("Fullerton Reverb")
|
static let fullertonReverb = PedalType("Fullerton Reverb")
|
||||||
|
static let jazzClean = PedalType("Jazz Clean")
|
||||||
static let neuralAmp = PedalType("Neural Amp")
|
static let neuralAmp = PedalType("Neural Amp")
|
||||||
static let overdrive = PedalType("Overdrive")
|
static let overdrive = PedalType("Overdrive")
|
||||||
static let distortion = PedalType("Distortion")
|
static let distortion = PedalType("Distortion")
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import LyrebirdSynth
|
import LyrebirdSynth
|
||||||
import LyrebirdUI
|
import LyrebirdUI
|
||||||
|
|
||||||
/// Shared base for the amp pedals (California / British / Chime / Fullerton Reverb).
|
/// Shared base for the amp pedals (California / British / Chime / Fullerton Reverb / Jazz Clean).
|
||||||
///
|
///
|
||||||
/// Each concrete amp fixes one tone-stack ``ToneStackModel`` and adds one signature control, but
|
/// Each concrete amp fixes one tone-stack ``ToneStackModel`` and adds one signature control, but
|
||||||
/// shares the common chain built here:
|
/// shares the common chain built here:
|
||||||
@@ -184,7 +184,16 @@ open class AmpVoicePedal: Pedal {
|
|||||||
/// - 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, 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 {
|
||||||
let sr: Double = sampleRate
|
cabinetAndLimit(preCabinetCore(dry))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The mono pre-cabinet core: `inputShaping → preamp → tone stack → onboardEffects → power amp →
|
||||||
|
/// shapeVoice`. Factored out of `effect(_:)` so a stereo (widener) amp can split into a stereo
|
||||||
|
/// stage (e.g. a stereo chorus) between the core and a per-channel ``cabinetAndLimit(_:)``.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: The post-power-amp, pre-cabinet mono signal.
|
||||||
|
func preCabinetCore(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
let preShaped: any ValidGeneratorInput = inputShaping(dry)
|
let preShaped: any ValidGeneratorInput = inputShaping(dry)
|
||||||
let preamp: TriodeStage = TriodeStage(input: preShaped, drive: $gain, bias: preampBias, oversample: 4)
|
let preamp: TriodeStage = TriodeStage(input: preShaped, drive: $gain, bias: preampBias, oversample: 4)
|
||||||
let toned: ToneStack = ToneStack(
|
let toned: ToneStack = ToneStack(
|
||||||
@@ -192,11 +201,20 @@ open class AmpVoicePedal: Pedal {
|
|||||||
let processed: any ValidGeneratorInput = onboardEffects(toned)
|
let processed: any ValidGeneratorInput = onboardEffects(toned)
|
||||||
let powerAmp: TriodeStage = TriodeStage(
|
let powerAmp: TriodeStage = TriodeStage(
|
||||||
input: processed, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2)
|
input: processed, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2)
|
||||||
let shaped: any ValidGeneratorInput = shapeVoice(powerAmp)
|
return 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.
|
||||||
|
///
|
||||||
|
/// - Parameter signal: The post-core signal for one channel.
|
||||||
|
/// - Returns: The cab-convolved, soft-limited, ceiling-clamped signal.
|
||||||
|
func cabinetAndLimit(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cab)
|
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cab)
|
||||||
let cabinet: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
|
let cabinet: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
|
||||||
input: shaped,
|
input: signal,
|
||||||
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
|
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate),
|
||||||
mix: cabinetMix
|
mix: cabinetMix
|
||||||
)
|
)
|
||||||
let softLimited: TriodeStage = TriodeStage(
|
let softLimited: TriodeStage = TriodeStage(
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
// JazzCleanAmpPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Ultra-clean solid-state combo with its signature lush **stereo chorus**, plus spring reverb and
|
||||||
|
/// a bright switch — the glassy "jazz clean" platform.
|
||||||
|
///
|
||||||
|
/// Unlike the mono amp voices, this amp is a ``PedalChannelKind/widener``: the real amp has two
|
||||||
|
/// power amps and two speakers fed by a stereo chorus, so it takes the mono guitar input and emits a
|
||||||
|
/// genuinely stereo pair. The chorus (mono → stereo) is the stereo splitter — its two taps become
|
||||||
|
/// the left and right channels, each then run through its own cabinet + output stage.
|
||||||
|
///
|
||||||
|
/// Signal path (inside `wideEffect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry → preCabinetCore (bright → preamp → tone → spring reverb → power amp) [mono]
|
||||||
|
/// → Chorus (mono → stereo) [stereo split]
|
||||||
|
/// → L: cabinetAndLimit R: cabinetAndLimit [per channel]
|
||||||
|
/// ```
|
||||||
|
/// A **Chorus** switch models the amp's chorus on/off footswitch: off collapses the chorus to a dry
|
||||||
|
/// pass-through (both channels identical), preserving the Rate/Depth settings.
|
||||||
|
public final class JazzCleanAmpPedal: AmpVoicePedal {
|
||||||
|
|
||||||
|
// MARK: - Onboard-effect parameters
|
||||||
|
|
||||||
|
/// Spring-reverb wet mix in [0, 1].
|
||||||
|
@UIParam public var reverb: Double = 0.2
|
||||||
|
/// Chorus LFO rate in Hz. Range [0.1, 5.0].
|
||||||
|
@UIParam public var chorusRate: Double = 0.8
|
||||||
|
/// Chorus depth as a fraction of the base delay time. Kept in the classic-chorus band
|
||||||
|
/// (~0.001–0.01) so it adds width without pitch wobble.
|
||||||
|
@UIParam public var chorusDepth: Double = 0.005
|
||||||
|
/// Bright switch: `0` = flat, `1` = treble shelf engaged.
|
||||||
|
@UIParam public var bright: Double = 0.0
|
||||||
|
/// Chorus footswitch: `1` = chorus engaged (stereo), `0` = bypassed (dry, mono-equivalent).
|
||||||
|
@UIParam public var chorusEnabled: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Bright-switch shelf corner in Hz.
|
||||||
|
private let brightFreqHz: Double = 3000.0
|
||||||
|
/// Bright-switch shelf lift in dB when engaged.
|
||||||
|
private let brightMaxGainDb: Double = 5.0
|
||||||
|
/// Bright-switch shelf slope.
|
||||||
|
private let brightSlope: Double = 0.9
|
||||||
|
/// Fixed chorus wet/dry blend when the chorus is engaged (the amp has no chorus-mix knob).
|
||||||
|
private let chorusMixValue: Double = 0.5
|
||||||
|
|
||||||
|
private let reverbRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
private let chorusRateRange: ClosedRange<Double> = 0.1 ... 5.0
|
||||||
|
private let chorusDepthRange: ClosedRange<Double> = 0.0005 ... 0.015
|
||||||
|
private let switchOffValue: Double = 0.0
|
||||||
|
private let switchOnValue: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Voice configuration
|
||||||
|
|
||||||
|
public override var toneStackModel: ToneStackModel { .fender }
|
||||||
|
public override var summaryText: String {
|
||||||
|
"Solid-state clean — lush stereo chorus, spring reverb, and a Bright switch."
|
||||||
|
}
|
||||||
|
public override var signatureKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Reverb", node: $reverb, range: reverbRange),
|
||||||
|
PedalKnob(label: "Rate", node: $chorusRate, range: chorusRateRange),
|
||||||
|
PedalKnob(label: "Depth", node: $chorusDepth, range: chorusDepthRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stereo output — the chorus feeds two independent power-amp/cabinet channels.
|
||||||
|
public override var channelKind: PedalChannelKind { .widener }
|
||||||
|
|
||||||
|
/// Wider card for the reverb/chorus knobs plus the Bright and Chorus switches.
|
||||||
|
public override var widthUnits: Int { 3 }
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a Jazz Clean 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: "Jazz Clean", inputBus: inputBus, outputBus: outputBus)
|
||||||
|
gain = 3.0 // clean, low-gain solid-state default
|
||||||
|
cab = 6.0 // Full-Range (FRFR) — the hi-fi, least-coloured voice
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Switches
|
||||||
|
|
||||||
|
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: "Chorus",
|
||||||
|
node: $chorusEnabled,
|
||||||
|
options: [
|
||||||
|
PedalSwitch.Option(title: "Off", value: switchOffValue),
|
||||||
|
PedalSwitch.Option(title: "On", value: switchOnValue),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Hooks
|
||||||
|
|
||||||
|
/// Bright switch: a high-shelf lift ahead of the preamp (identity when off, live, no rebuild).
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Spring reverb inside the mono core (before the stereo chorus split).
|
||||||
|
public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
SpringReverb.Audio(input: signal, mix: $reverb, sampleRate: sampleRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Stereo effect
|
||||||
|
|
||||||
|
/// Mono amp core → stereo chorus split → per-channel cabinet + output stage.
|
||||||
|
///
|
||||||
|
/// The `chorusEnabled` footswitch gates the chorus wet mix to `0` when off, so the chorus passes
|
||||||
|
/// the dry core to both channels (a mono-equivalent output) while preserving Rate/Depth.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: The stereo (left, right) amp output.
|
||||||
|
public override func wideEffect(
|
||||||
|
_ dry: any ValidGeneratorInput
|
||||||
|
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
|
||||||
|
let core: any ValidGeneratorInput = preCabinetCore(dry)
|
||||||
|
let chorusMix: any ValidGeneratorInput = $chorusEnabled * chorusMixValue
|
||||||
|
let chorus: Chorus.Audio = Chorus.Audio(
|
||||||
|
input: core,
|
||||||
|
depth: $chorusDepth,
|
||||||
|
rate: $chorusRate,
|
||||||
|
mix: chorusMix,
|
||||||
|
sampleRate: sampleRate
|
||||||
|
)
|
||||||
|
return (cabinetAndLimit(chorus.left), cabinetAndLimit(chorus.right))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ public enum PedalRegistry {
|
|||||||
"British": { BritishAmpPedal() },
|
"British": { BritishAmpPedal() },
|
||||||
"Chime": { ChimeAmpPedal() },
|
"Chime": { ChimeAmpPedal() },
|
||||||
"Fullerton Reverb": { FullertonReverbAmpPedal() },
|
"Fullerton Reverb": { FullertonReverbAmpPedal() },
|
||||||
|
"Jazz Clean": { JazzCleanAmpPedal() },
|
||||||
"Neural Amp": { NeuralAmpPedal() },
|
"Neural Amp": { NeuralAmpPedal() },
|
||||||
"Overdrive": { OverdrivePedal() },
|
"Overdrive": { OverdrivePedal() },
|
||||||
"Distortion": { DistortionPedal() },
|
"Distortion": { DistortionPedal() },
|
||||||
|
|||||||
@@ -178,10 +178,10 @@ public struct HelpView: View {
|
|||||||
+ "built-in speaker impulse responses.",
|
+ "built-in speaker impulse responses.",
|
||||||
"The Cabinet pedal's built-in cab voicings are original impulse responses generated in "
|
"The Cabinet pedal's built-in cab voicings are original impulse responses generated in "
|
||||||
+ "code — not captures of any third-party hardware or IR pack.",
|
+ "code — not captures of any third-party hardware or IR pack.",
|
||||||
"The California, British, Chime, and Fullerton Reverb amp pedals' tone stacks follow the "
|
"The California, British, Chime, Fullerton Reverb, and Jazz Clean amp pedals' tone stacks "
|
||||||
+ "Yeh & Smith analysis of the classic passive tone-stack circuit (\"Discretization of the "
|
+ "follow the Yeh & Smith analysis of the classic passive tone-stack circuit (\"Discretization "
|
||||||
+ "'59 Fender Bassman Tone Stack\", DAFx-06); their models are original code, not captures of "
|
+ "of the '59 Fender Bassman Tone Stack\", DAFx-06); their models are original code, not "
|
||||||
+ "specific hardware.",
|
+ "captures of specific hardware.",
|
||||||
"The Neural Amp pedal loads GuitarML Proteus / NeuralPi capture models (the open LSTM "
|
"The Neural Amp pedal loads GuitarML Proteus / NeuralPi capture models (the open LSTM "
|
||||||
+ "format from github.com/GuitarML). You supply the model file; none are bundled, and "
|
+ "format from github.com/GuitarML). You supply the model file; none are bundled, and "
|
||||||
+ "those models are licensed by their respective authors.",
|
+ "those models are licensed by their respective authors.",
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static let mapping: [String: PedalCategory] = [
|
private static let mapping: [String: PedalCategory] = [
|
||||||
"California": .gain, "British": .gain, "Chime": .gain, "Fullerton Reverb": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
|
"California": .gain, "British": .gain, "Chime": .gain, "Fullerton Reverb": .gain, "Jazz Clean": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
|
||||||
"Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics,
|
"Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics,
|
||||||
"Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter,
|
"Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter,
|
||||||
"Cabinet": .filter,
|
"Cabinet": .filter,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public struct PedalPaletteView: View {
|
|||||||
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
||||||
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
||||||
private static let preferredOrder: [String] = [
|
private static let preferredOrder: [String] = [
|
||||||
"California", "British", "Chime", "Fullerton Reverb", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
"California", "British", "Chime", "Fullerton Reverb", "Jazz Clean", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
||||||
"Volume",
|
"Volume",
|
||||||
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
|
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
|
||||||
"Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
|
"Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ private func enclosureColor(for displayName: String) -> Color {
|
|||||||
case "British": return Color(red: 0.30, green: 0.16, blue: 0.10) // oxblood tolex
|
case "British": return Color(red: 0.30, green: 0.16, blue: 0.10) // oxblood tolex
|
||||||
case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green
|
case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green
|
||||||
case "Fullerton Reverb": return Color(red: 0.15, green: 0.22, blue: 0.30) // blackface panel
|
case "Fullerton Reverb": return Color(red: 0.15, green: 0.22, blue: 0.30) // blackface panel
|
||||||
|
case "Jazz Clean": return Color(red: 0.14, green: 0.30, blue: 0.34) // solid-state silver-teal
|
||||||
case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet
|
case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet
|
||||||
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
|
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
|
||||||
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
|
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
|
||||||
@@ -796,7 +797,7 @@ public struct PedalView: View {
|
|||||||
private var switchRow: some View {
|
private var switchRow: some View {
|
||||||
let switches: [PedalSwitch] = pedal.effectSwitches
|
let switches: [PedalSwitch] = pedal.effectSwitches
|
||||||
if !switches.isEmpty {
|
if !switches.isEmpty {
|
||||||
VStack(spacing: PedalView.knobSpacing) {
|
HStack(spacing: PedalView.knobSpacing) {
|
||||||
ForEach(Array(switches.enumerated()), id: \.offset) { pair in
|
ForEach(Array(switches.enumerated()), id: \.offset) { pair in
|
||||||
PedalSwitchView(pair.element)
|
PedalSwitchView(pair.element)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,196 @@
|
|||||||
|
// JazzCleanAmpPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("JazzCleanAmpPedal")
|
||||||
|
struct JazzCleanAmpPedalTests {
|
||||||
|
|
||||||
|
private let sampleRate: Double = 48000.0
|
||||||
|
|
||||||
|
/// Renders the amp as a stereo widener, returning the separated (left, right) channels — the
|
||||||
|
/// pedal's `outputBusRight` is wired to a second bus and a split master routes both to the
|
||||||
|
/// hardware L/R so `readStereoCAF` can capture them independently.
|
||||||
|
private func renderStereo(configure: (JazzCleanAmpPedal) -> Void = { _ in }) throws
|
||||||
|
-> (left: [Float], right: [Float]) {
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||||
|
duration: 0.3, sampleRate: sampleRate, numAudioBuses: 64)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstL: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstR: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstL)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstR)
|
||||||
|
}
|
||||||
|
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal(inputBus: srcBus.index, outputBus: dstL.index)
|
||||||
|
pedal.outputBusRight = dstR.index
|
||||||
|
pedal.sampleRate = sampleRate
|
||||||
|
configure(pedal)
|
||||||
|
let master: JazzStereoSplitMaster = JazzStereoSplitMaster(left: dstL.index, right: dstR.index)
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(pedal, position: NodePosition.after(source))
|
||||||
|
try engine.add(master, position: NodePosition.after(pedal))
|
||||||
|
try engine.start()
|
||||||
|
|
||||||
|
let interleaved: [Float] = readStereoCAF(url: url, sampleRate: sampleRate)
|
||||||
|
var left: [Float] = []
|
||||||
|
var right: [Float] = []
|
||||||
|
left.reserveCapacity(interleaved.count / 2)
|
||||||
|
right.reserveCapacity(interleaved.count / 2)
|
||||||
|
for frame: Int in 0..<(interleaved.count / 2) {
|
||||||
|
left.append(interleaved[2 * frame])
|
||||||
|
right.append(interleaved[2 * frame + 1])
|
||||||
|
}
|
||||||
|
return (left, right)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 2048, window: Int = 2048) -> Double {
|
||||||
|
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
|
||||||
|
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||||
|
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func peak(_ samples: [Float]) -> Double {
|
||||||
|
samples.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func buildsNonSilentFiniteOutput() throws {
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo()
|
||||||
|
#expect(hasNonSilentOutput(left), "Jazz Clean left channel was silent")
|
||||||
|
#expect(hasNonSilentOutput(right), "Jazz Clean right channel was silent")
|
||||||
|
#expect(left.allSatisfy { $0.isFinite } && right.allSatisfy { $0.isFinite },
|
||||||
|
"Jazz Clean produced non-finite output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func chorusEngagedWidensToStereo() throws {
|
||||||
|
// Engaged: the two chorus taps differ → genuine stereo width.
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo { $0.chorusEnabled = 1.0 }
|
||||||
|
#expect(windowedSSD(left, right) > 0, "engaged chorus should make L and R differ")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func chorusBypassedCollapsesToMono() throws {
|
||||||
|
// Bypassed: mix 0 → both taps are the dry core → L == R (bit-identical).
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo { $0.chorusEnabled = 0.0 }
|
||||||
|
#expect(hasNonSilentOutput(left))
|
||||||
|
#expect(windowedSSD(left, right) == 0.0, "bypassed chorus should collapse to mono (L == R)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func chorusFootswitchChangesOutput() throws {
|
||||||
|
let on: [Float] = try renderStereo { $0.chorusEnabled = 1.0; $0.chorusRate = 3.0 }.left
|
||||||
|
let off: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 3.0 }.left
|
||||||
|
#expect(windowedSSD(on, off) > 0, "chorus footswitch had no effect")
|
||||||
|
// With the chorus off, the Rate knob is irrelevant (mix 0 → dry) — two off-renders match.
|
||||||
|
let offSlow: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 0.2 }.left
|
||||||
|
let offFast: [Float] = try renderStereo { $0.chorusEnabled = 0.0; $0.chorusRate = 5.0 }.left
|
||||||
|
#expect(windowedSSD(offSlow, offFast) == 0.0, "chorus off should ignore rate (dry pass-through)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func chorusRateChangesOutput() throws {
|
||||||
|
let slow: [Float] = try renderStereo { $0.chorusRate = 0.2 }.left
|
||||||
|
let fast: [Float] = try renderStereo { $0.chorusRate = 5.0 }.left
|
||||||
|
#expect(windowedSSD(slow, fast) > 0, "chorus rate had no effect")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func chorusDepthChangesOutput() throws {
|
||||||
|
let shallow: [Float] = try renderStereo { $0.chorusDepth = 0.001 }.left
|
||||||
|
let deep: [Float] = try renderStereo { $0.chorusDepth = 0.014 }.left
|
||||||
|
#expect(windowedSSD(shallow, deep) > 0, "chorus depth had no effect")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func reverbMixChangesOutput() throws {
|
||||||
|
let dry: [Float] = try renderStereo { $0.reverb = 0.0 }.left
|
||||||
|
let wet: [Float] = try renderStereo { $0.reverb = 0.9 }.left
|
||||||
|
#expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func brightSwitchChangesOutput() throws {
|
||||||
|
let flat: [Float] = try renderStereo { $0.bright = 0.0 }.left
|
||||||
|
let bright: [Float] = try renderStereo { $0.bright = 1.0 }.left
|
||||||
|
#expect(windowedSSD(flat, bright) > 0, "bright switch had no effect")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func bothChannelsStayWithinCeilingWithFXEngaged() throws {
|
||||||
|
let ceilingEpsilon: Double = 1.0e-4
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo { (pedal: JazzCleanAmpPedal) in
|
||||||
|
pedal.gain = 30.0
|
||||||
|
pedal.bass = 1.0
|
||||||
|
pedal.treble = 1.0
|
||||||
|
pedal.reverb = 1.0
|
||||||
|
pedal.bright = 1.0
|
||||||
|
pedal.chorusDepth = 0.015
|
||||||
|
}
|
||||||
|
#expect(peak(left) <= 1.0 + ceilingEpsilon, "left peak \(peak(left)) exceeds the ±1 ceiling")
|
||||||
|
#expect(peak(right) <= 1.0 + ceilingEpsilon, "right peak \(peak(right)) exceeds the ±1 ceiling")
|
||||||
|
#expect(peak(left) > 0.3 && peak(right) > 0.3, "unexpectedly quiet at max gain")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesFullControlSurface() throws {
|
||||||
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
||||||
|
#expect(pedal.effectKnobs.map { $0.label }
|
||||||
|
== ["Gain", "Bass", "Mid", "Treble", "Reverb", "Rate", "Depth"])
|
||||||
|
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Chorus"])
|
||||||
|
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
|
||||||
|
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
|
||||||
|
#expect(pedal.widthUnits == 3)
|
||||||
|
#expect(pedal.showsMixControl == false)
|
||||||
|
#expect(pedal.channelKind == .widener, "Jazz Clean should be a stereo widener")
|
||||||
|
#expect(pedal.toneStackModel == .fender)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func controlsRoundTripThroughState() throws {
|
||||||
|
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
||||||
|
pedal.gain = 6.0
|
||||||
|
pedal.reverb = 0.5
|
||||||
|
pedal.chorusRate = 2.0
|
||||||
|
pedal.chorusDepth = 0.008
|
||||||
|
pedal.bright = 1.0
|
||||||
|
pedal.chorusEnabled = 0.0
|
||||||
|
pedal.cab = 3.0
|
||||||
|
let restored: JazzCleanAmpPedal = JazzCleanAmpPedal()
|
||||||
|
restored.applyState(pedal.captureState())
|
||||||
|
#expect(restored.gain == 6.0)
|
||||||
|
#expect(restored.reverb == 0.5)
|
||||||
|
#expect(restored.chorusRate == 2.0)
|
||||||
|
#expect(restored.chorusDepth == 0.008)
|
||||||
|
#expect(restored.bright == 1.0)
|
||||||
|
#expect(restored.chorusEnabled == 0.0)
|
||||||
|
#expect(restored.cab == 3.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func registeredInBuiltInRegistry() throws {
|
||||||
|
#expect(PedalRegistry.makePedal(type: "Jazz Clean") is JazzCleanAmpPedal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Routes two mono board buses to hardware left (0) and right (1) so the widener's channels can be
|
||||||
|
/// captured separately by `readStereoCAF`.
|
||||||
|
@MainActor
|
||||||
|
private final class JazzStereoSplitMaster: SynthesizerBase {
|
||||||
|
private let left: Int
|
||||||
|
private let right: Int
|
||||||
|
|
||||||
|
init(left: Int, right: Int) {
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func build() {
|
||||||
|
output(bus: 0, source: input(bus: left))
|
||||||
|
output(bus: 1, source: input(bus: right))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user