I need to make an ability to change input device for record on the fly while program is running (between recording sessions, not in recording process). Here is the code that, i suppose, have to do that. But when im trying to change input device, AKNodeRecorder records nothing (duration always 0) and after trying to call exportAsynchronously on recorder.audioFile i always get an following error:
[central] 54: ERROR: >avae> AVAudioFile.mm:37: AVAudioFileImpl: error 2003334207
Tried to change almost all, but nothing has an effect. Here is the code that changes input device.
func setupRecordingChain(_ deviceIndex: Int = 0)
{
AudioKit.stop()
setupInputDevice(for: deviceIndex)
self.micMixer = AKMixer(self.mic)
self.micBooster = AKBooster(self.micMixer)
self.micBooster.gain = 0
do {
self.recorder = try AKNodeRecorder(node: self.micMixer)
}
catch {
//catch error
}
self.mainMixer = AKMixer(self.micBooster)
AudioKit.output = self.mainMixer
AudioKit.start()
}
private func setupInputDevice(for deviceIndex: Int)
{
guard let inputDevices = AudioKit.inputDevices else { return }
let inputDevice = inputDevices[deviceIndex]
do {
try self.mic.setDevice(inputDevice)
} catch {
//catch error
}
}