Skip to contentSkip to conversation

timestamps

DISCUSSION Jonas Holmberg 2 participants 2 messages Apr 21, 2010 – May 4, 2010

lore
Share & tools
lore
#0 lore raw

How can I get the CLOCK_MONOTONIC timestamp for the first sample in the data I get from snd_pcm_readi()?

/Jonas

#1 lore raw

Hi,

Quoted 2 lines · Jonas Holmberg

How can I get the CLOCK_MONOTONIC timestamp for the first sample in the data I get from snd_pcm_readi()?

before reading the data, take the current timestamp (with clock_gettime) and subtract snd_pcm_delay() for the stream (see the API docs for snd_pcm_delay() for more details).

The accuracy of the returned value depends on the driver/hw's ability to report accurate delay values.

PS Alternate strategy is to use SND_PCM_TSTAMP_MMAP mode, in which
you can query (with snd_pcm_htimestamp()) the timestamp of last period elapsed event. See the alsa-lib PCM API docs for details. With certain drivers/hw, this is the only way to get accurate estimates for delay.