[alsa-devel] Is there a way to figure out if the clocks of two snd_pcm_t's deviate? (snd_pcm_info_get_sync?)

Jaroslav Kysela perex at perex.cz
Fri Sep 4 08:44:50 CEST 2009

On Fri, 4 Sep 2009, Lennart Poettering wrote:

> Heya!
> I am looking for a way to find out whether the clocks of two
> snd_pcm_t's are perfectly in sync and don't deviate (or only deviate
> by a constant phase).
> i.e. for real duplex devices that use the same crystal for input and
> output this should tell me "Yes" for the playback snd_pcm_t tested
> against the recording snd_pcm_t; and for all other, unrelated audio
> devices it should return "No".
> I found snd_pcm_info_get_sync() in the docs, but its documentation is
> a bit terse, so I am wondering if this might be what I want. Is it?
> Does this (untested) code snippet do what I hope it does?


Nope. The snd_pcm_info_get_sync() function identifies streams with 
"sample sync and sample synchronized start".

All standard soundcards have only one clock source, so if 
snd_pcm_info_get_card() number matches, the streams will most probably 
run in sync.

I cannot recall from my mind, if any card has two clock sources - maybe 
only old Gravis UltraSound hardware with GF1 and CS4231 chips, but it's 
history. Also, professional hardware can run with word clock sync (wire 
connection carrying sample clock) or S/PDIF clock sync. But it's matter of 
user configuration.

I would suggest to match card number as default for used streams and add 
an user option to modify the stream word clock configuration for your app.


Jaroslav Kysela <perex at perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

More information about the Alsa-devel mailing list