[alsa-devel] Misusing snd_pcm_avail_update()

Lennart Poettering mznyfn at 0pointer.de
Thu Jan 22 23:20:15 CET 2009

On Wed, 21.01.09 01:39, Takashi Iwai (tiwai at suse.de) wrote:

> > The function should look like this:
> > 
> >     snd_pcm_sframes_t snd_pcm_busy_for(snd_pcm_t *pcm);
> > 
> > I called the prototype "busy for" since effectively the value I am
> > looking for is the time the card will be busy with the data it already
> > has, and doesn't need any new data.
> Isn't it snd_pcm_delay() that was originally designed for?

No. Let me summarize the meaning of snd_pcm_update_avail(),
snd_pcm_delay() and my snd_pcm_busy_for() to opefully make clear where
the differences are:

snd_pcm_update_avail() -- returns how many samples can be written
                          right now without blocking.

snd_pcm_delay() -- returns how many samples will be played before the
                   samples that are written now can be heard.

snd_pcm_busy_for() -- returns how many samples will be played before
                      ALSA would enter an underrun situation if no
                      further samples are written.

snd_pcm_update_avail() and snd_pcm_busy_for() return metrics that are
solely dependant on the size and metrics of the hardware buffer and
its current indexes. snd_pcm_delay() also includes information about
any extra latency that comes after the playback buffer.

Onle snd_pcm_update_avail()/snd_pcm_busy_for() are influenced by "fast
starts" as done by the USB driver's double buffering and by
block-based transfer.

Hmm, I am trying my best to explain why I want this function and what
exactly it should do. Any chance I can convince you guys that this
function really matters for timer-based audio scheduling?

> Did you check my previous patch?

You mean the one that makes snd_pcm_delay() for USB devices actually
include the extra latency that comes after the playback buffer? No, I
didn't check that one yet. It takes so much time to patch the kernel
and test things... I'll try too finally do it this WE.


Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4

More information about the Alsa-devel mailing list