CoreAudio crash - AVAudioIONodeImpl.mm:365: _GetHWFormat: required condition is false: hwFormat

Hi All,


I'm working with two application modules:


1) Recording module with this audioSession setup:



try audioSession.setCategory(AVAudioSessionCategoryRecord)
    try audioSession.setMode(AVAudioSessionModeMeasurement)
    try audioSession.setPreferredIOBufferDuration(0.05)
    try self.audioSession.setActive(true)



2) Recording module with this audioSession setup:


    try audioSession.setCategory(AVAudioSessionCategoryPlayback)
    try audioSession.setMode(AVAudioSessionModeDefault)
    try self.audioSession.setActive(true)



For each passage from 1->2 and 2-1 I have a

try self.audioSession.setActive(false)


If I pass from 1) module to 2) or redo 1) all works fine. Than if from 2) I come to 1) I get this error on

try self.audioSession.setActive(true)



This is the error:


ERROR: [0x16e10b000] >avae> AVAudioIONodeImpl.mm:365:

_GetHWFormat: required condition is false: hwFormat



What is this error related to? I can't find any help on Apple iOS documentation to understand where the problem can be.



Does anybody have any tip?

Replies

Hi,


This crash is still active and my app has it too on release products on AppStore. Cant reproduce on debug cases or cant reproduce for release app on all devices.


I use AVAudio like that and 12th line has a crash of "required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat)"



let recordingFormat: AVAudioFormat? = inputNode?.outputFormat(forBus: AVAudioNodeBus(0))
let inputFormat: AVAudioFormat? = inputNode?.inputFormat(forBus: AVAudioNodeBus(0))
var trueFormat: AVAudioFormat? = AVAudioFormat()
if inputFormat?.sampleRate == 0 {
            if let aChannels = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: AVAudioChannelCount(2)) {
                trueFormat = aChannels
            }
}
else {
            trueFormat = inputFormat
}          
inputNode?.installTap(onBus: AVAudioNodeBus(0), bufferSize: AVAudioFrameCount(8192), format: trueFormat, block: { buffer, when in
            AppUtils.shared.recognitionRequest?.append(buffer)
})
AppUtils.shared.audioEngine?.prepare()


Hope there is a fix for it.


Thanks

Kaan

I don't know if this will work, but it did for me. I am also not 100% sure why it worked, but I think by changing the audio session mode from .measurement to .voicePrompt, it only requires voice input and not output. Therefore, with no output, the error of input format not matching output format cannot occur, because there is no output. Please find my bug fix below:


Old code with format matching error:


do {

AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!)

AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!)

try audioSession.setCategory(.playAndRecord, mode: .measurement, options: .duckOthers)

} catch let error {

print("\(error)")

}


New code without error:


do {

AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!)

AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!)

try audioSession.setCategory(.playAndRecord, mode: .voicePrompt, options: .duckOthers)

} catch let error {

print("\(error)")

}


I may be wrong as I am a novice still. But I hope this helps!

Any update/solution?