v1.7.2 release: sample-rate-invariant TriodeStage coupling + Mesa/Soldano tone stacks

- TriodeStage coupling DC-blocker corner is now held constant in Hz across sample
  rates (was a fixed pole whose corner drifted up with Fs, thinning low end at high
  rates); evaluated at init, off the RT thread.
- New ToneStackModel cases .mesa and .soldano (Faust tonestacks-library values).
- GrayNoise output clamped to [-1, 1] (Int32.min edge).
This commit is contained in:
2026-08-03 15:57:54 -07:00
parent ea0aa84ca7
commit 77580ee98e
7 changed files with 135 additions and 11 deletions
@@ -79,6 +79,21 @@ struct ToneStackTests {
#expect(relativeDiff > 0.05, "Fender vs Vox 800 Hz response too close: rel=\(relativeDiff)")
}
@Test func mesaAndSoldanoAreDistinctModels() {
// The Mesa (deeper mid scoop) and Soldano (tighter Marshall-derived) stacks must voice
// differently from Fender and from each other at the midrange.
let freq: Double = 800.0
func midRMS(_ model: ToneStackModel) -> Double {
rms(Array(steadyRMS(freqHz: freq, bass: 0.5, mid: 0.5, treble: 0.5, model: model).suffix(engine.blockSize * 100)))
}
let fender: Double = midRMS(.fender)
let mesa: Double = midRMS(.mesa)
let soldano: Double = midRMS(.soldano)
#expect(abs(mesa - fender) / Swift.max(mesa, fender) > 0.05, "Mesa too close to Fender: mesa=\(mesa) fender=\(fender)")
#expect(abs(mesa - soldano) / Swift.max(mesa, soldano) > 0.05, "Mesa too close to Soldano: mesa=\(mesa) soldano=\(soldano)")
#expect(abs(soldano - fender) / Swift.max(soldano, fender) > 0.05, "Soldano too close to Fender: soldano=\(soldano) fender=\(fender)")
}
@Test func blocksDCInSteadyState() {
// The passive tone stack has series coupling caps → exactly zero DC gain (the numerator
// has no constant term; the discretized B0…B3 sum to 0). A constant input must decay to
@@ -110,4 +110,35 @@ struct TriodeStageTests {
#expect(naiveRatio > 0.05, "baseline did not alias as expected (ratio=\(naiveRatio))")
#expect(osRatio < naiveRatio * 0.5, "oversampling did not reduce aliasing: os=\(osRatio) naive=\(naiveRatio)")
}
@Test func couplingPoleMatchesLegacyAtReferenceRate() {
// The sample-rate-aware coupling pole must equal the legacy fixed coefficient at 44.1 kHz,
// so the historical 44.1 / 48 kHz voicing is unchanged.
#expect(abs(TriodeStage.couplingPole(sampleRate: 44_100.0) - leakDCDefaultAudioCoef) < 1.0e-12)
}
@Test func couplingCornerIsSampleRateInvariant() throws {
// The DC-blocker corner must stay fixed in Hz across sample rates — with the old fixed pole
// the corner drifted up with Fs and thinned the low end at 88.2 / 96 kHz. Measure |H| at a
// low frequency (small amplitude → near-linear) and confirm it matches across rates.
let lowHz: Double = 40.0
func lowFreqTransfer(atSampleRate rate: Double) throws -> Double {
let eng: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: rate)
try eng.start()
let blocks: Int = 400
let tailLen: Int = eng.blockSize * 256
let sineIn: OscSin.Audio = OscSin.Audio(freq: lowHz, mul: 0.05)
let inTail: [Double] = Array(collectBlocks(sineIn, engine: eng, blocks: blocks).suffix(tailLen))
let sine: OscSin.Audio = OscSin.Audio(freq: lowHz, mul: 0.05)
let stage: TriodeStage = TriodeStage(input: sine, drive: 1.0, bias: 0.0, oversample: 2)
let outTail: [Double] = Array(collectBlocks(stage, engine: eng, blocks: blocks).suffix(tailLen))
let cps: Double = lowHz / rate
return goertzel(outTail, cyclesPerSample: cps) / goertzel(inTail, cyclesPerSample: cps)
}
let h48: Double = try lowFreqTransfer(atSampleRate: 48_000.0)
let h96: Double = try lowFreqTransfer(atSampleRate: 96_000.0)
#expect(h48 > 0.5 && h96 > 0.5, "low-frequency transfer implausibly low (48k=\(h48) 96k=\(h96))")
#expect(abs(h96 - h48) / h48 < 0.1,
"coupling corner drifts with sample rate: |H(40Hz)| 48k=\(h48) 96k=\(h96)")
}
}