prep for 1.2.0 release updates
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// ChaoticInterpolateTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - ChaoticInterpolateTests
|
||||
|
||||
@Suite("chaoticInterpolate")
|
||||
struct ChaoticInterpolateTests {
|
||||
|
||||
let hM1: Double = -0.5
|
||||
let h0: Double = 0.2
|
||||
let h1: Double = 0.9
|
||||
let h2: Double = -0.3
|
||||
|
||||
@Test func noneHoldsSegmentStart() {
|
||||
#expect(chaoticInterpolate(.none, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) == h0)
|
||||
#expect(chaoticInterpolate(.none, phase: 0.99, hM1: hM1, h0: h0, h1: h1, h2: h2) == h0)
|
||||
}
|
||||
|
||||
@Test func linearEndpointsAndMidpoint() {
|
||||
#expect(abs(chaoticInterpolate(.linear, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h0) < 1e-15)
|
||||
#expect(abs(chaoticInterpolate(.linear, phase: 1.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h1) < 1e-15)
|
||||
let mid: Double = chaoticInterpolate(.linear, phase: 0.5, hM1: hM1, h0: h0, h1: h1, h2: h2)
|
||||
#expect(abs(mid - 0.5 * (h0 + h1)) < 1e-15)
|
||||
}
|
||||
|
||||
@Test func cubicPassesThroughSegmentEndpoints() {
|
||||
// The 4-point cubic kernel passes through h0 at t=0 and h1 at t=1.
|
||||
#expect(abs(chaoticInterpolate(.cubic, phase: 0.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h0) < 1e-12)
|
||||
#expect(abs(chaoticInterpolate(.cubic, phase: 1.0, hM1: hM1, h0: h0, h1: h1, h2: h2) - h1) < 1e-12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// CuspSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - CuspSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("CuspStepped.Audio")
|
||||
struct CuspSteppedAudioTests {
|
||||
|
||||
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: CuspStepped.Audio = CuspStepped.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.9)) < 1e-9)
|
||||
#expect(abs(s[0][1] - (-0.8024982662959761)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let m: CuspStepped.Audio = CuspStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - (-0.9)) < 1e-9 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let m: CuspStepped.Audio = CuspStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 1.5 }) // x in ~[-0.9,1.0]
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let m: CuspStepped.Audio = CuspStepped.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: CuspStepped.Audio = CuspStepped.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: CuspStepped.Audio = CuspStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: CuspStepped.Audio = CuspStepped.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: CuspStepped.Audio = CuspStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: CuspStepped.Audio = CuspStepped.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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// CuspSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - CuspSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("CuspStepped.Control")
|
||||
struct CuspSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let m: CuspStepped.Control = CuspStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (-0.9)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let m: CuspStepped.Control = CuspStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 1.5 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: CuspStepped.Control = CuspStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: CuspStepped.Control = CuspStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: CuspStepped.Control = CuspStepped.Control(freq: 500.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)))
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// FBSineSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - FBSineSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("FBSineStepped.Control")
|
||||
struct FBSineSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let m: FBSineStepped.Control = FBSineStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (0.5818307174710479)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let m: FBSineStepped.Control = FBSineStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) <= 1.0 + 1e-12 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: FBSineStepped.Control = FBSineStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: FBSineStepped.Control = FBSineStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: FBSineStepped.Control = FBSineStepped.Control(freq: 500.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)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// GbmanSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - GbmanSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("GbmanStepped.Audio")
|
||||
struct GbmanSteppedAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func deterministicSteppedIterations() {
|
||||
// freq == sampleRate, .none. xi=1.2, yi=2.1: iterates 0.1, -0.1, 1.0, 2.1, …
|
||||
// → held outputs -0.1, 1.0, 2.1, …
|
||||
let gb: GbmanStepped.Audio = GbmanStepped.Audio(freq: sr, interpolation: .none)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][0] - (-0.1)) < 1e-9)
|
||||
#expect(abs(s[0][1] - 1.0) < 1e-9)
|
||||
#expect(abs(s[0][2] - 2.1) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let gb: GbmanStepped.Audio = GbmanStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(gb, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - (-0.1)) < 1e-9 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let gb: GbmanStepped.Audio = GbmanStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(gb, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 10.0 })
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let gb: GbmanStepped.Audio = GbmanStepped.Audio(freq: 4000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(gb, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: GbmanStepped.Audio = GbmanStepped.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: GbmanStepped.Audio = GbmanStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let gb: GbmanStepped.Audio = GbmanStepped.Audio(freq: 8000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: GbmanStepped.Audio = GbmanStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: GbmanStepped.Audio = GbmanStepped.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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// GbmanSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - GbmanSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("GbmanStepped.Control")
|
||||
struct GbmanSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let gb: GbmanStepped.Control = GbmanStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (-0.1)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let gb: GbmanStepped.Control = GbmanStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(gb, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 10.0 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: GbmanStepped.Control = GbmanStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: GbmanStepped.Control = GbmanStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let gb: GbmanStepped.Control = GbmanStepped.Control(freq: 500.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = gb.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// HenonSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - HenonSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("HenonStepped.Audio")
|
||||
struct HenonSteppedAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func deterministicSteppedIterations() {
|
||||
// freq == sampleRate → dphase = 1, one iteration per sample, .none holds the
|
||||
// segment start. With a=1.4, b=0.3, x0=x1=0 the warm-up iterations are
|
||||
// 1, -0.4, 1.076, -0.7408864; after 4-iteration priming the held outputs are
|
||||
// -0.4, 1.076, -0.7408864, ...
|
||||
let henon: HenonStepped.Audio = HenonStepped.Audio(freq: sr, a: 1.4, b: 0.3,
|
||||
x0: 0.0, x1: 0.0, interpolation: .none)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][0] - (-0.4)) < 1e-9)
|
||||
#expect(abs(s[0][1] - 1.076) < 1e-9)
|
||||
#expect(abs(s[0][2] - (-0.7408864)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let henon: HenonStepped.Audio = HenonStepped.Audio(freq: sr) // canonical a/b
|
||||
let samples: [Double] = collectBlocks(henon, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
// Not a constant — the orbit visits distinct values.
|
||||
#expect(Set(samples.map { ($0 * 1e6).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let henon: HenonStepped.Audio = HenonStepped.Audio(freq: 4000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(henon, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsConstant() {
|
||||
// dphase = 0 → never iterates past priming → constant held output.
|
||||
let henon: HenonStepped.Audio = HenonStepped.Audio(freq: 0.0, interpolation: .linear)
|
||||
let samples: [Double] = collectBlocks(henon, engine: engine, blocks: 4)
|
||||
let first: Double = samples.first ?? .nan
|
||||
#expect(samples.allSatisfy { $0 == first })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let h1: HenonStepped.Audio = HenonStepped.Audio(freq: 8000.0)
|
||||
let s1: [Double] = collectBlocks(h1, engine: engine, blocks: 10)
|
||||
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let h2: HenonStepped.Audio = HenonStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(h2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let henon: HenonStepped.Audio = HenonStepped.Audio(freq: 8000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: HenonStepped.Audio = HenonStepped.Audio(freq: sr, interpolation: .none)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
|
||||
let scaled: HenonStepped.Audio = HenonStepped.Audio(freq: sr, interpolation: .none,
|
||||
mul: 2.0, 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 * 2.0 + 1.0)) < 1e-12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// HenonSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - HenonSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("HenonStepped.Control")
|
||||
struct HenonSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let henon: HenonStepped.Control = HenonStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(henon, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
// dphase = 0 → no iteration past priming; .none holds h0 = -0.4 (2nd Hénon
|
||||
// iterate for a=1.4, b=0.3, x0=x1=0). The block ramps 0 → -0.4, so the last
|
||||
// sample equals the target exactly.
|
||||
let henon: HenonStepped.Control = HenonStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (-0.4)) < 1e-12)
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let h1: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(h1, engine: engine, blocks: 20)
|
||||
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let h2: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(h2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let henon: HenonStepped.Control = HenonStepped.Control(freq: 500.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = henon.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// LatoocarfianSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LatoocarfianSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LatoocarfianStepped.Audio")
|
||||
struct LatoocarfianSteppedAudioTests {
|
||||
|
||||
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: LatoocarfianStepped.Audio = LatoocarfianStepped.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.34527127964613574)) < 1e-9)
|
||||
#expect(abs(s[0][1] - (-0.31328745455281626)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let m: LatoocarfianStepped.Audio = LatoocarfianStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - (0.34527127964613574)) < 1e-9 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let m: LatoocarfianStepped.Audio = LatoocarfianStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 }) // x in ~[-1.5,1.5]
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let m: LatoocarfianStepped.Audio = LatoocarfianStepped.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: LatoocarfianStepped.Audio = LatoocarfianStepped.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: LatoocarfianStepped.Audio = LatoocarfianStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: LatoocarfianStepped.Audio = LatoocarfianStepped.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: LatoocarfianStepped.Audio = LatoocarfianStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: LatoocarfianStepped.Audio = LatoocarfianStepped.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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// LatoocarfianSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LatoocarfianSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LatoocarfianStepped.Control")
|
||||
struct LatoocarfianSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let m: LatoocarfianStepped.Control = LatoocarfianStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (0.34527127964613574)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let m: LatoocarfianStepped.Control = LatoocarfianStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: LatoocarfianStepped.Control = LatoocarfianStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: LatoocarfianStepped.Control = LatoocarfianStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: LatoocarfianStepped.Control = LatoocarfianStepped.Control(freq: 500.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)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// LinCongSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LinCongSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LinCongStepped.Audio")
|
||||
struct LinCongSteppedAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func deterministicSteppedIterations() {
|
||||
// freq == sampleRate, .none. a=1.1, c=0.13, m=1, xi=0: iterates
|
||||
// 0.13, 0.273, 0.4303, … → held outputs 0.273, 0.4303, …
|
||||
let lc: LinCongStepped.Audio = LinCongStepped.Audio(freq: sr, interpolation: .none)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][0] - 0.273) < 1e-9)
|
||||
#expect(abs(s[0][1] - 0.4303) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let lc: LinCongStepped.Audio = LinCongStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(lc, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - 0.273) < 1e-12 })
|
||||
}
|
||||
|
||||
@Test func staysInZeroToModulusRange() {
|
||||
let lc: LinCongStepped.Audio = LinCongStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(lc, engine: engine, blocks: 60)
|
||||
#expect(samples.allSatisfy { $0 >= 0.0 && $0 < 1.0 })
|
||||
#expect(Set(samples.map { ($0 * 1e6).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let lc: LinCongStepped.Audio = LinCongStepped.Audio(freq: 4000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(lc, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: LinCongStepped.Audio = LinCongStepped.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: LinCongStepped.Audio = LinCongStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let lc: LinCongStepped.Audio = LinCongStepped.Audio(freq: 8000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: LinCongStepped.Audio = LinCongStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: LinCongStepped.Audio = LinCongStepped.Audio(freq: 0.0, mul: 2.0, 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 * 2.0 - 1.0)) < 1e-12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// LinCongSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LinCongSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LinCongStepped.Control")
|
||||
struct LinCongSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - 0.273) < 1e-12)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(lc, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { $0 >= 0.0 && $0 < 1.0 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let lc: LinCongStepped.Control = LinCongStepped.Control(freq: 500.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = lc.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// LorenzLinearAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LorenzLinearAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LorenzLinear.Audio")
|
||||
struct LorenzLinearAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIterationValue() {
|
||||
// dphase = 0 → output stays at the primed segment start h0 (= the 2nd Euler
|
||||
// iteration). With s=10, r=28, b=2.667, h=0.02, xi=0.1: iterations are
|
||||
// x1 = 0.08, x2 = 0.0752, so h0 = 0.0752.
|
||||
let lorenz: LorenzLinear.Audio = LorenzLinear.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(lorenz, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - 0.0752) < 1e-12 })
|
||||
}
|
||||
|
||||
@Test func orbitFiniteAndEvolves() {
|
||||
let lorenz: LorenzLinear.Audio = LorenzLinear.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(lorenz, engine: engine, blocks: 200)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
// Canonical Lorenz x stays bounded to roughly ±25.
|
||||
#expect(samples.allSatisfy { abs($0) < 30.0 })
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 50)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let lorenz: LorenzLinear.Audio = LorenzLinear.Audio(freq: 6000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(lorenz, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let l1: LorenzLinear.Audio = LorenzLinear.Audio(freq: 9000.0)
|
||||
let s1: [Double] = collectBlocks(l1, engine: engine, blocks: 30)
|
||||
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let l2: LorenzLinear.Audio = LorenzLinear.Audio(freq: 9000.0)
|
||||
let s2: [Double] = collectBlocks(l2, engine: engine2, blocks: 30)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let lorenz: LorenzLinear.Audio = LorenzLinear.Audio(freq: 9000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = lorenz.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = lorenz.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: LorenzLinear.Audio = LorenzLinear.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
|
||||
let scaled: LorenzLinear.Audio = LorenzLinear.Audio(freq: 0.0, mul: 0.05, add: 0.5)
|
||||
let g2: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: Double = scaled.calculatedSamples(graph: g2, count: engine.blockSize)[0][0]
|
||||
#expect(abs(s - (p * 0.05 + 0.5)) < 1e-12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// LorenzLinearControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - LorenzLinearControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("LorenzLinear.Control")
|
||||
struct LorenzLinearControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let lorenz: LorenzLinear.Control = LorenzLinear.Control(freq: 200.0, mul: 0.05)
|
||||
let samples: [Double] = collectBlocks(lorenz, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
// dphase = 0 → no iteration past priming. The block ramps from the initial
|
||||
// _rampTarget (0) to h0 = 0.0752 (2nd Euler iterate, h=0.02), so the block's
|
||||
// last sample equals the target exactly.
|
||||
let lorenz: LorenzLinear.Control = LorenzLinear.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = lorenz.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - 0.0752) < 1e-12)
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let l1: LorenzLinear.Control = LorenzLinear.Control(freq: 600.0)
|
||||
let s1: [Double] = collectBlocks(l1, engine: engine, blocks: 20)
|
||||
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let l2: LorenzLinear.Control = LorenzLinear.Control(freq: 600.0)
|
||||
let s2: [Double] = collectBlocks(l2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let lorenz: LorenzLinear.Control = LorenzLinear.Control(freq: 600.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = lorenz.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = lorenz.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// QuadSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - QuadSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("QuadStepped.Audio")
|
||||
struct QuadSteppedAudioTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func deterministicSteppedIterations() {
|
||||
// freq == sampleRate → one iteration per sample, .none holds the segment start.
|
||||
// a=1, b=-1, c=-0.75, xi=0: warm-up iterates -0.75, 0.5625, -0.99609375, …;
|
||||
// after 4-iteration priming the held outputs are 0.5625, -0.99609375, …
|
||||
let q: QuadStepped.Audio = QuadStepped.Audio(freq: sr, interpolation: .none)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][0] - 0.5625) < 1e-9)
|
||||
#expect(abs(s[0][1] - (-0.99609375)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let q: QuadStepped.Audio = QuadStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(q, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - 0.5625) < 1e-12 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let q: QuadStepped.Audio = QuadStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(q, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
#expect(Set(samples.map { ($0 * 1e6).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let q: QuadStepped.Audio = QuadStepped.Audio(freq: 4000.0, interpolation: mode)
|
||||
let samples: [Double] = collectBlocks(q, engine: engine, blocks: 20)
|
||||
#expect(samples.allSatisfy { $0.isFinite }, "mode \(mode) non-finite")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let q1: QuadStepped.Audio = QuadStepped.Audio(freq: 8000.0)
|
||||
let s1: [Double] = collectBlocks(q1, engine: engine, blocks: 10)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let q2: QuadStepped.Audio = QuadStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(q2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let q: QuadStepped.Audio = QuadStepped.Audio(freq: 8000.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
|
||||
@Test func mulAddScalesAndOffsets() {
|
||||
let plain: QuadStepped.Audio = QuadStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: QuadStepped.Audio = QuadStepped.Audio(freq: 0.0, mul: 2.0, 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 * 2.0 + 1.0)) < 1e-12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// QuadSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - QuadSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("QuadStepped.Control")
|
||||
struct QuadSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let q: QuadStepped.Control = QuadStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - 0.5625) < 1e-12)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let q: QuadStepped.Control = QuadStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(q, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { abs($0) < 2.0 })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let q1: QuadStepped.Control = QuadStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(q1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let q2: QuadStepped.Control = QuadStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(q2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let q: QuadStepped.Control = QuadStepped.Control(freq: 500.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let r1: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
let r2: [[Double]] = q.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(r1[0].prefix(engine.blockSize).elementsEqual(r2[0].prefix(engine.blockSize)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// StandardSteppedAudioTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - StandardSteppedAudioTests
|
||||
|
||||
@MainActor
|
||||
@Suite("StandardStepped.Audio")
|
||||
struct StandardSteppedAudioTests {
|
||||
|
||||
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: StandardStepped.Audio = StandardStepped.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] - (2.2890283227337602)) < 1e-9)
|
||||
#expect(abs(s[0][1] - (4.351601455163474)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func freqZeroHoldsSecondIteration() {
|
||||
let m: StandardStepped.Audio = StandardStepped.Audio(freq: 0.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 4)
|
||||
#expect(samples.allSatisfy { abs($0 - (2.2890283227337602)) < 1e-9 })
|
||||
}
|
||||
|
||||
@Test func chaoticOrbitStaysBounded() {
|
||||
let m: StandardStepped.Audio = StandardStepped.Audio(freq: sr)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 50)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { $0 >= 0.0 && $0 < lyrebirdTwoPi }) // x in [0, 2pi)
|
||||
#expect(Set(samples.map { ($0 * 1e4).rounded() }).count > 10)
|
||||
}
|
||||
|
||||
@Test func allInterpolationModesFinite() {
|
||||
for mode: TableInterpolation in [.none, .linear, .cubic] {
|
||||
let m: StandardStepped.Audio = StandardStepped.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: StandardStepped.Audio = StandardStepped.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: StandardStepped.Audio = StandardStepped.Audio(freq: 8000.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 10)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: StandardStepped.Audio = StandardStepped.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: StandardStepped.Audio = StandardStepped.Audio(freq: 0.0)
|
||||
let g1: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let p: Double = plain.calculatedSamples(graph: g1, count: engine.blockSize)[0][0]
|
||||
let scaled: StandardStepped.Audio = StandardStepped.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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// StandardSteppedControlTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - StandardSteppedControlTests
|
||||
|
||||
@MainActor
|
||||
@Suite("StandardStepped.Control")
|
||||
struct StandardSteppedControlTests {
|
||||
|
||||
let engine: SynthesisEngine
|
||||
let sr: Double = 44100
|
||||
|
||||
init() throws {
|
||||
engine = makeTestEngine(blockSize: 64, sampleRate: 44100)
|
||||
try engine.start()
|
||||
}
|
||||
|
||||
@Test func freqZeroRampsToPrimedValue() {
|
||||
let m: StandardStepped.Control = StandardStepped.Control(freq: 0.0)
|
||||
let g: SynthGraph = makeSynthGraph(engine: engine)
|
||||
let s: [[Double]] = m.calculatedSamples(graph: g, count: engine.blockSize)
|
||||
#expect(abs(s[0][engine.blockSize - 1] - (2.2890283227337602)) < 1e-9)
|
||||
}
|
||||
|
||||
@Test func finiteBoundedOutput() {
|
||||
let m: StandardStepped.Control = StandardStepped.Control(freq: 200.0)
|
||||
let samples: [Double] = collectBlocks(m, engine: engine, blocks: 40)
|
||||
#expect(samples.allSatisfy { $0.isFinite })
|
||||
#expect(samples.allSatisfy { $0 >= 0.0 && $0 < lyrebirdTwoPi })
|
||||
}
|
||||
|
||||
@Test func twoInstancesProduceIdenticalOutput() throws {
|
||||
let a1: StandardStepped.Control = StandardStepped.Control(freq: 500.0)
|
||||
let s1: [Double] = collectBlocks(a1, engine: engine, blocks: 20)
|
||||
let engine2: SynthesisEngine = makeTestEngine(blockSize: 64, sampleRate: sr)
|
||||
try engine2.start()
|
||||
let a2: StandardStepped.Control = StandardStepped.Control(freq: 500.0)
|
||||
let s2: [Double] = collectBlocks(a2, engine: engine2, blocks: 20)
|
||||
#expect(s1 == s2)
|
||||
}
|
||||
|
||||
@Test func participatesInFanOutCache() {
|
||||
let m: StandardStepped.Control = StandardStepped.Control(freq: 500.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)))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user