I’m working with the default AudioUnitExtension project created by XCode 15.3 by going File > New > Project > Audio Unit Extension App.
Currently, the demo project plays audio from a “Synth” audio file when a “Play” button is pressed. I’d like to instead have the audio be played with low latency from my microphone so that I can perform live audio processing on the input. However, I can’t seem to detach and reconnect the AudioEngine’s nodes in a way that doesn’t result in an error.
In the default project, my current (non-working) solution is to just alter the connect() method of Common/Audio/SimplePlayEngine.
I change the lines
if avAudioUnit.wantsAudioInput {
// Disconnect the player -> mixer.
engine.disconnectNodeInput(engine.mainMixerNode)
// Connect the player -> effect -> mixer.
if let format = file?.processingFormat {
engine.connect(player, to: avAudioUnit, format: format)
engine.connect(avAudioUnit, to: engine.mainMixerNode, format: format)
}
}
to
if avAudioUnit.wantsAudioInput {
// Disconnect the player -> mixer.
engine.disconnectNodeInput(engine.mainMixerNode)
// Connect the player -> effect -> mixer.
if let format = file?.processingFormat {
engine.detach(player)
engine.connect(engine.inputNode, to: avAudioUnit, format: nil)
engine.connect(avAudioUnit, to: engine.mainMixerNode, format: nil)
}
}
Before the change, the project is exactly the default project created automatically by XCode. It works as intended. After this change, the project builds and starts. When the “Play” button is pressed, the error “Thread 1: “required condition is false: _engine != nil”” is thrown at line 160 of the project stateChangeQueue.sync
in SimplePlayEngine.startPlaying().
This is the furthest I’ve gotten after several different solutions, and I’m not sure what exactly is going wrong here.