Skip to content

alsa: Add configurable delay after sample rate change#200

Closed
wtp128pro wants to merge 1 commit into
audacious-media-player:masterfrom
wtp128pro:alsa-sample-rate-delay
Closed

alsa: Add configurable delay after sample rate change#200
wtp128pro wants to merge 1 commit into
audacious-media-player:masterfrom
wtp128pro:alsa-sample-rate-delay

Conversation

@wtp128pro

Copy link
Copy Markdown

Summary

  • Adds a write_silence_locked() helper that writes zero-filled frames to the PCM device via snd_pcm_writei for a configurable duration
  • Hooks into start_playback() immediately after snd_pcm_prepare() succeeds, so silence is written while the mutex is held and the pump thread is blocked — the only point where a direct write survives to hardware
  • Detects rate changes (including cold start, where the previous rate is 0) in open_audio() and arms the silence duration if the setting is non-zero
  • Exposes the setting as a spin button in the ALSA plugin preferences (0–10000 ms, step 10, default 0 = disabled)

Motivation

Some hardware DACs need a short settling period when the PCM sample rate changes. Without a delay, the first few milliseconds of audio after a rate transition are lost or corrupted. This is also observable on cold start when audacious first opens the audio device.

Test plan

  • Set delay to 0 — verify no audible change in behaviour for same-rate tracks
  • Set delay to 150 ms — verify silence is heard between tracks with different sample rates
  • Set delay to 150 ms — verify silence is heard at the start of the first track after launch
  • Verify the spin button appears in Preferences → Output → ALSA
  • Verify the setting persists across restarts

🤖 Generated with Claude Code

Writes silence to the PCM device for a user-configurable duration
whenever the sample rate changes between tracks (including on first
open after a cold start). This gives hardware DACs time to settle
before audio begins, preventing the first portion of a track from
being lost during the hardware transition.

The delay is exposed as a spin button in the ALSA plugin preferences
(0-10000 ms, step 10, default 0 = disabled).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jlindgren90

Copy link
Copy Markdown
Member

I don't like this. It is AI-generated, right?

From a quick scan:

  • Doesn't follow modern C++ best practices (raw new/delete)
  • Uses static variables with difficult-to-follow lifetimes
  • Should have probably been an effect plugin to begin with

Sorry, I don't have time to review in more detail.

@wtp128pro wtp128pro closed this May 2, 2026
@wtp128pro wtp128pro deleted the alsa-sample-rate-delay branch May 2, 2026 13:09
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

Successfully merging this pull request may close these issues.

2 participants