2
votes

I would like to sync audio playback and recording on two different computers from a common trigger signal using a c/c++ script. Expected delay should not exceed 1ms.

Retrieving a signal and then start a script is not really an issue, delay is quite insignificant (few micro seconds).

For the moment, i'm stuck in an average delay (between the beginning of playback and beginning of the record) of about 20ms and deviation is quite important (5 to 10 ms). Computers are running on Linux and I'm using aplay and arecord from alsa-utils (started directly from code using system() command).

Does someone has a good idea or experience to decrease or control the latency between the two audio interfaces ?

In my opinion, there should be a way to init both interface (rate, output format, ...) and, for the playback device, preload the data into the audio buffer and then start playing when signal is received.

Thanks

1
Audio synchronization is a tricky thing. May be you should look at JACK instead of messing with alsa API directly. You definitely can make single JACK output which will synchronously output audio on multiple computers.Alexey Guseynov

1 Answers

1
votes

This is a tough one, but also technically very interesting. The best approach I can think of at the moment would be using a RTT (round trip time) approach (Given that you can control the delay of the audio devices to the extent required). You can emit a signal on the first system to the second system, to which the second system replies. The second system starts recording after a predefined amount of time (maybe 100 ms, but depends on the expected latency). When the fist system has received the response it may determine the round-trip-time. We can then start the playback after the predefined delay, minus the half round-trip-time - assuming that the way forth takes the same amount of time as the way back. The accuracy that can be achieved depends on the systems you are using for signalling.

EMIT SIGNAL ON SYSTEM 1

RECEIVE SIGNAL ON SYSTEM 2
EMIT SIGNAL ON SYSTEM 2

RECEIVE SIGNAL ON SYSTEM 1
DETERMINE ROUND-TRIP-TIME

START ON SYSTEM 2 AFTER X ms
START ON SYSTEM 1 ASTER (X-RTT/2) ms