fix(amps): Jazz Clean chorus depth range + true stereo tests

Review fixes:
- chorusDepth was defaulted 0.3 with a 0..1 range, but the Chorus generator's
  depth is a fraction of the delay time — that's ~30-300× the classic-chorus
  band and produces pitch wobble, not lush chorus. Retune to default 0.005,
  range 0.0005...0.015 (matching the ModulationPedal precedent).
- Tests now render the widener as true stereo (outputBusRight + split master),
  asserting L≠R when the chorus is engaged and bit-exact L==R when bypassed, and
  checking the ±1 ceiling on BOTH channels — the prior suite only exercised the
  left channel.
- AmpVoicePedal base doc lists Jazz Clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 08:20:23 -07:00
parent 102715ded1
commit 29b1747533
4 changed files with 97 additions and 46 deletions
@@ -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:
@@ -31,8 +31,9 @@ public final class JazzCleanAmpPedal: AmpVoicePedal {
@UIParam public var reverb: Double = 0.2 @UIParam public var reverb: Double = 0.2
/// Chorus LFO rate in Hz. Range [0.1, 5.0]. /// Chorus LFO rate in Hz. Range [0.1, 5.0].
@UIParam public var chorusRate: Double = 0.8 @UIParam public var chorusRate: Double = 0.8
/// Chorus depth as a fraction of the base delay time, in [0, 1]. /// Chorus depth as a fraction of the base delay time. Kept in the classic-chorus band
@UIParam public var chorusDepth: Double = 0.3 /// (~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. /// Bright switch: `0` = flat, `1` = treble shelf engaged.
@UIParam public var bright: Double = 0.0 @UIParam public var bright: Double = 0.0
/// Chorus footswitch: `1` = chorus engaged (stereo), `0` = bypassed (dry, mono-equivalent). /// Chorus footswitch: `1` = chorus engaged (stereo), `0` = bypassed (dry, mono-equivalent).
@@ -51,7 +52,7 @@ public final class JazzCleanAmpPedal: AmpVoicePedal {
private let reverbRange: ClosedRange<Double> = 0.0 ... 1.0 private let reverbRange: ClosedRange<Double> = 0.0 ... 1.0
private let chorusRateRange: ClosedRange<Double> = 0.1 ... 5.0 private let chorusRateRange: ClosedRange<Double> = 0.1 ... 5.0
private let chorusDepthRange: ClosedRange<Double> = 0.0 ... 1.0 private let chorusDepthRange: ClosedRange<Double> = 0.0005 ... 0.015
private let switchOffValue: Double = 0.0 private let switchOffValue: Double = 0.0
private let switchOnValue: Double = 1.0 private let switchOnValue: Double = 1.0
+1 -1
View File
@@ -797,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)
} }
@@ -16,95 +16,126 @@ struct JazzCleanAmpPedalTests {
private let sampleRate: Double = 48000.0 private let sampleRate: Double = 48000.0
/// Renders the left channel through a bare engine. As with the other widener-pedal suites, the /// Renders the amp as a stereo widener, returning the separated (left, right) channels — the
/// right channel needs a board stereo region, so this exercises the mono core → chorus.left → /// pedal's `outputBusRight` is wired to a second bus and a split master routes both to the
/// cabinet path; the control-surface / stereo config is asserted directly below. /// hardware L/R so `readStereoCAF` can capture them independently.
private func render(configure: (JazzCleanAmpPedal) -> Void = { _ in }) throws -> [Float] { private func renderStereo(configure: (JazzCleanAmpPedal) -> Void = { _ in }) throws
-> (left: [Float], right: [Float]) {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine( let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.3, sampleRate: sampleRate, numAudioBuses: 64) duration: 0.3, sampleRate: sampleRate, numAudioBuses: 64)
defer { try? FileManager.default.removeItem(at: url) } defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: 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 { defer {
engine.busAllocator.releaseAudioBus(srcBus) engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus) engine.busAllocator.releaseAudioBus(dstL)
engine.busAllocator.releaseAudioBus(dstR)
} }
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index) let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal(inputBus: srcBus.index, outputBus: dstBus.index) let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal(inputBus: srcBus.index, outputBus: dstL.index)
pedal.outputBusRight = dstR.index
pedal.sampleRate = sampleRate pedal.sampleRate = sampleRate
configure(pedal) configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index) let master: JazzStereoSplitMaster = JazzStereoSplitMaster(left: dstL.index, right: dstR.index)
try engine.add(source) try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source)) try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal)) try engine.add(master, position: NodePosition.after(pedal))
try engine.start() try engine.start()
return readStereoCAF(url: url, sampleRate: sampleRate)
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 = 4096, window: Int = 4096) -> Double { 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 } 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 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 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 { @Test func buildsNonSilentFiniteOutput() throws {
let samples: [Float] = try render() let (left, right): ([Float], [Float]) = try renderStereo()
#expect(!samples.isEmpty) #expect(hasNonSilentOutput(left), "Jazz Clean left channel was silent")
#expect(hasNonSilentOutput(samples), "Jazz Clean produced silence") #expect(hasNonSilentOutput(right), "Jazz Clean right channel was silent")
#expect(samples.allSatisfy { $0.isFinite }, "Jazz Clean produced non-finite output") #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 { @Test func chorusRateChangesOutput() throws {
let slow: [Float] = try render { $0.chorusRate = 0.2 } let slow: [Float] = try renderStereo { $0.chorusRate = 0.2 }.left
let fast: [Float] = try render { $0.chorusRate = 5.0 } let fast: [Float] = try renderStereo { $0.chorusRate = 5.0 }.left
#expect(windowedSSD(slow, fast) > 0, "chorus rate had no effect") #expect(windowedSSD(slow, fast) > 0, "chorus rate had no effect")
} }
@Test func chorusDepthChangesOutput() throws { @Test func chorusDepthChangesOutput() throws {
let shallow: [Float] = try render { $0.chorusDepth = 0.05 } let shallow: [Float] = try renderStereo { $0.chorusDepth = 0.001 }.left
let deep: [Float] = try render { $0.chorusDepth = 0.9 } let deep: [Float] = try renderStereo { $0.chorusDepth = 0.014 }.left
#expect(windowedSSD(shallow, deep) > 0, "chorus depth had no effect") #expect(windowedSSD(shallow, deep) > 0, "chorus depth had no effect")
} }
@Test func reverbMixChangesOutput() throws { @Test func reverbMixChangesOutput() throws {
let dry: [Float] = try render { $0.reverb = 0.0 } let dry: [Float] = try renderStereo { $0.reverb = 0.0 }.left
let wet: [Float] = try render { $0.reverb = 0.9 } let wet: [Float] = try renderStereo { $0.reverb = 0.9 }.left
#expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect") #expect(windowedSSD(dry, wet) > 0, "reverb mix had no effect")
} }
@Test func brightSwitchChangesOutput() throws { @Test func brightSwitchChangesOutput() throws {
let flat: [Float] = try render { $0.bright = 0.0 } let flat: [Float] = try renderStereo { $0.bright = 0.0 }.left
let bright: [Float] = try render { $0.bright = 1.0 } let bright: [Float] = try renderStereo { $0.bright = 1.0 }.left
#expect(windowedSSD(flat, bright) > 0, "bright switch had no effect") #expect(windowedSSD(flat, bright) > 0, "bright switch had no effect")
} }
@Test func chorusFootswitchBypasses() throws { @Test func bothChannelsStayWithinCeilingWithFXEngaged() throws {
// Off must differ from on; and with the chorus off the Rate knob is irrelevant (mix 0 →
// dry), so two off-renders at different rates are bit-identical.
let on: [Float] = try render { $0.chorusEnabled = 1.0; $0.chorusRate = 3.0 }
let off: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 3.0 }
#expect(windowedSSD(on, off) > 0, "chorus footswitch had no effect")
let offSlow: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 0.2 }
let offFast: [Float] = try render { $0.chorusEnabled = 0.0; $0.chorusRate = 5.0 }
#expect(windowedSSD(offSlow, offFast) == 0.0, "chorus off should ignore rate (dry pass-through)")
}
@Test func outputStaysWithinCeilingWithFXEngaged() throws {
let ceilingEpsilon: Double = 1.0e-4 let ceilingEpsilon: Double = 1.0e-4
let hot: [Float] = try render { (pedal: JazzCleanAmpPedal) in let (left, right): ([Float], [Float]) = try renderStereo { (pedal: JazzCleanAmpPedal) in
pedal.gain = 30.0 pedal.gain = 30.0
pedal.bass = 1.0 pedal.bass = 1.0
pedal.treble = 1.0 pedal.treble = 1.0
pedal.reverb = 1.0 pedal.reverb = 1.0
pedal.bright = 1.0 pedal.bright = 1.0
pedal.chorusDepth = 0.9 pedal.chorusDepth = 0.015
} }
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) } #expect(peak(left) <= 1.0 + ceilingEpsilon, "left peak \(peak(left)) exceeds the ±1 ceiling")
#expect(peak <= 1.0 + ceilingEpsilon, "peak \(peak) exceeds the ±1 ceiling") #expect(peak(right) <= 1.0 + ceilingEpsilon, "right peak \(peak(right)) exceeds the ±1 ceiling")
#expect(peak > 0.3, "unexpectedly quiet at max gain: \(peak)") #expect(peak(left) > 0.3 && peak(right) > 0.3, "unexpectedly quiet at max gain")
} }
@Test func exposesFullControlSurface() throws { @Test func exposesFullControlSurface() throws {
@@ -125,7 +156,7 @@ struct JazzCleanAmpPedalTests {
pedal.gain = 6.0 pedal.gain = 6.0
pedal.reverb = 0.5 pedal.reverb = 0.5
pedal.chorusRate = 2.0 pedal.chorusRate = 2.0
pedal.chorusDepth = 0.4 pedal.chorusDepth = 0.008
pedal.bright = 1.0 pedal.bright = 1.0
pedal.chorusEnabled = 0.0 pedal.chorusEnabled = 0.0
pedal.cab = 3.0 pedal.cab = 3.0
@@ -134,7 +165,7 @@ struct JazzCleanAmpPedalTests {
#expect(restored.gain == 6.0) #expect(restored.gain == 6.0)
#expect(restored.reverb == 0.5) #expect(restored.reverb == 0.5)
#expect(restored.chorusRate == 2.0) #expect(restored.chorusRate == 2.0)
#expect(restored.chorusDepth == 0.4) #expect(restored.chorusDepth == 0.008)
#expect(restored.bright == 1.0) #expect(restored.bright == 1.0)
#expect(restored.chorusEnabled == 0.0) #expect(restored.chorusEnabled == 0.0)
#expect(restored.cab == 3.0) #expect(restored.cab == 3.0)
@@ -144,3 +175,22 @@ struct JazzCleanAmpPedalTests {
#expect(PedalRegistry.makePedal(type: "Jazz Clean") is JazzCleanAmpPedal) #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))
}
}