All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
To: alsa-devel@alsa-project.org
Subject: Re: [PATCH 1/2] ALSA: pcm: rewrite snd_pcm_playback_silence()
Date: Thu, 13 Apr 2023 11:44:29 +0200	[thread overview]
Message-ID: <ZDfO/dxtg81czJ2O@ugly> (raw)
In-Reply-To: <1775ab67-1967-e496-58af-e2aaa034f105@perex.cz>

On Wed, Apr 12, 2023 at 09:23:23PM +0200, Jaroslav Kysela wrote:
>On 12. 04. 23 12:33, Oswald Buddenhagen wrote:
>> On Tue, Apr 11, 2023 at 12:47:26PM +0200, Jaroslav Kysela wrote:
>>> On 05. 04. 23 22:12, Oswald Buddenhagen wrote:
>>>> +	else if ((snd_pcm_uframes_t) hw_avail >= runtime->boundary)
>>>> +		hw_avail -= runtime->boundary;
>>>
>>> If hw_avail is above runtime->boundary then the initial condition is totaly
>>> bogus. I would use snd_BUG_ON() and direct return here.
>>>
>I will correct that it will make sense where hw_ptr is nearby boundary 
>(boundary - buffer_size ... boundary - 1) and appl_ptr is cropped using 
>boundary (0 ... buffer_size).
>
no, that's the case where it goes negative.
because it's a subtraction, it plain cannot go over the boundary when 
both inputs are bounded.
due to the remaining correction, it could still go "very big" in an 
underrun condition, as the comment in the patch says.
we should discuss the implications of the latter for the 
snd_pcm_*_avail() functions separately (the apidoc doesn't make the 
contract clear at all).

>But because appl_ptr can be set by application without any kernel side 
>correction, it may be possible to check if the appl_ptr is in 0 ...  
>boundary range before any use.
>
that should be rather obviously done *somewhere*, as otherwise appl_ptr 
can often be even slightly above 2*boundary, at which point the above 
correction (and many alike) wouldn't even work. but for the sake of 
efficiency, that should be done asap, so when it is set or the boundary 
changes. no?

>>>>    		frames = runtime->silence_threshold - noise_dist;
>>>> +		if ((snd_pcm_sframes_t) frames <= 0)
>>>> +			return;
>>>
>>> The retyping does not look good here. Could we move the if before frames
>>> assignment like:
>>>
>>>    if (runtime->silence_threshold <= noise_dist)
>>>      return;
>>>    frames = runtime->silence_threshold - noise_dist;
>>>
>> dunno, i don't like it - it's more noisy and imo it loses
>> expressiveness, as the question we're asking is "how many frames do we
>> need to fill?".
>
>It seems that you have answer to everything.
>
only to the parts that i actually reply to ...

>(is the requested silence threshold fulfilled? or is the noise distance 
>greater than the whole buffer / buffer_size?).
>
but why would you want to approach it that way? it's just an extra step 
to think through. to reinforce the point: if the compiler is any good, 
then your variant will be optimized into mine.

regards

      reply	other threads:[~2023-04-13  9:46 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-05 20:12 [PATCH 1/2] ALSA: pcm: rewrite snd_pcm_playback_silence() Oswald Buddenhagen
2023-04-05 20:12 ` [PATCH 2/2] ALSA: pcm: auto-fill buffer with silence when draining playback Oswald Buddenhagen
2023-04-07 23:58   ` Jaroslav Kysela
2023-04-08  5:55     ` Takashi Iwai
2023-04-08  7:24     ` Oswald Buddenhagen
2023-04-11 11:09       ` Jaroslav Kysela
2023-04-11 13:57         ` Oswald Buddenhagen
2023-04-11 14:48           ` Jaroslav Kysela
2023-04-11 16:50             ` Oswald Buddenhagen
2023-04-11 17:23               ` Jaroslav Kysela
2023-04-12  7:54                 ` Takashi Iwai
2023-04-12  8:04                   ` Oswald Buddenhagen
2023-04-12 10:37                     ` Takashi Iwai
2023-04-12 11:38                       ` Oswald Buddenhagen
2023-04-12 19:59                       ` Jaroslav Kysela
2023-04-13  5:42                         ` Takashi Iwai
2023-04-13 10:16                           ` Oswald Buddenhagen
2023-04-13 10:28                             ` Takashi Iwai
2023-04-13 11:10                               ` Oswald Buddenhagen
2023-04-13 12:06                                 ` Takashi Iwai
2023-04-13 14:59                                   ` Oswald Buddenhagen
2023-04-14  8:26                                     ` Takashi Iwai
2023-04-14  8:56                                       ` Oswald Buddenhagen
2023-04-14  9:28                                         ` Takashi Iwai
2023-04-06 14:53 ` [PATCH 1/2] ALSA: pcm: rewrite snd_pcm_playback_silence() Takashi Iwai
2023-04-11 10:47 ` Jaroslav Kysela
2023-04-12 10:33   ` Oswald Buddenhagen
2023-04-12 19:23     ` Jaroslav Kysela
2023-04-13  9:44       ` Oswald Buddenhagen [this message]

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=ZDfO/dxtg81czJ2O@ugly \
    --to=oswald.buddenhagen@gmx.de \
    --cc=alsa-devel@alsa-project.org \
    /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.