alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Raymond Yau <superquad.vortex2@gmail.com>
To: alsa-devel@alsa-project.org
Subject: Re: safe support for rewind in ALSA
Date: Tue, 9 Feb 2010 06:59:45 +0800	[thread overview]
Message-ID: <4f3252891002081459q29f02414hf168a596ab641995@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.1.10.1002012328440.3125@ecabase.localdomain>

2010/2/2 Kai Vehmanen <kvehmanen@eca.cx>

> Hi all,
>
> and then about the "other problem", e.g. of rewinding with drivers/HW that
> do burst transfers of samples from ALSA ringbuffer to a separate HW
> buffer. Uh oh, and what the subject says this thread is ought to be
> about.:)
>
> On Mon, 1 Feb 2010, Kai Vehmanen wrote:
>
> > So while snd_pcm_delay() provides a snapshot of the delay at the last DMA
> > burst/block-transfer (when hw_ptr+runtime->delay were last updated in the
> > driver), the information may be refined with snd_pcm_status_get_tstamp(),
> > which essentially tells the diff between T1&T3. So essentially what the
> > application is looking for is 'snd_pcm_delay()-(T3-T1)'.
> [...]
> > One idea is to tie this to the existing SNDRV_PCM_INFO_BATCH flag (e.g.
> > quoting existing documentation in pcm_local.h -> "device transfers
> samples in
> > batch"). So if the PCM has this flag set, application should interpret
> > snd_pcm_delay() results as referring to the last batch.
>
> Maybe the same INFO_BATCH flag could be used to help solve the rewind
> problem as well. If set, it is a signal that a segment of the ringbuffer
> (N samples after current hw_ptr) may have been already transferred, or is
> currently in transfer, and cannot be rewound (without stopping the stream
> and causing a glitch), but the elapsed callback and hw_ptr have not yet
> occured. And most importantly, when pointer() cb reports that hw_ptr jumps
> in bursts, so current snd_pcm_rewindable() implementation may not be
> accurate with these drivers.
>
> But then how much is N? I guess we can't assume N=period-size (does not
> apply for e.g. how pulseaudio uses ALSA in glitch free mode).
> Sw-params:xfer-align is not the same thing plus it's now deprecated. Any
> ideas?
>
> Hmm, or on a second though, maybe N=period-size is a good idea after all.
> E.g. drivers would configure the DMA transfers according to the
> hwparams:period-size, and apps such as pulseaudio could decide (by setting
> the period-size) how close to hw-ptr it wants to live (and still rewind if
> needed). Of course, it's not obvious how useful PA glitch-free is if used
> in this way...
>
> For applications, this would be hidden in the implementation of
> snd_pcm_rewindable() and snd_pcm_rewind() (they would check for
> INFO_BATCH and limit rewinding appropriately).
>
> PS Like with my earlier mail, I'm not 100% convinced this is a generic
>    enough approach (or if the wider community thinks this is
>    a serious enough of a problem), but with these proposals I'm
>    thinking what can be done within the scope of current (driver)
>    APIs...
>
>
>>  - at T3, application calls snd_pcm_delay() to query how many samples
>>   of delay there is currently (e.g. if it write a sample to ALSA
>>   PCM device now, how long before it hits the speaker)

No, your assumption (how long before it hits the speaker ) is wrong , refer
to

http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html

For playback the delay is defined as the time that a frame that is written
to the PCM stream shortly after this call will take to be actually audible.
It is as such the overall latency from the write call to the final DAC.

For capture the delay is defined as the time that a frame that was digitized
by the audio device takes until it can be read from the PCM stream shortly
after this call returns. It is as such the overall latency from the initial
ADC to the read call.
(e.g. the latency of decoding those AC3 or DTS pass through spdif by the
digital receiver is not included)

How about those sound cards which only support non-inteleaved mode ?

why do PA insist to use one period per buffer when only those ISA drivers
and intel8x0 have periods_min =1 , the most common HDA driver and most sound
cards have periods_min =2 ?

  reply	other threads:[~2010-02-08 22:59 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 17:20 safe support for rewind in ALSA pl bossart
2010-02-01 18:00 ` Jaroslav Kysela
2010-02-01 22:40   ` pl bossart
2010-02-03  2:20     ` Raymond Yau
2010-02-03 18:03       ` Kai Vehmanen
2010-02-03 20:52     ` Kai Vehmanen
2010-02-03 22:57       ` pl bossart
2010-02-08  1:22         ` Raymond Yau
2010-02-02  2:53   ` Raymond Yau
2010-02-06 11:59   ` Raymond Yau
2010-02-17 15:30     ` Lennart Poettering
2010-02-18  1:31       ` Raymond Yau
2010-02-18  2:33         ` Lennart Poettering
2010-02-18  3:21           ` Raymond Yau
2010-02-01 18:01 ` Mark Brown
2010-02-01 18:05   ` Jaroslav Kysela
2010-02-01 21:28     ` Kai Vehmanen
2010-02-01 21:54       ` Kai Vehmanen
2010-02-08 22:59         ` Raymond Yau [this message]
2010-02-09 20:54           ` Kai Vehmanen
2010-02-10 13:19             ` Raymond Yau
2010-02-10 13:36               ` Clemens Ladisch
2010-02-11  6:52                 ` Raymond Yau
2010-02-11  7:20                   ` Clemens Ladisch
2010-02-11  7:27                     ` Jaroslav Kysela
2010-02-15  3:03                       ` Raymond Yau
2010-02-17 15:46                         ` Lennart Poettering
2010-02-21 10:35                         ` Kai Vehmanen
2010-02-22  9:07                           ` Raymond Yau
     [not found]                           ` <20100221203500.GH31800@tango.0pointer.de>
2010-02-22 19:15                             ` semantics of SNDRV_PCM_INFO_BATCH (was: Re: safe support for rewind in ALSA) Kai Vehmanen
2010-02-23  7:02                               ` Raymond Yau
2010-02-23  2:37                           ` safe support for rewind in ALSA Raymond Yau
2010-02-23  2:44                           ` Raymond Yau
2010-02-17 15:42                       ` Lennart Poettering
2010-02-21 10:06                       ` Kai Vehmanen
     [not found]                         ` <20100221202144.GG31800@tango.0pointer.de>
2010-05-04  2:31                           ` Raymond Yau
2010-02-17 15:39                   ` Lennart Poettering
2010-02-17 15:36               ` Lennart Poettering
2010-02-17 15:35           ` Lennart Poettering
2010-02-01 22:10       ` Kai Vehmanen

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=4f3252891002081459q29f02414hf168a596ab641995@mail.gmail.com \
    --to=superquad.vortex2@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).