Can't set AVAudio sampleRate and installTap needs bufferSize 4800 at minimum

Two issues:

No matter what I set in

try audioSession.setPreferredSampleRate(x)

the sample rate on both iOS and macOS is always 48000 when the output goes through the speaker, and 24000 when my Airpods connect to an iPhone/iPad.

Now, I'm checking the current output loudness to animate a 3D character, using

mixerNode.installTap(onBus: 0, bufferSize: y, format: nil) { [weak self] buffer, time in
    Task { @MainActor in
         // calculate rms and animate character accordingly

but any buffer size under 4800 is just ignored and the buffers I get are 4800 sized. This is ok, when the sampleRate is currently 48000, as 10 samples per second lead to decent visual results.

But when AirPods connect, the samplerate is 24000, which means only 5 samples per second, so the character animation looks lame.

My AVAudioEngine setup is the following:

audioEngine.connect(playerNode, to: pitchShiftEffect, format: format)
audioEngine.connect(pitchShiftEffect, to: mixerNode, format: format)
audioEngine.connect(mixerNode, to: audioEngine.outputNode, format: nil)

Now, I'd be fine if the outputNode runs at whatever if it needs, as long as my tap would get at least 10 samples per second.

PS: Specifying my favorite format in the

let format = AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2)!
mixerNode.installTap(onBus: 0, bufferSize: y, format: format)

doesn't change anything either

PS: If I ask for the actual format like so

let actualFormat = mixerNode.outputFormat(forBus: 0)
Logger.tts.info("mixer node format: \(actualFormat)")

i actually get 44.1khz:

mixer node format: <AVAudioFormat 0x11cf65360:  2 ch,  44100 Hz, Float32, deinterleaved>
Can't set AVAudio sampleRate and installTap needs bufferSize 4800 at minimum
 
 
Q