iPhone 11: No data from microphone after attaching a mixer to AVAudioEngine

Viewed 178

I have a recording app that uses AVAudioEngine. I am connecting a mixer to microphone to convert the data to desired format, then attach a tap to the mixer to retrieve the data. It used to work just fine until iPhone 11 was released. In iPhone 11 the data I get from microphone is simply complete silence.

After getting problem reported from users of the app I first checked the iPhone 11 simulator in newest XCode and, strange enough, it is working fine there. So I bought myself shiny new iPhone 11 and I could only confirm the app records nothing but silence.

The problematic part is this:

let audioEngine = AVAudioEngine()
let inputNode = audioEngine.inputNode
let main = audioEngine.mainMixerNode
let inputFormat = inputNode.inputFormat(forBus: 0)
let outputFormat = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)

audioEngine.attach(downMixer)
audioEngine.connect(inputNode, to: downMixer, format: inputFormat)
audioEngine.connect(downMixer, to: main, format: outputFormat)
downMixer.installTap(onBus: 0, bufferSize: 640, format: outputFormat) { (buffer, time) -> Void in
    print("First 20 bytes of recorded data:", terminator: " ")
    let data = Data(buffer: buffer)
    var i = 0
    for byte in data {
        print("\(byte)", terminator: ", ")
        i += 1
        if i > 20 {
            break;
        }
    }
    print("")
}

Once these lines:

audioEngine.connect(inputNode, to: downMixer, format: inputFormat)
audioEngine.connect(downMixer, to: main, format: outputFormat)

get executed, the output from the mic becomes null:

First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
First 20 bytes of recorded data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
etc.

I did a search on the internet and it seems no one is having similar problem. Am I doing something wrong?

0 Answers
Related