All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaroslav Kysela <perex@perex.cz>
To: ALSA development <alsa-devel@alsa-project.org>
Cc: Takashi Iwai <tiwai@suse.de>,
	Oswald Buddenhagen <oswald.buddenhagen@gmx.de>,
	Jeff Chua <jeff.chua.linux@gmail.com>
Subject: [PATCH 3/5] ALSA: pcm: fix playback silence - correct the incremental silencing
Date: Fri,  5 May 2023 09:38:11 +0200	[thread overview]
Message-ID: <20230505073813.1219175-4-perex@perex.cz> (raw)
In-Reply-To: <20230505073813.1219175-1-perex@perex.cz>

The incremental silencing was broken with the threshold mode. The silenced
area was smaller than expected in some cases. The updated area starts
at runtime->silence_start + runtime->silence_filled position not
only at runtime->silence_start in this mode.

Unify the runtime->silence_start use for all cases (threshold and top-up).

Suggested-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 sound/core/pcm_lib.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 8a01aeda2213..cfdb4aa5f6fa 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -78,26 +78,24 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
 		if (frames > runtime->silence_size)
 			frames = runtime->silence_size;
 	} else {
-		if (new_hw_ptr == ULONG_MAX) {	/* initialization */
+		if (new_hw_ptr == ULONG_MAX) {
+			/* initialization, fill silence to whole unused buffer */
 			snd_pcm_sframes_t avail = snd_pcm_playback_hw_avail(runtime);
 			if (avail > runtime->buffer_size)
 				avail = runtime->buffer_size;
 			runtime->silence_filled = avail > 0 ? avail : 0;
-			runtime->silence_start = (runtime->status->hw_ptr +
-						  runtime->silence_filled) %
-						 runtime->boundary;
+			runtime->silence_start = runtime->status->hw_ptr;
 		} else {
-			ofs = runtime->status->hw_ptr;
-			frames = new_hw_ptr - ofs;
+			/* top-up mode (appl_ptr is not required) */
+			/* silence the played area immediately */
+			frames = new_hw_ptr - runtime->status->hw_ptr;
 			if ((snd_pcm_sframes_t)frames < 0)
 				frames += runtime->boundary;
-			runtime->silence_filled -= frames;
-			if ((snd_pcm_sframes_t)runtime->silence_filled < 0) {
+			if ((snd_pcm_uframes_t)frames < runtime->silence_filled)
+				runtime->silence_filled -= frames;
+			else
 				runtime->silence_filled = 0;
-				runtime->silence_start = new_hw_ptr;
-			} else {
-				runtime->silence_start = ofs;
-			}
+			runtime->silence_start = new_hw_ptr;
 		}
 		frames = runtime->buffer_size - runtime->silence_filled;
 	}
@@ -105,7 +103,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
 		return;
 	if (frames == 0)
 		return;
-	ofs = runtime->silence_start % runtime->buffer_size;
+	ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size;
 	while (frames > 0) {
 		transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
 		err = fill_silence_frames(substream, ofs, transfer);
-- 
2.39.2


  parent reply	other threads:[~2023-05-05  7:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  7:38 [PATCH 0/5] rewrite snd_pcm_playback_silence() again Jaroslav Kysela
2023-05-05  7:38 ` [PATCH 1/5] ALSA: pcm: Revert "ALSA: pcm: rewrite snd_pcm_playback_silence()" Jaroslav Kysela
2023-05-05  9:31   ` Takashi Iwai
2023-05-05  9:38     ` Oswald Buddenhagen
2023-05-05 10:44       ` Takashi Iwai
2023-05-05  7:38 ` [PATCH 2/5] ALSA: pcm: fix playback silence - use the actual new_hw_ptr for the threshold mode Jaroslav Kysela
2023-05-05  7:38 ` Jaroslav Kysela [this message]
2023-05-05  9:57   ` [PATCH 3/5] ALSA: pcm: fix playback silence - correct the incremental silencing Takashi Iwai
2023-05-05 10:17     ` Oswald Buddenhagen
2023-05-05  7:38 ` [PATCH 4/5] ALSA: pcm: playback silence - remove extra code Jaroslav Kysela
2023-05-05  7:38 ` [PATCH 5/5] ALSA: pcm: playback silence - move silence variables updates to separate function Jaroslav Kysela
2023-05-05  9:22 ` [PATCH 0/5] rewrite snd_pcm_playback_silence() again Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230505073813.1219175-4-perex@perex.cz \
    --to=perex@perex.cz \
    --cc=alsa-devel@alsa-project.org \
    --cc=jeff.chua.linux@gmail.com \
    --cc=oswald.buddenhagen@gmx.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.