From: Robert Spier <rspier@pobox.com>
To: alsa-devel@lists.sourceforge.net
Subject: Using alsa-lib for timing
Date: Fri, 15 Nov 2002 09:36:08 -0800 [thread overview]
Message-ID: <15829.12424.589673.766811@rls.cx> (raw)
[Summary of this message:
I want to use alsa for timing of video frames, and want alsa to
trigger a wakeup every .01466 seconds. But the documentation is
sparse in this area]
I'm attempting to use alsa-lib as a timing tool for a specialized
movie playback engine. It _must_ tick/wakeup at 24fps (every .04166
sec) and the input audio will be at 44.1khz/2 channel/16bit per chan.
For legacy reasons we need to use the poll based interface
(getting the file handle from snd_pcm_poll_descriptors()).
Alsa will tick regularly at .0416 seconds if the period size is set to
1837[1] samples. This is suboptimal because:
1- this is a weird period size - generally powers of 2 are used
(1024,2048,4096)
2- for truly accurate 24fps playback we need 1837.5 samples/video
frame, which can be approximated by alternating between 1837 and
1838 samples/video frame. (And the period size cannot be changed
at runtime.)
The general solution to this with other sound libraries (OSS and IRIX)
is to use a rational period size and set a wakeup point. In ALSA,
this is done with snd_pcm_sw_params_set_avail_min, but it doesn't have
the expected effect.
Because it's only a _minimum_ the wakeup can be delayed (usually until
a multiple of the period size) is reached. This screws up the
timing. I saw something in the alsa-devel archives that wakeup points
(avail_min) settings can only be powers of two... which is different
than OSS.)
Am I missing something obvious here?
Are there any examples of code (or other tools?) doing similar things?
Please don't recommend I switch to asynchronous ticks, sadly, that
isn't an option for this code.
Thanks!
-R
Footnotes:
[1] 24fps = .041666 seconds/video frame
44100hz = samples/seconds
1837.5 samples/video frame
-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing
your web site with SSL, click here to get a FREE TRIAL of a Thawte
Server Certificate: http://www.gothawte.com/rd524.html
next reply other threads:[~2002-11-15 17:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-15 17:36 Robert Spier [this message]
2002-11-15 20:16 ` Using alsa-lib for timing Paul Davis
2002-11-26 6:03 ` Robert Spier
2002-11-26 11:27 ` James Courtier-Dutton
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=15829.12424.589673.766811@rls.cx \
--to=rspier@pobox.com \
--cc=alsa-devel@lists.sourceforge.net \
/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.