cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Allow querying the buffer size of a Stream

Open will3942 opened this issue 1 month ago • 1 comments

On Android, amongst other platforms, when using the default buffer size the platform sets the buffer size, this would be useful to query at runtime.

Context on PR - https://github.com/RustAudio/cpal/pull/1039

will3942 avatar Nov 12 '25 11:11 will3942

Agreed. #964 did some work on that. Maybe we could have both: buffer size and latency, if supported. I was thinking to work on this onto v0.18 (with v0.17 currently in release cycle). Happy to receive contributions.

roderickvd avatar Dec 10 '25 20:12 roderickvd

I wonder whether the default buffer size could be put in Device::default_{input, output}_config, like the device's preferred sample rate already is? Currently it returns a (fairly useless, on pipewire-alsa at least) SupportedStreamConfig, in the sense that the buffer size it provides is just a range from 1 to 4194304.

edwloef avatar Dec 19 '25 21:12 edwloef

Most hosts that cross my mind actually don't have a way of returning their default buffer size. You may only query it after you've created a stream.

roderickvd avatar Dec 23 '25 08:12 roderickvd

Most hosts that cross my mind actually don't have a way of returning their default buffer size. You may only query it after you've created a stream.

After some more investigation, I believe that CoreAudio, AAudio and JACK could return a default buffer size before trying to initialize a stream. ALSA & WASAPI can't. ASIO maybe. 3 or 4 out of 6... that's right on the edge of whether it's cross-platform yes/no.

I'll be pushing a PR soon to address this issue of querying the buffer size of a stream. With a bit of a workaround that'd enable a user to try and recreate a stream, if the results of BufferSize::Default aren't to his or her liking. If in the future the need for querying ahead of stream creation still comes up, we can consider.

roderickvd avatar Dec 23 '25 15:12 roderickvd

PR up at #1080

roderickvd avatar Dec 23 '25 20:12 roderickvd