Skip to content

Conversation

roderickvd
Copy link
Member

@roderickvd roderickvd commented Sep 7, 2025

Use device default number of periods for better device compatibility.

Problem

#990 broke playback on one of my USB devices on a Raspberry Pi 4 with the following error immediately on opening the stream:

A backend-specific error has occurred: `alsa::poll()` returned POLLERR

Changing to use set_period_time instead of set_period_size fixes stream opening, but then runs into the same error minutes after playback.

Investigations have shown that the root cause is to always set two periods. Reverting to the device defaults (four periods) fixes the issue.

Way Forward

I have reverted most of #990 (still: @attackgoat thanks a lot for your hard work on that!) to go back to the device defaults. Instead, with PR #1010 I am proposing an ergonomic API to set platform-specific options like the number of periods on ALSA.

I also submitted PR diwic/alsa-rs#137 to expose more Alsa getters and setters relevant to periods and buffers.

This mostly reverts #990 for device compatibility, by letting ALSA calculate
the period size from the device default period count. Forcing the period count
to 2 caused underruns on some systems.
@roderickvd
Copy link
Member Author

As the current code in master is now unstable for some ALSA devices, I am going to merge this now. Let's collaborate on #1010 to be able to programmatically set the number of periods.

@roderickvd roderickvd marked this pull request as ready for review September 11, 2025 20:45
@roderickvd roderickvd changed the title fix: improve ALSA period configuration for device compatibility fix: simplify ALSA buffer size and period configuration logic Sep 11, 2025
@roderickvd roderickvd merged commit 1c9c642 into master Sep 11, 2025
30 checks passed
@roderickvd roderickvd deleted the fix/alsa-buffer-size branch September 25, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant