5

I'm developing an audio app with AudioKit which involves periodically stopping AudioKit, rearranging or replacing the chain of AKNode subclasses, then restarting AudioKit. This has been working smoothly until I tried it with AKMicrophone.

If AKMicrophone is present in the initial sound chain, i.e., when I make the first call to AudioKit.start(), it works fine. But if I put AKMicrophone into the sound chain at some point after an earlier call AudioKit.start(), the app will crash at the next AudioKit.start() call, producing 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 to AudioKit.start() it will crash:

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

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

Is there any way to avoid this? Even help understanding the error message would be helpful. Thanks.

Edit: I've noticed the same behaviour AKStereoInput - same error message under the same conditions

c_booth
  • 2,185
  • 1
  • 13
  • 22

1 Answers1

0

After

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

Try;

do{
   try AudioKit.stop()
   try AudioKit.shutdown()
   AudioKit.output = nil
}catch{
   print(error)
}
Trevor
  • 1,051
  • 12
  • 16