[alsa-devel] Underruns in basic audio playback application

Christophe Osuna christophe.osuna at gmail.com
Fri Dec 4 09:28:57 CET 2009

2009/12/3 Devin Heitmueller <dheitmueller at kernellabs.com>:
> I am working on a very basic application that reads a capture device
> and outputs to a playback device.  It's what you would traditionally
> accomplish with something like the following:
> arecord -D hw:1,0 -r 48000 -c 2 -f S16_LE | aplay -
> However, in this case, since the final result will be part of a TV
> watching application, I need to maintain less than 30ms of latency to
> preserve lipsync.
> The application I ended up with essentially creates two PCM streams
> (one for capture, one for playback), sets them up with the same
> parameters in terms of rate, format, channels, etc., and then has a
> loop of snd_pcm_readi() and snd_pcm_writei() calls.
> The application works, except I am getting a considerable amount of
> underruns on the playback device.
> Given my relative inexperience with alsa-lib, I suspect that I have
> misconfigured one of the parameters effecting buffering - buffer size,
> buffer time, period size, period time.
> Can anyone offer any constructive suggestions or tips on what these
> tuning parameters should be set to for a continuous 48000Khz, 2
> channel stream of audio?  Also, should the buffering configuration
> really be the same for both the capture and playback stream, or do I
> need to play some games such that one requires more/less buffering
> than the other?

I don't have much experience myself, but in such a situation I would
recommend either increasing buffer size, or linking capture and
playback devices with snd_pcm_link().

More information about the Alsa-devel mailing list