Commit 82db14c
Constrain ALSA buffer size and start_threshold in fallback path
When buffer/period negotiation fails and we fall back to the device's
defaults, some devices (e.g. USB audio via the `front:` plugin) end up
with enormous buffers (1M+ frames at 44.1 kHz = ~23 seconds of audio).
This causes two user-visible problems:
1. Playback start is delayed because start_threshold is set to
buffer_size - period_size, so ALSA waits for ~23 seconds of data
to be written before producing any output.
2. Track changes block because drain() must wait for the entire buffer
to play out before the sink can be reopened for the next track.
Fix both by:
- Calling set_buffer_size_near(MAX_BUFFER) on the fallback hw params
so the device picks a buffer close to 500 ms instead of its
unconstrained default. This is best-effort (errors are ignored) and
does not change behavior for devices that already negotiate
successfully.
- Capping start_threshold to at most SAMPLE_RATE frames (1 second) so
that even if the buffer is still large, playback begins promptly.
Co-Authored-By: Claude Opus 4.6 <[email protected]>1 parent 29ec49b commit 82db14c
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
365 | 370 | | |
366 | 371 | | |
367 | 372 | | |
| |||
376 | 381 | | |
377 | 382 | | |
378 | 383 | | |
379 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
380 | 389 | | |
381 | 390 | | |
382 | 391 | | |
| |||
0 commit comments