// DelayLineFeedbackAllpassModulationTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing @testable @_spi(LyrebirdExtensions) import LyrebirdSynth // MARK: - DelayLineFeedbackAllpassModulationTests /// Regression guard for the allpass fractional-delay interpolator's recursive-state /// handling in `DelayLineFeedback` under delay modulation. On an exact integer delay /// (`frac == 0`) the interpolator must record the integer-delayed sample as its previous /// output; freezing the stale value clicks when the delay moves back off the integer. Measured against /// the same modulation through `.linear` interpolation. See /// `DelayLineAllpassModulationTests` for the timeline rationale. @MainActor @Suite("DelayLineFeedback allpass modulation") struct DelayLineFeedbackAllpassModulationTests { let clickRatioLimit: Double = 2.0 /// Moderate feedback — high feedback rings enough to mask the click in the global metric. let feedbackDecayTime: Double = 0.012 @Test func modulatedAllpassDelayStaysClickFreeThroughIntegerDwell() throws { let timeline: [Double] = modulatedDelayDwellTimeline() let linear: [Double] = try renderModulatedDelay(delaySamples: timeline) { input, modulator, maxDelay in DelayLineFeedback(input: input, maxDelay: maxDelay, delay: modulator, decayTime: feedbackDecayTime, sampleRate: delaySweepSampleRate, interpolation: .linear) } let allpass: [Double] = try renderModulatedDelay(delaySamples: timeline) { input, modulator, maxDelay in DelayLineFeedback(input: input, maxDelay: maxDelay, delay: modulator, decayTime: feedbackDecayTime, sampleRate: delaySweepSampleRate, interpolation: .allpass) } #expect(allpass.allSatisfy { $0.isFinite }, "allpass output must be finite") let linearStep: Double = maxAbsDelta(linear) let allpassStep: Double = maxAbsDelta(allpass) #expect(linearStep > 0, "linear reference should have non-zero motion") #expect( allpassStep < clickRatioLimit * linearStep, "modulated allpass feedback delay clicks at integer dwell exit: allpass maxΔ \(allpassStep) vs linear \(linearStep)" ) } }