Skip to content

Conversation

@roderickvd
Copy link
Member

Reported on Discord:

When enumerating devices I get a lot of alsa errors:

[2025-10-16T22:38:51Z INFO  alsa] ALSA lib confmisc.c:855:(parse_card) cannot find card '$CARD'
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5205:(_snd_config_evaluate) function snd_func_card_inum returned error: No such device
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5205:(_snd_config_evaluate) function snd_func_concat returned error: No such device
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib confmisc.c:1342:(snd_func_refer) error evaluating name
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5205:(_snd_config_evaluate) function snd_func_refer returned error: No such device
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5728:(snd_config_expand) Evaluate error: No such device
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5541:(parse_args) Unknown parameter CARD
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5712:(snd_config_expand) Parse arguments error: No such file or directory
[2025-10-16T22:38:51Z INFO  alsa] ALSA lib conf.c:5541:(parse_args) Unknown parameter CARD
...

This is due to trying to open devices that were configured as templates in ALSA. Basically this is an ALSA configuration mistake, however, there's no point to cpal trying to open them either, so that's just removed now.

Cleaned up a little while there.

This PR builds on top of #1033, so review just the last commits to see what's changed on top.

Avoid setting period count when BufferSize::Default is used, allowing
PipeWire-ALSA to select optimal buffer and period sizes. This prevents
excessively large periods and high latency on PipeWire-ALSA devices.
@roderickvd
Copy link
Member Author

Note to self: devices() currently returns an empty Vec. Instead, it should return the combination of input and output devices.

Set buffer_size_near before period_size_near for Fixed buffer sizes to
constrain total latency and avoid extremely large allocations (eg.
PipeWire-ALSA creating ~1M-frame buffers). Then set period_size to keep
double-buffering semantics.

Adjust avail_min by direction: for playback wake when level drops to
one period (buffer - period); for capture wake when one period is
available (period) to prevent excessive capture latency.
Revert to v0.16 behavior: always terminate stream without attempting
state-based drain or wait. Remove buffer-duration calculation and
snd_pcm_wait usage to avoid delays during drop.
Query the device's period size and set buffer_size to 2 * period for
BufferSize::Default. This prevents excessive memory allocation (e.g.
PipeWire-ALSA) while respecting the device's period preference.
This should always align with the two-period double-buffering strategy that we use anyway.
- Introduce init_hw_params and a TryFrom<SampleFormat> implementation to
  centralize format and hw param initialization.

- For BufferSize::Default, constrain both period and buffer to enforce
  double-buffering (2 periods), preventing pathologically large periods
  with PipeWire-ALSA.

- Update docs to clarify ring buffer/period behaviors and add issue
  references.
@roderickvd roderickvd force-pushed the fix/pointless-device-opening branch from 4c7eaad to 9c8ea9a Compare November 12, 2025 01:41
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.

2 participants