1

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 
    }
}
drywet
  • 75
  • 7
  • I'm not too surprised because input devices are difficult to deal with. Just FYI there was a similar error reported here. https://stackoverflow.com/questions/29088594/osstatus-error-2003334207-when-using-avaudioplayer – Aurelius Prochazka Sep 27 '18 at 00:33
  • Yeah, i've seen it. So there is nothing wrong in my code changing input logic? – drywet Sep 27 '18 at 10:48

0 Answers0