[alsa-devel] Alsa timing question

Raymond Toy rtoy at google.com
Thu Aug 25 17:52:30 CEST 2011

On Thu, Aug 25, 2011 at 12:15 AM, Clemens Ladisch <clemens at ladisch.de>wrote:

> Raymond Toy wrote:
> > I'm working on an application where I'd like to have relatively fixed
> timing
> > between calls to snd_pcm_writei.
> Why?

It's a bit complicated.  A different process generates the audio and places
the data in a shared memory area.  My process sends signals the other
process to generate more data, I read the shared memory area (for the
previously generated data).  Sometime later, the other process fills the
shared area with new samples.  Thus, if the timing between calls is not
fairly regular, I'll either reread the same data or miss the new data.  (I'm
not in control of how this works.  I just have to deal with what I'm

> > [...] I see is that most calls to snd_pcm_writei are spaced about 50 ms
> > apart.  This makes some sense, but I was expecting the calls to be about
> > 42.67 ms apart.  However, about every 6th call, the time is just 200 us
> > or so.  Why is that?
> In theory, when the device is configured for a specific period size, its
> interrupts (and therefore the application wakeups) will arrive spaced at
> this interval (modulo any scheduling delays).
> However, if you're using the dmix plugin, the period size of your
> application's device will not necessarily be identical with the period
> size of the hardware device.  To see the actual period size, look into
> /proc/asound/card?/pcm0p/sub0/hw_params.
It says:

format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 44096
buffer_size: 88192


More information about the Alsa-devel mailing list