Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/ChimeVariantsTests.swift
T
josh f9ddd6b160 feat(amp): Gain/Drive become a 1–11 dial with a musical taper
Every amp's Gain (and the boutique/drive-channel Drive) is now a 1–11 dial —
yes, it goes to eleven — instead of the raw 1–30 tube-drive number.

- New AmpVoicePedal.taperedDrive(_:) maps the 1–11 dial to the 1–30 tube drive
  through an exponential LinExp taper, so 1 is nearly clean, 11 is full
  saturation, and the useful grind spreads across the dial (fine at the bottom,
  steep at the top) rather than bunching near the low end.
- Wired into the base preampStage and every override that feeds a drive:
  Boutique / Fullerton Drive / Jazz Clean / British Dual (Drive channel),
  Anaheim (SS preamp), British Master (cascaded stage).
- gainRange / driveRange → 1...11; every amp's default gain/drive reconverted
  from drive-space to the equivalent dial value (dial = 1 + 10·ln(drive)/ln(30)),
  so each amp's shipped voicing is preserved.
- No preset migration (nothing shipped — per product owner); all knob work
  stays within ShoeGaze (no core Lyrebird change).
- Tests updated to the 1–11 scale; added range + exponential-taper assertions.

671 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-04 10:42:35 -07:00

128 lines
5.5 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.
// ChimeVariantsTests.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("Chime variants")
struct ChimeVariantsTests {
private let sampleRate: Double = 48000.0
private func render<P: AmpVoicePedal>(_ make: () -> P, configure: (P) -> Void = { _ in }) throws -> [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 dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: P = make()
pedal.inputBus = srcBus.index
pedal.outputBus = dstBus.index
pedal.sampleRate = sampleRate
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url, sampleRate: sampleRate)
}
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> 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 let variants: [(name: String, make: () -> ChimeAmpPedal)] = [
("Chime 15", { ChimeFifteenAmpPedal() }),
("Chime Normal", { ChimeNormalAmpPedal() }),
("Chime Baby", { ChimeBabyAmpPedal() }),
]
@Test func allBuildNonSilentFinite() throws {
for v: (name: String, make: () -> ChimeAmpPedal) in variants {
let s: [Float] = try render(v.make)
#expect(hasNonSilentOutput(s), "\(v.name) produced silence")
#expect(s.allSatisfy { $0.isFinite }, "\(v.name) produced non-finite output")
}
}
@Test func cutChangesOutput() throws {
for v: (name: String, make: () -> ChimeAmpPedal) in variants {
let open: [Float] = try render(v.make) { $0.cut = 0.0 }
let dark: [Float] = try render(v.make) { $0.cut = 1.0 }
#expect(windowedSSD(open, dark) > 0, "\(v.name) Cut had no effect")
}
}
@Test func inheritCutSurfaceAndChimeStack() throws {
for v: (name: String, make: () -> ChimeAmpPedal) in variants {
let pedal: ChimeAmpPedal = v.make()
#expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"], "\(v.name) knobs")
#expect(pedal.toneStackModel == .vox, "\(v.name) tone stack")
}
}
@Test func breakupVariantsOversampleAtFour() throws {
// Chime 15 and Chime Baby drive the power amp harder → 4× oversample; Normal keeps the base.
#expect(ChimeFifteenAmpPedal().powerAmpOversample == 4)
#expect(ChimeBabyAmpPedal().powerAmpOversample == 4)
#expect(ChimeNormalAmpPedal().powerAmpOversample == 2)
}
@Test func variantsDifferFromEachOther() throws {
let cfg: (ChimeAmpPedal) -> Void = { $0.gain = 6.0; $0.cut = 0.2 }
let fifteen: [Float] = try render({ ChimeFifteenAmpPedal() }, configure: cfg)
let normal: [Float] = try render({ ChimeNormalAmpPedal() }, configure: cfg)
let baby: [Float] = try render({ ChimeBabyAmpPedal() }, configure: cfg)
#expect(windowedSSD(fifteen, normal) > 0, "Chime 15 and Normal should voice differently")
#expect(windowedSSD(normal, baby) > 0, "Chime Normal and Baby should voice differently")
#expect(windowedSSD(fifteen, baby) > 0, "Chime 15 and Baby should voice differently")
}
@Test func stayWithinCeilingAtMaxGain() throws {
let ceilingEpsilon: Double = 1.0e-4
for v: (name: String, make: () -> ChimeAmpPedal) in variants {
let hot: [Float] = try render(v.make) { (pedal: ChimeAmpPedal) in
pedal.gain = 11.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.cut = 0.0
}
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "\(v.name) peak \(peak) exceeds the ±1 ceiling")
}
}
@Test func cutRoundTripsThroughState() throws {
let pedal: ChimeBabyAmpPedal = ChimeBabyAmpPedal()
pedal.cut = 0.7
pedal.cab = 3.0
let restored: ChimeBabyAmpPedal = ChimeBabyAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.cut == 0.7 && restored.cab == 3.0, "Chime Baby state did not round-trip")
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Chime 15") is ChimeFifteenAmpPedal)
#expect(PedalRegistry.makePedal(type: "Chime Normal") is ChimeNormalAmpPedal)
#expect(PedalRegistry.makePedal(type: "Chime Baby") is ChimeBabyAmpPedal)
}
}