Files
Lyrebird/Tests/LyrebirdTests/Generators/Delays/DelayLineFeedbackAllpassModulationTests.swift
T
josh f8878324fd v2.1.1 release: delay-click fix + internal consolidation
Mirror of Lyrebird dev HEAD (9f791c7c) minus maintainer-only paths. Patch release:
fixes the allpass fractional-delay click (DelayLine/CombFilter/AllpassFilter/
DelayLineFeedback under a modulated delay) and lands the internal code-quality
consolidation pass (~160 deduped sites + shared base classes/helpers, bit-identical
output). No public API removed or changed. See RELEASES.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-07 21:20:49 -07:00

49 lines
2.3 KiB
Swift

// 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)"
)
}
}