[alsa-devel] Join play of pcm in multiple playback devices

Pierre-Louis Bossart pierre-louis.bossart at linux.intel.com
Tue Jan 3 22:32:23 CET 2012

> while(1)
> {
>       retval=snd_pcm_readi(pAlsaConfig->pcm_handle, buffer,
> pAlsaConfig->alsaBufferSize);
>       snd_pcm_writei(pAlsaConfig->pcm_handle1, buffer,retval);
>       snd_pcm_writei(pAlsaConfig->pcm_handle2, buffer,retval);
> }

This code doesn't work in the general case where the different devices 
don't share a common audio clock and have different physical 
capture/playback rates. Compensating for clock drift requires the use of 
asynchronous sample-rate conversion.
Assuming you have a perfectly synchronous system, you could make use of 
snd_pcm_delay() to compensate for delays incurred in the 
driver/firmware/hardware. This is not well supported by all drivers though.

More information about the Alsa-devel mailing list