ALSA-Pulseaudio (snd_pcm_recover) underrun occurred (Linux)
Brought to you by:
sobukus
Using alsa over pulseaudio leads to following errors and overjumped sound pieces:
mpg123-alsa -v audio.mp3 High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3 version 1.25.10; written and copyright by Michael Hipp and others free software (LGPL) without any warranty but with best wishes Decoder: x86-64 (AVX) Trying output module: alsa, device: <nil> Terminal control enabled, press 'h' for listing of keys and functions. Playing MPEG stream 1 of 1: audio.mp3 ... MPEG 1.0 L III vbr 48000 mono Title: Title Artist: Artist > 0000+9526 00:00.00+03:48.58 --- 100=100 32 kb/s 96 B acc 0 clip p+0.000 ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred …
Same happens with versions 1.25.10 and 1.25.13 of mpg123.
I can safely use mpg123-pulse and everything works well, but the default mpg123 (at least from Ubuntu 18.04) uses ALSA and it should in principle work with pulseaudio-alsa, too.
This doesn't happen e.g. with Audacity which uses pulseaudio-alsa, too.
Please let me know if I can help with any further information!
See the end of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=930088 for my take on this long-standing issue. Does current https://mpg123.org/snapshot fix it for you?
Of course, I'm open to a way to properly detect if pulse is running and use that by default instead of alsa. Currently, trying pulse first would attempt to start a server if none is there IMHO, which might not be what the user wants.
Thanks for the fix! It seems to work well now (tried with 1.26rc3). For curiosity: How did you implement it?
Quoting myself from he debian report:
I just had some reproducable playback trouble on a Ubuntu 18.04 box and
mpg123 -o alsa as opposed to mpg123 -o pulse: A brief period of static
noise and reported ALSA underruns on loading a new track. This hints at
some performance/timing issue that at least triggers this. I fixed it
in current mpg123 trunk by delaying device activation based on the
ringbuffer fill.
We used to have this in src/libout123/modules/alsa.c for a long time
(so, also in current Debian):
This starts the audio device as soon as the first block of audio is
there. Strangely, this seems to work fine for real hardware or ALSA's
dmix stuff (where I'd expect the real trouble), but fails when being
decoupled via pulse. I changed that now to
and this seems to work fine in my tests. Maybe someone can confirm with
a build from the current https://mpg123.org/snapshot, or just this
little change applied to the debian package?
Interestingly enough, just not setting this value (relying on a
sensible default) does not help. The default doesn't seem to be
sensible.