Recordings on iOS 18.0 beta start with stuttering.

I'm experiencing stuttering every time I record something with my iOS app on iOS 18 beta. The code ran fine on previous iOS versions.

The stuttering occurs for the first 2 seconds. Here's an example: https://soundcloud.com/thomas-walther-219010679/ios-18-stuttering

The way I set up AVAudioEngine and AVAudioSession was vetted quite thoroughly during sessions at WWDC '23. Here is how the engine and the tap is configured:

let engine = AVAudioEngine()
let recorderNode = AVAudioMixerNode()
engine.attach(recorderNode)

engine.connect(engine.mainMixerNode,    to: engine.outputNode,      format: engine.outputNode.inputFormat(forBus: 0))
engine.connect(recorderNode,            to: engine.mainMixerNode,   format: recordingOutputFormat)
engine.connect(engine.inputNode,        to: recorderNode,           format: engine.inputNode.inputFormat(forBus: 0))

let bufferSize: AVAudioFrameCount = 4096
recorderNode.installTap(onBus: 0, bufferSize: bufferSize, format: nil) { [weak self] buffer, time in
    guard let self = self else { return }
    
    do {
        // Write recording to disk
        try audioFile.write(buffer)
    } catch {
        // ...
    }
}

I tried setting a different buffer size, but with no luck. I also can't see any hangs in Instruments. Do you have any pointers on how to debug this?

Please use Feedback Assistant to submit a bug report, and please post here the ID generated by Feedback Assistant. If possible, please capture a sysdiagnose after reproducing the issue and attach it to your bug report.

Certainly. The ID is FB14713293, and a sysdiagnose is attached.

I've been able to reproduce the problem with a small example project. I uploaded it to FB14713293, alongside new system diagnostics gathered right after running the example project. It is also available here: https://github.com/TapeIt/ios18-record-stuttering

The project contains a simple SwiftUI view with a record and a play button, a TapeDeck class that configures AVAudioSession and handles global recording and playback state, and a Recorder class that does the actual recording.

I also stumbled on a second bug: If you set the sampleRate to 48000 in Recorder.swift, another bug occurs: the stuttering is now faster, and happens on the entire recording.

I looked more into this. It seems that automatic sample rate conversion on iOS 18 is broken, at least between engine.inputNode and other AVAudioMixerNodes. I've worked around it by manually doing the sample rate conversion using AVAudioConverter, but this means that I no longer set up an audio graph with the inputNode connected to other nodes in the graph.

This seems like a major regression in AVAudioEngine.

Recordings on iOS 18.0 beta start with stuttering.
 
 
Q