Failed to add AKMicrophone

I am developing an audio application with AudioKit that includes intermittently stopping AudioKit, reordering or replacing a chain of subclasses AKNode, and then restarting AudioKit. This works smoothly until I tried it using AKMicrophone.

If AKMicrophonepresent in the initial chain of sound, that is, when I make the first call AudioKit.start(), it works fine. But if I put AKMicrophonein a chain of sounds at some point after an earlier call AudioKit.start(), the application will crash on the next call AudioKit.start(), causing the following error message:

...[avae] AVAudioEngine.mm:149:-[AVAudioEngine prepare]: Engine@0x1c0007170: could not initialize, error = -10875
...[mcmx] 338: input bus 0 sample rate is 0
...[avae] AVAEInternal.h:103:_AVAE_CheckNoErr: [AVAudioEngineGraph.mm:1266:Initialize: 
(err = AUGraphParser::InitializeActiveNodesInOutputChain(ThisGraph, kOutputChainOptimizedTraversal, *GetOutputNode(), isOutputChainActive)): error -10875

To illustrate, the following code runs smoothly:

    let mic = AKMicrophone()
    if let input = AudioKit.inputDevice {
        try! mic.setDevice(input)
    }
    AudioKit.output = mic
    AudioKit.start()

But if it is preceded by a call AudioKit.start(), it will work:

    AudioKit.output = AKOscillator()
    AudioKit.start()
    AudioKit.stop()

    let mic = AKMicrophone()
    if let input = AudioKit.inputDevice {
        try! mic.setDevice(input)
    }
    AudioKit.output = mic
    AudioKit.start()

? . .

: AKStereoInput -

+5
1

AudioKit.output = AKOscillator()
AudioKit.start()

;

do{
   try AudioKit.stop()
   try AudioKit.shutdown()
   AudioKit.output = nil
}catch{
   print(error)
}
0

Source: https://habr.com/ru/post/1693054/


All Articles