prep for 1.2.0 release updates
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// LFGaussControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LFGaussControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LFGauss.Control")
|
||||
struct LFGaussControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func outputWithinUnitRange() {
|
||||
let gauss: LFGauss.Control = LFGauss.Control(period: 0.05, width: 0.2)
|
||||
let samples: [Double] = collectBlocks(gauss, engine: engine, blocks: 60)
|
||||
// Linear ramp between bell values stays bounded in [0, 1].
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { $0 >= -1e-12 && $0 <= 1.0 + 1e-12 })
|
||||
}
|
||||
|
||||
@Test func lastSampleMatchesBellValueAtAdvancedPhase() {
|
||||
// First block: phase advances by dt·count from 0; ramp end == bell value at new phase.
|
||||
let period: Double = 0.05
|
||||
let width: Double = 0.2
|
||||
let gauss: LFGauss.Control = LFGauss.Control(period: period, width: width, phase: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let samples: [[Double]] = gauss.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
|
||||
let dt: Double = 1.0 / (period * sr)
|
||||
let advancedPhase: Double = dt * Double(engine.blockSize)
|
||||
let x: Double = 2.0 * advancedPhase - 1.0
|
||||
let aTerm: Double = x / width
|
||||
let expected: Double = exp(-0.5 * aTerm * aTerm)
|
||||
#expect(abs(samples[0][engine.blockSize - 1] - expected) < 1e-10)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let gauss: LFGauss.Control = LFGauss.Control(period: 0.05, width: 0.2)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = gauss.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = gauss.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user