All of lore.kernel.org
 help / color / mirror / Atom feed
* Using alsa-lib for timing
@ 2002-11-15 17:36 Robert Spier
  2002-11-15 20:16 ` Paul Davis
  2002-11-26 11:27 ` James Courtier-Dutton
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Spier @ 2002-11-15 17:36 UTC (permalink / raw)
  To: alsa-devel


[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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-26 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-15 17:36 Using alsa-lib for timing Robert Spier
2002-11-15 20:16 ` Paul Davis
2002-11-26  6:03   ` Robert Spier
2002-11-26 11:27 ` James Courtier-Dutton

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.