[alsa-devel] Control the exact moment of output
pe1chl at amsat.org
Tue Apr 29 10:25:16 CEST 2014
Clemens Ladisch wrote:
> Rob Janssen wrote:
>> For a distributed system that requires synchronized output I would like to determine
>> the exact moment when output samples are sent, preferably within +/- 1 sample time.
>> Is this possible within the ALSA API?
> In theory, yes; snd_pcm_delay() should take these latencies into account.
> In practice, there is no hardware where this value is accurate. Drivers with
> large latencies (e.g., USB) report their internal queues, but nobody bothers
> for the small delays (about 10 samples) in the DMA controllers and DACs.
Ok, thanks for the reply!
We will use PCI soundcards, not USB dongles, and it is not a problem when there is a fixed extra delay
that is the same for all the systems. What we need to control is the synchronization between
the physically separated systems, and my approach up to now is to do this by synchronizing
to the very precise system time derived from GPS.
I was thinking along the line of an API feature where one can send frames with a related moment
of playback, but now I realize that what I should do is calculate how far off the desired playback
moment we are (using the current system time, the desired playback time, and the snd_pcm_delay)
for each block, and then pad or trim some frames as required before sending the block.
Is that correct?
>> And are there soundcards available where the sample clock can somehow be
>> locked to system time or an external 10MHz/1PPS reference?
> Some cards can be locked to an S/PDIF input or to a word clock from another
> sound card. This does not work for physically separated outputs; you'd have
> to measure the clock differences and do dynamic resampling.
We would have to generate a word clock or S/PDIF signal from the 10MHz/1PPS we have available
from the GPS (which are synchronous on all the sites). That will be the next step when the first
approximation does not yield us enough perfection.
More information about the Alsa-devel