69 lines
2.7 KiB
Swift
69 lines
2.7 KiB
Swift
// PanAzParameterRampingTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@Suite("PanAz parameter ramping")
|
|
struct PanAzParameterRampingTests {
|
|
|
|
@Test func azimuthRampIsApplied() throws {
|
|
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
|
try engine.start()
|
|
defer { engine.stop() }
|
|
|
|
let lastSampleIdx: Int = engine.blockSize - 1
|
|
|
|
let pan: PanAz = PanAz(input: ConstantGeneratorInput(1.0))
|
|
pan.azimuth = 0.0 // front centre
|
|
|
|
// Block 1: settle az=0.
|
|
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
|
_ = pan.calculatedSamples(graph: g1, count: 64)
|
|
advanceBlock(engine)
|
|
|
|
// Block 2: ramp azimuth to π/4 (RF corner).
|
|
pan.azimuth = .pi / 4
|
|
let g2: SynthGraph = makeSynthGraph(engine: engine)
|
|
let out2: [[Double]] = pan.calculatedSamples(graph: g2, count: 64)
|
|
// At sample lastSampleIdx, az ≈ π/4 → hard-RF. ch0 (LF) ≈ 0, ch1 (RF) ≈ 1.
|
|
let ch0Last: Double = abs(out2[0][lastSampleIdx])
|
|
let ch1Last: Double = abs(out2[1][lastSampleIdx])
|
|
#expect(ch0Last < 1e-4, "After azimuth=π/4 ramp: LF (ch0) should be near 0")
|
|
#expect(ch1Last > 0.9, "After azimuth=π/4 ramp: RF (ch1) should dominate (>0.9), got \(ch1Last)")
|
|
}
|
|
|
|
@Test func azimuthRampSweepsFrontToRear() throws {
|
|
let engine: SynthesisEngine = makeTestEngine(blockSize: 64)
|
|
try engine.start()
|
|
defer { engine.stop() }
|
|
|
|
let lastSampleIdx: Int = engine.blockSize - 1
|
|
|
|
let pan: PanAz = PanAz(input: ConstantGeneratorInput(1.0))
|
|
pan.azimuth = 0.0 // front centre
|
|
|
|
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
|
_ = pan.calculatedSamples(graph: g1, count: 64)
|
|
advanceBlock(engine)
|
|
|
|
// Block 2: ramp azimuth to π (rear centre).
|
|
pan.azimuth = .pi
|
|
let g2: SynthGraph = makeSynthGraph(engine: engine)
|
|
let out2: [[Double]] = pan.calculatedSamples(graph: g2, count: 64)
|
|
// At last sample az=π → (0, -1) → RR + LR even split, LF + RF ≈ 0.
|
|
let ch0Last: Double = abs(out2[0][lastSampleIdx])
|
|
let ch1Last: Double = abs(out2[1][lastSampleIdx])
|
|
let ch2Last: Double = abs(out2[2][lastSampleIdx])
|
|
let ch3Last: Double = abs(out2[3][lastSampleIdx])
|
|
#expect(ch0Last < 1e-4, "After az=π ramp: LF should be near 0")
|
|
#expect(ch1Last < 1e-4, "After az=π ramp: RF should be near 0")
|
|
#expect(ch2Last > 0.5, "After az=π ramp: RR should carry rear energy")
|
|
#expect(ch3Last > 0.5, "After az=π ramp: LR should carry rear energy")
|
|
}
|
|
}
|