Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requested buffer size not used on macOS #748

Open
stijnfrishert opened this issue Feb 4, 2023 · 5 comments
Open

Requested buffer size not used on macOS #748

stijnfrishert opened this issue Feb 4, 2023 · 5 comments

Comments

@stijnfrishert
Copy link

stijnfrishert commented Feb 4, 2023

Hey there! I'm running into the following issue:

  1. I'm enumerating through all the supported_output_configs() and finding one where my preferred buffer size fits within the SupportedBufferSize range.
  2. I call SupportedStreamConfigRange::with_sample_rate().config() on this with a rate within the range
  3. On the resulting StreamConfig, I set the buffer size to my preferred one, knowing it's within range
  4. 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.

@w-ensink
Copy link

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.

@morajabi
Copy link

Same on macOS Ventura as well. I request 480, I get 1044 (output device)

@stijnfrishert
Copy link
Author

@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.

@morajabi
Copy link

@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?

@jacobstern
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants