I'm trying to change the input device used to listen to incoming audio. I've tried a number of solutions, but most end up with the following error when preparing and starting the audio-engine:
AVAEInternal.h:82:_AVAE_CheckAndReturnErr: required condition is false: [AVAudioEngineGraph.mm:1295:Initialize: (IsFormatSampleRateAndChannelCountValid(outputHWFormat))]
Current (simplified) code:
var engine = AVAudioEngine()
var inputDeviceID: AudioDeviceID = 41 // another audio input device
let sizeOfAudioDevId = UInt32(MemoryLayout<AudioDeviceID>.size)
let error = AudioUnitSetProperty(engine.inputNode.audioUnit!, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &inputDeviceID, sizeOfAudioDevId)
if error > 0
{
print(error)
}
let inputNode = engine.inputNode
engine.connect(inputNode, to: engine.mainMixerNode, format: nil)
engine.connect(engine.mainMixerNode, to: engine.outputNode, format: nil)
engine.prepare()
do
{
try engine.start()
}
catch
{
print("Failed to start the audio input engine: \(error)")
}
The audioDeviceId (41) is correct, because using a random number gives different errors.
What am I doing wrong?