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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>

---

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 --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;
-- 
2.40.0.152.g15d061e6df




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux