[alsa-devel] Playback underrun recovery
Paul D. DeRocco
pderocco at ix.netcom.com
Sat Apr 21 23:12:20 CEST 2012
I've got a synth program outputting directly to the main hw PCM device, with
no intervening plugins. It uses about 75-80% of the time on one core, so it
normally doesn't underrun. Once in a while, other burdens on the system
trigger an underrun, and my program never recovers. My buffer contains two
periods of 256 stereo frames (with 32-bit samples), which at 96KHz comes out
to a little over 5.3ms total. When it fails, its CPU usage goes up to 100%
on that core, and it spits out bursts of 5.3ms of audio (two full periods,
not one), with about 4ms of silence between them. My top level code consists
of a loop that generates one period at a time:
int buf[512];
while (true) {
generate_samples(buf, 256); // generate 256 stereo frames
if (snd_pcm_writei(h, buf, 256) < 0)
snd_pcm_prepare(h);
}
The funny thing is that if I break to the debugger and then restart, I get
exactly one underrun as you would expect, and then it recovers. What could
cause it to get into a state where it fails every other time around the
loop, and then sucks up milliseconds of CPU time before it gets going again,
thus guaranteeing another underrun?
--
Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com
More information about the Alsa-devel
mailing list