All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.demon.co.uk>
To: Juan Carlos Granda <granda@telecable.es>
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: Re: Audio and Video sync. Getting Timestamps
Date: Fri, 07 May 2004 00:02:13 +0000	[thread overview]
Message-ID: <409AD205.1010900@superbug.demon.co.uk> (raw)
In-Reply-To: <002501c433c2$70a06b90$a6b06153@palmian>

Juan Carlos Granda wrote:
> That's my app does:
> 
> 1.- Open the device for capture
> 2.- Set the access mode SND_PCM_ACCESS_RW_INTERLEAVED
> 3.- Set format 16 bits (SND_PCM_FORMAT_S16_LE)
> 4.- Set channels 2 (stereo)
> 5.- Set buffer time near 1 second
> 6.- Set period time near 0.1 seconds
> 7.- Copy the hardware params to alsa
> 8.- Set start threshold (0x7fffffffff -> Explicit start)
> 9.- Set transfer align 1
> 10.- Copy the software params to alsa
> 
> read loop:
>     - Read 'period size' frames (snd_pcm_readi)
> 
> How can i get the timestamp of the first frame read? If i use
> snd_pcm_status_get_trigger_tstamp i obtain the same timestamp all the times.
> If i use snd_pcm_status_get_tstamp i obtain the "now" time. Is there any way
> to get the timestamp of every period.
> 
> Thanks
> 
> 

I help develope xinehq.de.
We have needed to do audio, video sync, but we don't need any audio 
timestamps using the get_trigger_tstamp etc.
We just use the snd_pcm_delay() call.

Take an example.
Sample rate 10000 Samples a second (10000 just to make things easy to 
explain.)

We call snd_pcm_delay() and it returns 4000.
4000 samples at a sample rate of 10000 = 400ms.
If we now write some samples to the sound device, we know that they will 
arrive at the speakers in 400ms time.

If we have some audio that needs to be played in 500ms time, we just 
insert 100 samples(100ms of samples) before sending our audio. We just 
know that those samples will reach the speakers in 500ms time.

In xine, we do more compilcated things like resampling, so that samples 
are removed and added without the user noticing.

So, for your application, if you just call snd_pcm_delay() just before 
you write your samples, or just after you write them, you will get a 
measure of when they will play.

Cheers
James


-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver
higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3

  reply	other threads:[~2004-05-07  0:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-05  9:13 Audio and Video sync. Getting Timestamps granda
2004-05-05  9:38 ` Takashi Iwai
2004-05-05  9:39   ` Jaroslav Kysela
2004-05-06 23:32   ` Juan Carlos Granda
2004-05-07  0:02     ` James Courtier-Dutton [this message]
2004-05-07  6:59       ` Måns Rullgård
2004-05-07 11:52         ` 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=409AD205.1010900@superbug.demon.co.uk \
    --to=james@superbug.demon.co.uk \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=granda@telecable.es \
    /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.