cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Unable to change BufferSize on Windows.

Open CaseyB opened this issue 4 years ago • 2 comments

I'm running into latency issues on Windows. When I iterate over the SupportedStreamConfigs I only get one option:

SupportedStreamConfigRange { channels: 4, min_sample_rate: SampleRate(48000), max_sample_rate: SampleRate(48000), buffer_size: Unknown, sample_format: F32 }

And when I try to change the buffer size to anything other than BufferSize::Default it tells me

The requested stream configuration is not supported by the device.

I'm kind of at a loss for where to go from here.

CaseyB avatar Feb 21 '21 19:02 CaseyB

Hello CaseyB,

I assume that you try to use WASAPI on Windows ? Right now, you can't choose the buffer size with this host, it's not implemented. By default, cpal try to get the smalest possible buffer. There is already on issue for that (https://github.com/RustAudio/cpal/issues/534). But you have to know that with WASAPI, you can't really choose the buffer size. You can ask for a buffer size and WASPI will try to give it to you but you have no warranty. you can check here : https://docs.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-initialize (If the call succeeds, the method allocates a buffer that is a least this large). I did some test and the buffer size may vary over time. If you need precise buffer size, you should try Asio host. By the way, if you succed, I am interested since I can't get it to work (https://github.com/RustAudio/cpal/issues/539).

downfall85 avatar Feb 23 '21 19:02 downfall85

In such case, is there a way to know ahead of time the buffer size that we will receive? Or a sensible upper bound for it? (I need it to implement de-interlacing of the channels) Because the upper bound I get from the default config is just gigantic: buffer_size: Range { min: 0, max: 4294967295 }

YPares avatar Apr 11 '24 19:04 YPares