diff mbox series

[2/2] pcm: hw: fix excessive silence fill on drain

Message ID 20230515084106.3447657-2-oswald.buddenhagen@gmx.de (mailing list archive)
State New, archived
Headers show
Series [1/2] pcm: hw: reinterpret the drain_silence setting | expand

Commit Message

Oswald Buddenhagen May 15, 2023, 8:41 a.m. UTC
Setting the threshold to the size of the buffer results in additional
filling each time a period elapses. As draining is usually initiated
with a rather full buffer, this would usually result in filling way in
excess of what was intended.

A sufficient threshold is the required worst-case fill, that is, one
period size plus the "overhang".

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>

---

This patch is entirely untested! But it's derived from my previously
posted v3 kernel patch, which was successfully tested.
---
 src/pcm/pcm_hw.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
index ecc47a76..a5f87215 100644
--- a/src/pcm/pcm_hw.c
+++ b/src/pcm/pcm_hw.c
@@ -764,12 +764,11 @@  static int snd_pcm_hw_drain(snd_pcm_t *pcm)
 	}
 	silence_size += silence_slack;
 	if (sw_params.silence_size < silence_size) {
-		/* fill the silence soon as possible (in the bellow ioctl
-		 * 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_threshold = pcm->period_size + silence_slack;
+		if (sw_params.silence_threshold > pcm->buffer_size)
+			sw_params.silence_threshold = pcm->buffer_size;
+		if (silence_size > sw_params.silence_threshold)
+			silence_size = sw_params.silence_threshold;
 		sw_params.silence_size = silence_size;
 		if (ioctl(hw->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sw_params) < 0) {
 			err = -errno;