I'm developing an app that generates sounds with AVFoundation framework. Now I'd like to add Chirp.io SDK to encode some information into sounds as an addition to my code.
If I use my sound code or Chirp sdk alone everything is working fine. When I do sound with my code and then run Chirp it works only once and then fails with errors on second attempt:
2018-10-23 19:32:55.188460+0300 FieldApp[2243:1408580] [avae] AVAEInternal.h:70:_AVAE_Check: required condition is false: [AVAudioPlayerNode.mm:536:StartImpl: (_engine->IsRunning())]
2018-10-23 19:32:55.191931+0300 FieldApp[2243:1408580] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'
Is it possible to combine usage of AVAudioEngine and Chirp.io SDK?
Here is a sample from my code:
// ... init part of my sound code ....
let engine: AVAudioEngine = AVAudioEngine()
let playerNode: AVAudioPlayerNode = AVAudioPlayerNode()
let audioFormat = AVAudioFormat(standardFormatWithSampleRate: 44100.0, channels: 2)
engine.attach(playerNode)
engine.connect(playerNode, to: engine.mainMixerNode, format: audioFormat)
// ... Chirp init code ...
let connect: ChirpConnect! = ChirpConnect(appKey: "xXx", andSecret: "xXx")
connect.setConfig("xXxxx")
connect.start()
// ... do this in a loop ....
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try AVAudioSession.sharedInstance().setActive(true)
try engine.start()
started = true
}
catch {
LogManager.shared.post("Error starting sound engine: \(error.localizedDescription)")
}
playerNode.play()
//.... wait until playing ends ....
playerNode.stop()
engine.stop()
//.... Chirp SDK sounds ....
let buf: Data = ..... some data to send
connect.send(buf)
//... end of pseudo-loop
So when I run the code in the loop second time I get the exception but I don't get an exception in engine.start(), it executes normally...