Repository navigation
Conversation
kapok-4o
left a comment
There was a problem hiding this comment.
from_device() now treats the WASAPI shared-mode scheduling period as a buffer limit. For software endpoints, CPAL 0.18.1 and 0.18.2 report that period as a one-value range. The stream builder passes the requested duration to IAudioClient::Initialize. With a custom CPAL device at 48 kHz, the base requests 2048 frames and this PR requests 480, even though the device accepts 2048. Can we preserve the preferred request when the backend accepts it? The actual buffer allocation still needs a Windows check.
In the capped-device test, the PR opens the stream with 960 frames. It would be worth keeping regression tests for both cases. The default macOS suite passed and Clippy had no new warnings. The stream docs could also use the 50 ms target and express buffer duration as frames divided by sample rate.
The reported range isn't always a limit. WASAPI in shared mode reports the device period as a one-value range for software endpoints, and takes any size, so clamping to it asked for 480 frames at 48 kHz where 2048 opened fine. Keep asking for 50 ms first, and fall back to the nearest size in the range only if building the stream fails. A size set with `with_buffer_size` or `with_config` is still never replaced. Tests cover a capped device, which now opens with 960 frames after 2048 is refused, and one that takes the preferred size despite its range, using cpal's custom devices. The `stream` docs now state the 50 ms target and give a buffer's duration as frames over the sample rate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
|
Thanks @kapok-4o! Good catch on WASAPI, and cpal's code agrees: for software endpoints, the range is the device period, and
What I couldn't check is the buffer WASAPI really allocates, since I don't have a Windows machine. The tests only show what rodio asks for. Also, the speakers API's |
kapok-4o
left a comment
There was a problem hiding this comment.
Thanks for the update. Both earlier points are addressed: with 0284e05 a WASAPI-style one-value range keeps the 2048-frame request, and the capped case retries with 960. The stream docs now give the 50 ms target and frames divided by sample rate.
I checked whether the new tests catch the bug. On the base stream.rs, capped_device_opens_with_the_largest_size_it_takes fails. On 427acec, both it and device_keeps_the_preferred_size_when_it_takes_it fail. chosen_buffer_size_is_never_replaced passes on all three, so it guards against a future regression rather than this change.
One small, optional point: src/stream.rs:447 retries on any BuildError. With a custom device returning DeviceBusy, rodio requests 2048 and then 960, and still returns the first error, so nothing is masked. It only costs one pointless attempt. CPAL 0.18.1 reports an out-of-range size as ErrorKind::UnsupportedConfig on CoreAudio and ALSA, so checking e.kind() == UnsupportedConfig would limit the retry to that case.
Locally on macOS (stable 1.99): cargo fmt --check and cargo clippy --all-features -- -D warnings are clean. cargo test --all-targets passed 113 (1 ignored), --all-features passed 153 (1 ignored), and --doc passed 71 (2 ignored). The Windows allocation is still untested on my side. Otherwise this looks good to me.
Any build error led to a second attempt with the clamped buffer size, so a busy device was tried twice for nothing. Hosts report a buffer size outside the device's range as `UnsupportedConfig`, so retry only on that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
|
Thanks @kapok-4o, and for checking which tests catch what! Done in 2868c19: the retry now only happens when the build fails with |
from_devicepicks a 50 ms buffer without checking what the device accepts. My AirPods only take 15–960 frames, so it asks for 2048, and cpal 0.18 refuses a fixed size outside the supported range — the stream never opens.open_default_sinkthen walks the other devices and takes the first that opens. On my machine that's a virtual output from a screen recorder, so the audio plays somewhere nobody can hear. That part surprised me more than the failure itself.The range is already in
default_config, so when the device refuses the 50 ms size as an unsupported config, this retries with it clamped to that range. It doesn't clamp up front, since the range isn't always a limit: WASAPI in shared mode reports its period as a one-value range and takes any size.Might be #900 as well — same "worked on crates.io, unsupported device on master" shape, on Windows.