prep for 1.2.0 release updates
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
// FBSineSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - FBSineSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("FBSineStepped.Audio")
|
||||
struct FBSineSteppedAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func deterministicSteppedIterations() {
|
||||
// freq == sampleRate, .none → held outputs are the warm-up iterates 2,3,…
|
||||
let m: FBSineStepped.Audio = FBSineStepped.Audio(freq: sr, interpolation: .none)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][0] - (0.5818307174710479)) < 1e-9)
|
||||
#expect(abs(s[0][1] - (0.9422154392244042)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let m: FBSineStepped.Audio = FBSineStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - (0.5818307174710479)) < 1e-9 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let m: FBSineStepped.Audio = FBSineStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) <= 1.0 + 1e-12 }) // x = sin in [-1,1]
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let m: FBSineStepped.Audio = FBSineStepped.Audio(freq: 4000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: FBSineStepped.Audio = FBSineStepped.Audio(freq: 8000.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 10)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: FBSineStepped.Audio = FBSineStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: FBSineStepped.Audio = FBSineStepped.Audio(freq: 8000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: FBSineStepped.Audio = FBSineStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: FBSineStepped.Audio = FBSineStepped.Audio(freq: 0.0, mul: 0.5, add: 1.0)
|
||||
let g2: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: Double = scaled.calculatedSamples(graph: g2, count: engine.blockSize)[0][0]
|
||||
#expect(abs(s - (p * 0.5 + 1.0)) < 1e-12)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user