prep for 1.2.0 release updates
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// SpectralProcessor2Tests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
@MainActor
|
||||
@Suite("SpectralProcessor2 dispatch")
|
||||
struct SpectralProcessor2Tests {
|
||||
|
||||
/// Counts calls and records the buffer references it received. Lets us
|
||||
/// verify SpectralChain.Audio is dispatching with the correct host +
|
||||
/// side-chain spectral buffers.
|
||||
private final class CountingDualProcessor: SpectralProcessor2 {
|
||||
var callCount: Int = 0
|
||||
var lastHost: SpectralBuffer?
|
||||
var lastSide: SpectralBuffer?
|
||||
func process(spectral: SpectralBuffer,
|
||||
sideChain: SpectralBuffer, engine: SynthesisEngine) {
|
||||
callCount += 1
|
||||
lastHost = spectral
|
||||
lastSide = sideChain
|
||||
}
|
||||
}
|
||||
|
||||
@Test func dualProcessorReceivesHostAndSideChainBuffers() throws {
|
||||
let fftSize: Int = 64
|
||||
let hopSize: Int = 32
|
||||
let blockSize: Int = hopSize
|
||||
|
||||
let engine: SynthesisEngine = makeTestEngine(blockSize: blockSize)
|
||||
try engine.start()
|
||||
defer { engine.stop() }
|
||||
|
||||
let sideAnalysis: SpectralChain.Audio = SpectralChain.Audio(input: Double(1.0),
|
||||
fftSize: fftSize, hopSize: hopSize,
|
||||
analyzeOnly: true)
|
||||
let counter: SpectralProcessor2Tests.CountingDualProcessor = CountingDualProcessor()
|
||||
let mainAnalysis: SpectralChain.Audio = SpectralChain.Audio(
|
||||
input: Double(0.5),
|
||||
fftSize: fftSize, hopSize: hopSize,
|
||||
stages: [.dual(counter, sideChain: sideAnalysis)],
|
||||
analyzeOnly: true
|
||||
)
|
||||
|
||||
// Run several blocks. Side-chain must be evaluated before main so its
|
||||
// spectralBuffer is fresh when the main hop fires.
|
||||
for _ in 0..<4 {
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
_ = sideAnalysis.calculatedSamples(graph: g, count: blockSize)
|
||||
_ = mainAnalysis.calculatedSamples(graph: g, count: blockSize)
|
||||
advanceBlock(engine)
|
||||
}
|
||||
|
||||
#expect(counter.callCount > 0,
|
||||
"Dual processor should be called at least once after several hops")
|
||||
#expect(counter.lastHost === mainAnalysis.spectralBuffer,
|
||||
"Host buffer should be the main analysis spectralBuffer")
|
||||
#expect(counter.lastSide === sideAnalysis.spectralBuffer,
|
||||
"Side-chain buffer should be the side analysis spectralBuffer")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user