All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
To: alsa-devel@alsa-project.org
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH 1/2] pcm: hw: reinterpret the drain_silence setting
Date: Mon, 15 May 2023 10:41:05 +0200	[thread overview]
Message-ID: <20230515084106.3447657-1-oswald.buddenhagen@gmx.de> (raw)

It makes no sense to have a config option which determines the entire
silencing time, because useful values strongly depend on the period size
runtime setting.

So instead we interpret the setting as an override for the "overhang"
which is used to compensate FIFOs and IRQ delays. The reasonable worst
case of this is determined by the hardware, so it makes sense to have
this as a config option.

In a next step, we may want to derive the default value from the
declared FIFO size (whiche few drivers do) and the minimal period size
(which is generally linked to the FIFO size).

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
 src/pcm/pcm_hw.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
index 8ffebed9..ecc47a76 100644
--- a/src/pcm/pcm_hw.c
+++ b/src/pcm/pcm_hw.c
@@ -737,18 +737,19 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm)
 {
 	snd_pcm_hw_t *hw = pcm->private_data;
 	snd_pcm_sw_params_t sw_params;
+	snd_pcm_uframes_t silence_slack;
 	snd_pcm_uframes_t silence_size;
 	int err;
 
 	if (pcm->stream != SND_PCM_STREAM_PLAYBACK)
 		goto __skip_silence;
 	if (hw->drain_silence == 0 || hw->perfect_drain)
 		goto __skip_silence;
 	snd_pcm_sw_params_current_no_lock(pcm, &sw_params);
-	if (hw->drain_silence > 0) {
-		silence_size = (pcm->rate * hw->drain_silence) / 1000;
-		goto __manual_silence;
-	}
+	if (hw->drain_silence > 0)
+		silence_slack = (pcm->rate * hw->drain_silence) / 1000;
+	else
+		silence_slack = pcm->rate / 10;	/* 1/10th of second */
 	/* compute end silence size, align to period size + extra time */
 	if ((pcm->boundary % pcm->period_size) == 0) {
 		silence_size = pcm->period_size - (*pcm->appl.ptr % pcm->period_size);
@@ -761,8 +762,7 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm)
 		 */
 		silence_size = pcm->period_size;
 	}
-	silence_size += pcm->rate / 10;	/* 1/10th of second */
-__manual_silence:
+	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)
-- 
2.40.0.152.g15d061e6df


             reply	other threads:[~2023-05-15  8:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15  8:41 Oswald Buddenhagen [this message]
2023-05-15  8:41 ` [PATCH 2/2] pcm: hw: fix excessive silence fill on drain Oswald Buddenhagen
2023-05-15  9:06 ` [PATCH 1/2] pcm: hw: reinterpret the drain_silence setting Jaroslav Kysela
2023-05-15  9:55   ` Oswald Buddenhagen

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=20230515084106.3447657-1-oswald.buddenhagen@gmx.de \
    --to=oswald.buddenhagen@gmx.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=perex@perex.cz \
    --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.