[alsa-devel] Underruns in basic audio playback application

Devin Heitmueller dheitmueller at kernellabs.com
Thu Dec 3 17:04:46 CET 2009

Hello all,

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?

Thanks in advance,


Devin J. Heitmueller - Kernel Labs

More information about the Alsa-devel mailing list