visual c++ - Sync two soundcards -


i have program written in c++ uses rtaudio ( directsound ) capture , playback audio @ 48khz samplerate.

the input capture uses callback option. callback writes data ringbuffer. output blocking write function in separate thread reads ringbuffer.

if input , output devices same audio loops thru perfectly. want audio device 1 , playback on device 2. each device has own sampleclock set 48khz not in sync. after couple of seconds input , output out of sync.

is possible sync 2 independent oudio devices?

there 2 challenges face:

  1. getting 2 devices start @ same time.
  2. getting 2 devices stay in sync.

both of these tasks difficult. in pro audio world, #2 accomplished special hardware sync word-clocks of multiple devices. can done high quality video signal. believe can done firewire devices, i'm not sure how works. in practice, have used devices no sync ("wild") , gotten reasonable sync hour or two. depending on trying do, sync should not drift more few milliseconds on course of few minutes. if does, can consider hardware broken (of course, cheap hardware broken).

as #1, i'm not sure possible in reliable sense directsound. extent it's possible audio api, difficult @ best: both cards have streams require time setup, open , start playing. in general, solution use api time super low (asio, example). works reasonably applications video, don't know if solves problem in general.

if need solve problem, open both cards, starting play silence, , use timing information generated cards establish delay between putting data card , eventual playback (this different each card , each time run) , use data calculate when start actual playback. don't know if rtaudio supplies necessary timing information, portaudio does. this document may help.


Comments