Thursday, May 16, 2024
HomeiOS Developmentios - Find out how to play from engine.inputNode slightly than from...

ios – Find out how to play from engine.inputNode slightly than from a file in an Audio Unit Extension App


I am working with the default AudioUnitExtension venture created by XCode 15.3 by going File > New > Challenge > Audio Unit Extension App (and choosing “Impact” because the Audio Unit Kind).

Presently, the demo venture performs audio from a “Synth” audio file when a “Play” button is pressed. I might wish to as a substitute have the audio be performed with low latency from my microphone in order that I can carry out stay audio processing on the enter. Nevertheless, I can not seem to detach and reconnect the AudioEngine’s nodes in a method that does not lead to an error.

Within the default venture, my present (non-working) resolution is to simply alter the join() technique of Frequent/Audio/SimplePlayEngine.

I alter the traces

if avAudioUnit.wantsAudioInput {
    // Disconnect the participant -> mixer.
    engine.disconnectNodeInput(engine.mainMixerNode)
            
    // Join the participant -> impact -> mixer.
    if let format = file?.processingFormat {
        engine.join(participant, to: avAudioUnit, format: format)
        engine.join(avAudioUnit, to: engine.mainMixerNode, format: format)
    }
}

to

if avAudioUnit.wantsAudioInput {
    // Disconnect the participant -> mixer.
    engine.disconnectNodeInput(engine.mainMixerNode)
            
    // Join the participant -> impact -> mixer.
    if let format = file?.processingFormat {
        engine.detach(participant)
        engine.join(engine.inputNode, to: avAudioUnit, format: nil)
        engine.join(avAudioUnit, to: engine.mainMixerNode, format: nil)
    }
}

Earlier than the change, the venture is precisely the default venture created robotically by XCode. It really works as meant. After this modification, the venture builds and begins. When the “Play” button is pressed, the error “Thread 1: “required situation is fake: _engine != nil”” is thrown at line 160 of the venture stateChangeQueue.sync in SimplePlayEngine.startPlaying().

That is the furthest I’ve gotten after a number of totally different options, and I am unsure what precisely goes incorrect right here.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments