Underruns in basic audio playback application
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
Signature · 2 lines
Devin J. Heitmueller - Kernel Labs http://www.kernellabs.com
2009/12/3 Devin Heitmueller <[email protected]>:
Quoted 22 lines
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()andsnd_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.
Quoted 6 lines
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().
Quoted 3 lines · Christophe Osuna
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().
Thanks for the input. In the end, I hacked up a version of the test/latency.c to do what I needed. I think the root of the issue is that ALSA behaves badly if both the period and buffer sizes/times are configured, and the values provided do not match up (in terms of the buffer size relative to the period size).
Anyway, I've got it working now, so thanks anyway!
Devin
Signature · 2 lines
Devin J. Heitmueller - Kernel Labs http://www.kernellabs.com