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

On Fri, 05 May 2023 09:38:11 +0200,
Jaroslav Kysela wrote:
> 
> 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>

While this change itself follows the original code, and is fine from
the code-refactoring POV.

But, the difficulty of the code (even after this patch) is that the
filling behavior is completely different between the threshold and the
fill-up modes, and we still try to use the similar code.
When reconsidering what we actually need, you can notice that, in the
fill-up mode, we don't have to keep tracking silence_start and
silence_size at all.

Namely, in the fill-up mode, what we need are:
- at init, fill silence in the unused buffer:

	ofs = runtime->control->appl_ptr % runtime->buffer_size;
	frames = snd_pcm_playback_avail(runtime);
	fill_silence_in_loop(ofs, frames);

- at each incremental hw_ptr update, fill the area with silence:

	ofs = runtime->status->hw_ptr % runtime->buffer_size;
	frames = new_hw_ptr - runtime->status->hw_ptr;
	if (frames < 0)
		frames += runtime->boundary;
	fill_silence_in_loop(ofs, frames);

That's all, and far simpler than keeping silence_start and
silence_filled.  (I really had hard time to understand why filling at
silence_start + silence_filled in the incremental mode works
correctly...)

I might have overlooked something and there can be a bit more room for
optimization, but the point is that unifying the code for two behavior
isn't always good.  Treating separately can be sometimes easier.


thanks,

Takashi

  reply	other threads:[~2023-05-05  9:58 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 ` [PATCH 3/5] ALSA: pcm: fix playback silence - correct the incremental silencing Jaroslav Kysela
2023-05-05  9:57   ` Takashi Iwai [this message]
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=87y1m3hzir.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=jeff.chua.linux@gmail.com \
    --cc=oswald.buddenhagen@gmx.de \
    --cc=perex@perex.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox