Files
Lyrebird/Tests/LyrebirdTests/Generators/Chaotic/StandardSteppedControlTests.swift
T
2026-06-21 11:45:58 -07:00

57 lines
2.1 KiB
Swift

// 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)))
}
}