From: Jaroslav Kysela Date: Wed, 3 May 2023 20:24:47 +0000 (+0200) Subject: pcm: hw: fix the silence size setup in drain X-Git-Tag: v1.2.9~1 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=58077e2f0d896ff848f3551518b1d9fc6c97d695;p=alsa-lib.git 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 --- 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;