fixes for Swift 6 and threading concerns

This commit is contained in:
2026-06-02 12:09:44 -07:00
parent 2fa4bfd45e
commit 6d3a0930a1
327 changed files with 1596 additions and 199 deletions
@@ -7,6 +7,7 @@
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@MainActor
@Suite("AUInput.Audio") struct AUInputAudioTests {
@Test func channelMustBeNonNegative() {
@@ -88,9 +88,11 @@ private struct ABLFixture {
}
}
@MainActor
@Suite("AUv3Driver") struct AUv3DriverTests {
@Test func returnsUninitializedBeforeSetup() {
defer { lyrebirdClearRTMarkAfterTestRender() }
let driver: AUv3Driver = AUv3Driver()
let fixture: ABLFixture = ABLFixture(channels: 2, frames: 64)
defer { fixture.deallocate() }
@@ -99,6 +101,7 @@ private struct ABLFixture {
}
@Test func rejectsFrameCountAboveMax() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 256)
let engine: SynthesisEngine = SynthesisEngine(
blockSize: 128, sampleRate: 44100,
@@ -114,6 +117,7 @@ private struct ABLFixture {
}
@Test func smallHostFrameCountDrivesMultipleEngineBlocks() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
// Engine block 128; host requests 64 per call — two calls per engine block.
let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 64)
let engine: SynthesisEngine = SynthesisEngine(
@@ -156,6 +160,7 @@ private struct ABLFixture {
}
@Test func largeHostFrameCountPullsMultipleEngineBlocks() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
// Host wants 1024 per call but engine block is 256 — 4 engine blocks per
// render call.
let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 1024)
@@ -182,6 +187,7 @@ private struct ABLFixture {
}
@Test func alternatingFrameCountsPreserveContinuity() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
// Hosts may switch frame counts mid-stream; the ring must keep sample
// continuity intact.
let driver: AUv3Driver = AUv3Driver(maxFramesToRender: 1024)
@@ -7,6 +7,7 @@
import Testing
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@MainActor
@Suite("AUv3RingBuffer") struct AUv3RingBufferTests {
@Test func capacityRoundsUpToPowerOfTwo() {
@@ -32,6 +32,7 @@ private final class InheritedParamSynth: ParamSynth {
// MARK: - Tests
@MainActor
@Suite("LyrebirdAUParameterMapping discovery") struct LyrebirdAUParameterDiscoveryTests {
@Test func discoversAllLiveParamsInDeclarationOrder() {
@@ -70,6 +71,7 @@ private final class InheritedParamSynth: ParamSynth {
}
}
@MainActor
@Suite("LyrebirdAUParameterMapping tree") struct LyrebirdAUParameterTreeTests {
@Test func buildsOneAUParameterPerSlot() {
@@ -43,6 +43,7 @@ private final class FixturePresetGen: GeneratorBase, AudioGenerator, LyrebirdAUP
func floatValue(graph: SynthGraph) -> Double { _amp }
}
@MainActor
@Suite("LyrebirdAUPresetSourceRegistry") struct LyrebirdAUPresetRegistryTests {
@Test func registerAndMakeRoundTrip() {
@@ -15,6 +15,7 @@ private final class TestVoice: SynthesizerBase {
override func build() { output(bus: 0, source: $freq * $amp * $gate) }
}
@MainActor
@Suite("LyrebirdAUVoicePoolBinding") struct LyrebirdAUVoicePoolBindingTests {
@Test func noteOnAllocatesVoiceAndConfigures() throws {
@@ -21,7 +21,7 @@ private final class PassthroughSynth: SynthesizerBase {
private final class PassthroughEffectAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase {
PassthroughSynth()
MainActor.assumeIsolated { PassthroughSynth() }
}
public override class var lyrebirdInputChannels: Int { 2 }
public override class var lyrebirdOutputChannels: Int { 2 }
@@ -37,6 +37,7 @@ private func makeEffectDescription() -> AudioComponentDescription {
)
}
@MainActor
@Suite("LyrebirdAudioUnit effect") struct LyrebirdAudioUnitEffectTests {
@Test func effectAUDeclaresInputAndOutputBuses() throws {
@@ -62,7 +63,7 @@ private func makeEffectDescription() -> AudioComponentDescription {
override func build() { output(bus: 0, source: 0.0) }
}
final class StubInstrumentAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase { StubSynth() }
public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { StubSynth() } }
}
let desc: AudioComponentDescription = AudioComponentDescription(
componentType: kAudioUnitType_MusicDevice,
@@ -10,6 +10,7 @@ import AudioToolbox
import AVFoundation
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
@MainActor
@Suite("LyrebirdAudioUnit MIDI dispatch") struct LyrebirdAudioUnitMIDITests {
@Test func dispatchHandlesNilHeadGracefully() {
@@ -26,7 +26,7 @@ private final class StemRenderSynth: SynthesizerBase {
}
private final class StemRenderAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase { StemRenderSynth() }
public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { StemRenderSynth() } }
public override class var lyrebirdOutputBusses: [LyrebirdAUBusSpec] {
[
.init(name: "Main", channelCount: 2),
@@ -48,7 +48,7 @@ private final class SidechainPassthrough: SynthesizerBase {
}
private final class SidechainAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase { SidechainPassthrough() }
public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { SidechainPassthrough() } }
public override class var lyrebirdOutputBusses: [LyrebirdAUBusSpec] {
[.init(name: "Output", channelCount: 2)]
}
@@ -67,7 +67,7 @@ private final class SingleBusSynth: SynthesizerBase {
}
private final class SingleBusAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase { SingleBusSynth() }
public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { SingleBusSynth() } }
// No bus-spec overrides — must keep the default single-bus behaviour.
}
@@ -81,6 +81,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
)
}
@MainActor
@Suite("LyrebirdAudioUnit multi-bus — defaults") struct LyrebirdAudioUnitMultiBusDefaultTests {
@Test func singleBusAUKeeps104aShape() throws {
@@ -97,6 +98,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
}
}
@MainActor
@Suite("LyrebirdAudioUnit multi-bus — multi-output") struct LyrebirdAudioUnitMultiOutputBusTests {
@Test func twoOutputBussesAreExposed() throws {
@@ -120,6 +122,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
}
@Test func asymmetricBusPullsDoNotCrash() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
// AU spec lets a host pull bus 0 repeatedly without pulling bus 1.
// Without the driver's saturation guard this would overflow bus 1's
// ring buffer after `capacity / blockSize` engine advances.
@@ -157,6 +160,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
}
@Test func renderingRoutesEachBusIndependently() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
let au: StemRenderAU = try StemRenderAU(componentDescription: makeAUDesc(subtype: 0x534D4F44))
try au.allocateRenderResources()
defer { au.deallocateRenderResources() }
@@ -199,6 +203,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
}
}
@MainActor
@Suite("LyrebirdAudioUnit multi-bus — sidechain input") struct LyrebirdAudioUnitSidechainTests {
@Test func twoInputBussesAreExposed() throws {
@@ -219,6 +224,7 @@ private func makeAUDesc(subtype: UInt32) -> AudioComponentDescription {
}
@Test func renderLoopDispatchesPerInputBusPullBlock() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
// Drive the full internalRenderBlock → driver → _fillInputStagingFromHost
// path with a synthetic pullInputBlock that fills bus 0 ABL with +1.0
// and bus 1 ABL with -1.0. Verify the AU passes bus 0 samples through
@@ -17,7 +17,7 @@ private final class PresetSynth: SynthesizerBase {
}
private final class PresetAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase { PresetSynth() }
public override class func makeSynthesizer() -> SynthesizerBase { MainActor.assumeIsolated { PresetSynth() } }
public override class func factoryPresetsForLyrebird() -> [LyrebirdAUFactoryPreset] {
[
.init(name: "Bright", scalarValues: ["freq": 880, "amp": 0.8]),
@@ -36,6 +36,7 @@ private func makeDesc() -> AudioComponentDescription {
)
}
@MainActor
@Suite("LyrebirdAudioUnit factory presets") struct LyrebirdAudioUnitFactoryPresetsTests {
@Test func factoryPresetsExposeAllNames() throws {
@@ -22,7 +22,7 @@ private final class TestFMSynth: SynthesizerBase {
private final class TestFMSynthAudioUnit: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase {
TestFMSynth()
MainActor.assumeIsolated { TestFMSynth() }
}
public override class func parameterMetadata() -> [String: LyrebirdAUParameterInfo] {
[
@@ -44,6 +44,7 @@ private func makeDescription() -> AudioComponentDescription {
// MARK: - Init / parameter tree
@MainActor
@Suite("LyrebirdAudioUnit init") struct LyrebirdAudioUnitInitTests {
@Test func initSucceedsAndPopulatesParameterTree() throws {
@@ -94,6 +95,7 @@ private func makeDescription() -> AudioComponentDescription {
// MARK: - Resource lifecycle
@MainActor
@Suite("LyrebirdAudioUnit render resources") struct LyrebirdAudioUnitRenderResourceTests {
@Test func allocateAndDeallocateLifecycle() throws {
@@ -127,6 +129,7 @@ private func makeDescription() -> AudioComponentDescription {
}
@Test func renderProducesNonzeroOutputAfterAllocate() throws {
defer { lyrebirdClearRTMarkAfterTestRender() }
let au: TestFMSynthAudioUnit = try TestFMSynthAudioUnit(componentDescription: makeDescription())
try au.allocateRenderResources()
defer { au.deallocateRenderResources() }
@@ -175,6 +178,7 @@ private func makeDescription() -> AudioComponentDescription {
// MARK: - fullState save / restore
@MainActor
@Suite("LyrebirdAudioUnit fullState") struct LyrebirdAudioUnitFullStateTests {
@Test func fullStateRoundTripPreservesScalarLiveParams() throws {