cpal
cpal copied to clipboard
Requested buffer size not used on macOS
Hey there! I'm running into the following issue:
- I'm enumerating through all the
supported_output_configs()
and finding one where my preferred buffer size fits within theSupportedBufferSize
range. - I call
SupportedStreamConfigRange::with_sample_rate().config()
on this with a rate within the range - On the resulting
StreamConfig
, I set the buffer size to my preferred one, knowing it's within range - Build an output stream
The requested buffer size isn't taken into account. When I request 128
I get a stream of 279
. Other times I get 512
.
Am I doing something wrong? Is this a bug? Or is this a limitation of the CoreAudio framework, and if so:
- How do other software packages work around this, where you can pick a precise buffer size in the preferences?
- Shouldn't CPAL document this, and call this variable
preferred_buffer_size
or something? - Is there a way of knowing what max buffer size was decided on for the stream, before I call
play()
it? I need that information to build my audio chain
This is on macOS Ventura 13.1, with CPAL 0.15.0
.
I had this issue too. I don't know if it is related to core audio. From what I saw it seemed related to the sample rate. The buffer size would be normal for one sample rate and it would be weird for another. This not only happens on macOS, but also on Linux. I fixed it by using ring buffers.
Same on macOS Ventura as well. I request 480, I get 1044 (output device)
@w-ensink Yeah, I ended up writing a quick CoreAudio wrapper myself locally and it runs at the buffer size that I ask it to, so I'm guessing this is an actual bug in CPAL itself. The fact that it also happens on Linux is another give-away.
@w-ensink Yeah, I ended up writing a quick CoreAudio wrapper myself locally and it runs at the buffer size that I ask it to, so I'm guessing this is an actual bug in CPAL itself. The fact that it also happens on Linux is another give-away.
Oh wonder how much effort that can take, can you put it in a GitHub gist?
On Ventura 13.5, changing the default audio output from a device configured for 48khz to a device configured for 44.1khz, or indeed changing the configured sample rate for a device during playback via Audio MIDI Setup, results in the output buffer resizing without any notification from CPAL.