All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Raymond Toy <rtoy@google.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: Alsa timing question
Date: Fri, 26 Aug 2011 10:02:35 +0200	[thread overview]
Message-ID: <4E57531B.3070107@ladisch.de> (raw)
In-Reply-To: <CAE3TgXHocCLC4T69p_n_yyDu6MFvyPF0-DOioZ-kZnXjyZn3Sw@mail.gmail.com>

Raymond Toy wrote:
> On Thu, Aug 25, 2011 at 12:15 AM, Clemens Ladisch <clemens@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.

The obvious way to resolve this problem would be to add a signal from
the other process to your process.  Even a serial number in the shared
memory area would help detecting problems.

> (I'm not in control of how this works.  I just have to deal with what
> I'm given.)

"It is a vessel of fertilizer, and none may abide its strength."

> > > [...] 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,

Your other mail shows you're using the PulseAudio plugin.

> > the period size of your application's device will not necessarily be
> > identical with the period size of the hardware device.

PulseAudio doesn't use period interrupts, it uses its own timer that,
apparently, runs at 50 ms.

In theory, you should use a period size that is an exact multiple of
50 ms, but in practice, this is not possible because the device's sample
clock is not synchronized with the computer's timer.

You could try to use, e.g.,  500 ms periods so that the inaccuracies of
PA's timer result in smaller relative jitter in your own timing, but
this will increase latency.

Try asking on the PA list how to get accurate period timing.


Regards,
Clemens

  reply	other threads:[~2011-08-26  8:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-25  0:10 Alsa timing question Raymond Toy
2011-08-25  7:15 ` Clemens Ladisch
2011-08-25 15:52   ` Raymond Toy
2011-08-26  8:02     ` Clemens Ladisch [this message]
2011-08-26  8:29     ` Olivier Guillion - Myriad
2011-08-26 15:56       ` Raymond Toy
2011-08-27  8:08         ` Olivier Guillion - Myriad
2011-08-27  9:15           ` Jassi Brar
2011-08-29 18:41           ` Raymond Toy
2011-08-29 20:24   ` Raymond Toy
2011-08-30  7:49     ` Clemens Ladisch
2011-08-30 19:04       ` Raymond Toy
2011-08-31 20:07         ` Clemens Ladisch

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=4E57531B.3070107@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=rtoy@google.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 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.