Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: twischer@de.adit-jv.com
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH - Intervals v2 1/1] interval: Interpret (x x+1] correctly and return x+1
Date: Thu, 18 Oct 2018 14:02:56 +0200	[thread overview]
Message-ID: <s5hbm7rv4wf.wl-tiwai@suse.de> (raw)
In-Reply-To: <1539862404-21955-1-git-send-email-twischer@de.adit-jv.com>

On Thu, 18 Oct 2018 13:33:24 +0200,
<twischer@de.adit-jv.com> wrote:
> 
> From: Timo Wischer <twischer@de.adit-jv.com>
> 
> Without this change an interval of (x x+1] will be interpreted as an
> empty interval but the right value would be x+1.
> This leads to a failing snd_pcm_hw_params() call which returns -EINVAL.
> 
> An example issue log is given in the following:
> snd_pcm_hw_params failed with err -22 (Invalid argument)
> ACCESS: MMAP_NONINTERLEAVED
> FORMAT: S16_LE
> SUBFORMAT: STD
> SAMPLE_BITS: 16
> FRAME_BITS: 16
> CHANNELS: 1
> RATE: 16000
> PERIOD_TIME: (15999 16000]
> PERIOD_SIZE: (255 256]
> PERIOD_BYTES: (510 512]
> PERIODS: [2 3)
> BUFFER_TIME: 32000
> BUFFER_SIZE: 512
> BUFFER_BYTES: 1024
> 
> In case of (x x+1) we have to interpret it anyway as a single value of x to
> compensate rounding issues.
> For example the period size will result in an interval of (352 353) when
> the period time is 16ms and the sample rate 22050 Hz
> (16ms * 22,05 kHz = 352,8 frames). But 352 has to be chosen to allow a
> buffer size of 705 (32ms * 22,05 kHz = 705,6 frames) which has to be >= 2x
> period size to avoid Xruns. The buffer size will not end up with an
> interval of (705 706) simular to the period size because
> snd_pcm_rate_hw_refine_cchange() calls snd_interval_floor() for the buffer
> size. Therefore this value will be interpreted as an integer interval
> instead of a real interval further on.
> 
> This issue seems to exist since the change of 9bb985c38 ("pcm:
> snd_interval_refine_first/last: exclude value only if also excluded
> before")
> 
> Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
> ---
> > On 10/18/18 12:57, Takashi Iwai wrote:
> > This change looks risky.  The snd_interval_value() might be called
> > even if the interval isn't reduced to a single value.  Rather check
> > openmin instead.
> 
> If I would do
> "if (i->openmin)"
> on an interval of (x x+1) x+1 would be returned. But this would result in
> the second issue which I have tried to describe in the commit message:
> x has to be returned otherwise it is not guaranteed that
> buffer_size >= 2x period_size. And this would result in continuously Xruns.
> Therefore I would like to prefer
> "if (i->openmin && !i->openmax)"

Hm, I overlooked that there is an assert() before that.  So a
single-value interval is a must at this execution, so it doesn't
matter which one to take.

Didn't the assert() hit in your case with x+1, then?


Takashi

> diff --git a/src/pcm/interval_inline.h b/src/pcm/interval_inline.h
> index a68e292..d9a30b2 100644
> --- a/src/pcm/interval_inline.h
> +++ b/src/pcm/interval_inline.h
> @@ -51,12 +51,14 @@ INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i)
>  {
>  	assert(!snd_interval_empty(i));
>  	return (i->min == i->max || 
> -		(i->min + 1 == i->max && i->openmax));
> +		(i->min + 1 == i->max && (i->openmin || i->openmax)));
>  }
>  
>  INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i)
>  {
>  	assert(snd_interval_single(i));
> +	if (i->openmin && !i->openmax)
> +		return i->max;
>  	return i->min;
>  }
>  
> -- 
> 2.7.4
> 

  reply	other threads:[~2018-10-18 12:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18 11:33 [PATCH - Intervals v2 1/1] interval: Interpret (x x+1] correctly and return x+1 twischer
2018-10-18 12:02 ` Takashi Iwai [this message]
2018-10-18 12:28   ` Timo Wischer
2018-10-18 13:19     ` Takashi Iwai
2018-10-18 14:31       ` Timo Wischer
2018-10-18 14:45         ` Takashi Sakamoto
2018-10-18 15:16           ` Timo Wischer
2018-10-18 14:58         ` Takashi Iwai
2018-10-18 15:55           ` Timo Wischer
2018-10-18 18:57             ` Takashi Iwai
2018-10-22  7:19               ` Timo Wischer
2018-10-24  7:06                 ` Takashi Iwai
2018-10-24  7:44                   ` Timo Wischer
2018-10-24  7:48                     ` Takashi Iwai
2018-10-24  8:05                       ` Timo Wischer
2018-10-24 10:15                         ` Jaroslav Kysela

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=s5hbm7rv4wf.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=twischer@de.adit-jv.com \
    /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