// CabinetIRFactoryTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing import Foundation import LyrebirdSynth @testable import LyrebirdShoeGaze @MainActor @Suite("CabinetIRFactory") struct CabinetIRFactoryTests { private let sampleRate: Double = 48000.0 /// Goertzel magnitude of the IR's frequency response at `hz`. private func responseMagnitude(_ ir: LyrebirdBuffer, hz: Double) -> Double { let omega: Double = 2.0 * Double.pi * hz / sampleRate let cosine: Double = cos(omega) let sine: Double = sin(omega) let coeff: Double = 2.0 * cosine var s1: Double = 0.0 var s2: Double = 0.0 for i: Int in 0.. 0.9 && peak <= 1.0001, "\(voice) IR not peak-normalized: \(peak)") } } @Test func rollsOffLowAndHighFrequencies() { // A speaker cab attenuates sub-bass and high treble relative to the midrange. let ir: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, sampleRate: sampleRate) let low: Double = responseMagnitude(ir, hz: 40.0) // below the ~80 Hz high-pass let mid: Double = responseMagnitude(ir, hz: 800.0) // passband let high: Double = responseMagnitude(ir, hz: 12000.0) // above the ~5.5 kHz low-pass #expect(mid > low * 2.0, "low end not attenuated (mid=\(mid) low=\(low))") #expect(mid > high * 2.0, "high end not attenuated (mid=\(mid) high=\(high))") } @Test func voicesDifferInResponse() { let american: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, sampleRate: sampleRate) let dark: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .vintageDark, sampleRate: sampleRate) // The darker voice rolls off earlier, so it has less 5 kHz energy than the American voice. let americanHigh: Double = responseMagnitude(american, hz: 5000.0) let darkHigh: Double = responseMagnitude(dark, hz: 5000.0) #expect(americanHigh > darkHigh, "vintageDark should be darker at 5 kHz") } }