diff mbox series

ALSA: aloop: Fix random zeros in capture data when using jiffies timer

Message ID 20220901144036.4049060-1-pteerapong@chromium.org
State Accepted
Commit 3e48940abee88b8dbbeeaf8a07e7b2b6be1271b3
Headers show
Series ALSA: aloop: Fix random zeros in capture data when using jiffies timer | expand

Commit Message

Pattara Teerapong Sept. 1, 2022, 2:40 p.m. UTC
In loopback_jiffies_timer_pos_update(), we are getting jiffies twice.
First time for playback, second time for capture. Jiffies can be updated
between these two calls and if the capture jiffies is larger, extra zeros
will be filled in the capture buffer.

Change to get jiffies once and use it for both playback and capture.

Signed-off-by: Pattara Teerapong <pteerapong@chromium.org>
---

 sound/drivers/aloop.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Takashi Iwai Sept. 2, 2022, 6:58 a.m. UTC | #1
On Thu, 01 Sep 2022 16:40:36 +0200,
Pattara Teerapong wrote:
> 
> In loopback_jiffies_timer_pos_update(), we are getting jiffies twice.
> First time for playback, second time for capture. Jiffies can be updated
> between these two calls and if the capture jiffies is larger, extra zeros
> will be filled in the capture buffer.
> 
> Change to get jiffies once and use it for both playback and capture.
> 
> Signed-off-by: Pattara Teerapong <pteerapong@chromium.org>

Thanks, applied.


Takashi
diff mbox series

Patch

diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 9b4a7cdb103a..12f12a294df5 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -605,17 +605,18 @@  static unsigned int loopback_jiffies_timer_pos_update
 			cable->streams[SNDRV_PCM_STREAM_PLAYBACK];
 	struct loopback_pcm *dpcm_capt =
 			cable->streams[SNDRV_PCM_STREAM_CAPTURE];
-	unsigned long delta_play = 0, delta_capt = 0;
+	unsigned long delta_play = 0, delta_capt = 0, cur_jiffies;
 	unsigned int running, count1, count2;
 
+	cur_jiffies = jiffies;
 	running = cable->running ^ cable->pause;
 	if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) {
-		delta_play = jiffies - dpcm_play->last_jiffies;
+		delta_play = cur_jiffies - dpcm_play->last_jiffies;
 		dpcm_play->last_jiffies += delta_play;
 	}
 
 	if (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) {
-		delta_capt = jiffies - dpcm_capt->last_jiffies;
+		delta_capt = cur_jiffies - dpcm_capt->last_jiffies;
 		dpcm_capt->last_jiffies += delta_capt;
 	}