From 58077e2f0d896ff848f3551518b1d9fc6c97d695 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 3 May 2023 22:24:47 +0200 Subject: pcm: hw: fix the silence size setup in drain The silence size cannot exceed the silence threshold. Move the check from the manual condition to the common code. This may happen for small ring buffers (where the 1/10th second is too large). Suggested-by: Oswald Buddenhagen Signed-off-by: Jaroslav Kysela --- src/pcm/pcm_hw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 180a3e84..8ffebed9 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -747,8 +747,6 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm) snd_pcm_sw_params_current_no_lock(pcm, &sw_params); if (hw->drain_silence > 0) { silence_size = (pcm->rate * hw->drain_silence) / 1000; - if (silence_size > pcm->buffer_size) - silence_size = pcm->buffer_size; goto __manual_silence; } /* compute end silence size, align to period size + extra time */ @@ -770,6 +768,8 @@ __manual_silence: * or the next period wake up) */ sw_params.silence_threshold = pcm->buffer_size; + if (silence_size > pcm->buffer_size) + silence_size = pcm->buffer_size; sw_params.silence_size = silence_size; if (ioctl(hw->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sw_params) < 0) { err = -errno; -- cgit v1.2.1