fix(amps): master review follow-ups — tone-proving test, headroom, default
- britishMasterDrivesPowerAmp now uses an RMS-normalized SSD so it proves Master changes the *waveshape* (power-amp saturation), not merely level — a raw SSD couldn't distinguish the two, and distinguishing them is the whole point vs `level`. - Add powerAmpOversample hook (default 2); British overrides to 4 so the higher Master drive (up to 5.0 vs the fixed 1.5) has anti-alias headroom. - British Master default 0.3 → 0.22 so it maps to ≈1.5 drive, keeping the amp's out-of-box tone unchanged. - Add a max-Master (gain 30 + Master 1.0) ceiling test; DocC no longer links the private powerAmpDrive symbol. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,25 @@ struct AmpVoicePedalTests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sum-of-squared-differences after RMS-normalizing each window, so a pure level difference
|
||||
/// collapses to ~0 and only a genuine waveshape (saturation) change registers.
|
||||
private func rmsNormalizedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double {
|
||||
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
|
||||
let aw: ArraySlice<Float> = a[skip..<(skip + window)]
|
||||
let bw: ArraySlice<Float> = b[skip..<(skip + window)]
|
||||
func rms(_ x: ArraySlice<Float>) -> Double {
|
||||
let sumSq: Double = x.reduce(0.0) { $0 + Double($1) * Double($1) }
|
||||
return (sumSq / Double(x.count)).squareRoot()
|
||||
}
|
||||
let ra: Double = rms(aw)
|
||||
let rb: Double = rms(bw)
|
||||
guard ra > 0.0, rb > 0.0 else { return 0.0 }
|
||||
return zip(aw, bw).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0) / ra - Double(pair.1) / rb
|
||||
return acc + d * d
|
||||
}
|
||||
}
|
||||
|
||||
/// The three concrete voices under test, keyed by their display name / registry key.
|
||||
private let voices: [(name: String, make: () -> AmpVoicePedal)] = [
|
||||
("California", { CaliforniaAmpPedal() }),
|
||||
@@ -128,13 +147,26 @@ struct AmpVoicePedalTests {
|
||||
}
|
||||
|
||||
@Test func britishMasterDrivesPowerAmp() throws {
|
||||
// Master drives the power-amp stage, so at fixed preamp Gain a low vs high Master must
|
||||
// change the tone (power-amp saturation), not merely the level — verify the waveform differs
|
||||
// after normalizing out any overall level change.
|
||||
// Master drives the power-amp stage into saturation — so it must change the *waveshape*, not
|
||||
// just the level (which is what `level` would do). RMS-normalize each window before diffing:
|
||||
// a pure level change collapses to ~0, so a clearly-positive normalized SSD proves genuine
|
||||
// power-amp saturation.
|
||||
let low: [Float] = try render({ BritishAmpPedal() }) { $0.gain = 12.0; $0.master = 0.1 }
|
||||
let high: [Float] = try render({ BritishAmpPedal() }) { $0.gain = 12.0; $0.master = 1.0 }
|
||||
#expect(hasNonSilentOutput(low) && hasNonSilentOutput(high))
|
||||
#expect(windowedSSD(low, high) > 0, "Master had no effect on the power-amp stage")
|
||||
#expect(rmsNormalizedSSD(low, high) > 1.0e-3, "Master changed level but not tone (no power-amp saturation)")
|
||||
}
|
||||
|
||||
@Test func britishStaysWithinCeilingAtMaxMaster() throws {
|
||||
let ceilingEpsilon: Double = 1.0e-4
|
||||
let hot: [Float] = try render({ BritishAmpPedal() }) { (pedal: BritishAmpPedal) in
|
||||
pedal.gain = 30.0
|
||||
pedal.bass = 1.0
|
||||
pedal.treble = 1.0
|
||||
pedal.master = 1.0
|
||||
}
|
||||
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||
#expect(peak <= 1.0 + ceilingEpsilon, "British peak \(peak) exceeds the ±1 ceiling at max Master")
|
||||
}
|
||||
|
||||
@Test func britishMasterRoundTripsThroughState() throws {
|
||||
|
||||
Reference in New Issue
Block a user