Reputation: 1237
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...
Upvotes: 0
Views: 320
Reputation: 744
It certainly is possible to combine AVAudioEngine with the Chirp iOS SDK.
The issue raised arises because the Chirp SDK is operating on the same shared AVAudioSession instance as your audio player, when you set the category you are overriding the settings set by the Chirp SDK.
I would suggest that you remove the line where you call setCategory
and this will work - the settings set by the Chirp SDK will be sufficient, correct me if I am wrong here.
Others have reported seeing the 'Unknown selected data source' warnings in the logs, I believe this is an issue with iOS 12. See https://forums.developer.apple.com/thread/108785
Upvotes: 3