f8878324fd
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>
48 lines
2.3 KiB
Swift
48 lines
2.3 KiB
Swift
// DelayLineAllpassModulationTests.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import Testing
|
||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||
|
||
// MARK: - DelayLineAllpassModulationTests
|
||
|
||
/// Regression guard for the allpass fractional-delay interpolator's recursive-state
|
||
/// handling. When the delay lands on an exact integer sample (`frac == 0`) the interpolator
|
||
/// bypasses to the integer-delayed sample; its recursive state must record that sample as
|
||
/// the previous output. Leaving it stale (freezing the pre-bypass value) clicks when the
|
||
/// delay dwells on an integer and then moves off. The timeline dwells on an exact integer
|
||
/// then ramps a fractional delay out, and the allpass step is compared against the same
|
||
/// modulation through `.linear` interpolation, which has no recursive state and stays smooth.
|
||
@MainActor
|
||
@Suite("DelayLine allpass modulation")
|
||
struct DelayLineAllpassModulationTests {
|
||
|
||
/// Allpass-vs-linear sample-step ratio tolerated. Correct state handling keeps this
|
||
/// ~1×; freezing the stale state drives it past 3× for DelayLine.
|
||
let clickRatioLimit: Double = 2.0
|
||
|
||
@Test func modulatedAllpassDelayStaysClickFreeThroughIntegerDwell() throws {
|
||
let timeline: [Double] = modulatedDelayDwellTimeline()
|
||
let linear: [Double] = try renderModulatedDelay(delaySamples: timeline) { input, modulator, maxDelay in
|
||
DelayLine(input: input, maxDelay: maxDelay, delay: modulator,
|
||
sampleRate: delaySweepSampleRate, interpolation: .linear)
|
||
}
|
||
let allpass: [Double] = try renderModulatedDelay(delaySamples: timeline) { input, modulator, maxDelay in
|
||
DelayLine(input: input, maxDelay: maxDelay, delay: modulator,
|
||
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 delay clicks at integer dwell/crossing: allpass maxΔ \(allpassStep) vs linear \(linearStep)"
|
||
)
|
||
}
|
||
}
|