0

I'm experiencing an issue that when ALSA gives an XRUN underrun, the pulseaudio virtual sinks for the output that i've set start changing. Description below:

I've created three virtual sinks using the following commands (from Virtual0 to Virtual2)

pacmd load-module module-null-sink sink_name=Virtual0
pacmd update-sink-proplist Virtual0 device.description=Virtual0
pacmd update-source-proplist Virtual0.monitor device.description=Virtual0

I'm then running some DSP commands which output into three aplay commands (aplay -v -r 48000 -f S16_LE). Then in pavucontrol I set each of those to a seperate virtual sink (Virtual0 - Virtual2), which I then use to pipe to another DSP program.

The problem is that whenever ALSA underruns due to high CPU usage, the source entry in pavucontrol will briefly dissappear, then come back a second or two later with the virtual sink changed to the last one that i've set in the pavucontrol GUI (usually Virtual2). So after a few underruns on each alsa instance all sources end up outputting to the Virtual2 sink.

I don't mind ALSA underruning every now and then (underruns only occur rarely when the CPU fully maxes out - this is a Raspberry Pi), but I just want the sources to restore to the same sink.

I think the problem is that each aplay source has the same name. So when one briefly disappears due to an underrun it goes to the last set sink for that name, which happens to be the last one set in the GUI.

Is there anything I can do to stop the source entry briefly dissappearing on an underrun? Or change the aplay source name to something unique?

Just a note: Interestingly, i've also tried outputting with mplayer, and this never glitches the source in pavucontrol, but unforuntately mplayer introduces an unacceptable latency on the audio (even with caching disabled), so it can't be used. aplay and play (from sox) both have the issue.

Before Underruns Before Underruns

After Underruns After Underruns

0

If anyone comes across a similar issue, I eventually found the solution. You need to create some virtual cards that have the device set in asound.conf, then output the audio to those cards.

sudo nano /etc/asound.conf

Paste into asound.conf.

pcm.VirtualCard0 {
        type pulse
        device Virtual0
}

ctl.VirtualCard0 {
        type pulse
        device Virtual0
}

pcm.VirtualCard1 {
        type pulse
        device Virtual1
}

ctl.VirtualCard1 {
        type pulse
        device Virtual1
}

pcm.VirtualCard2 {
        type pulse
        device Virtual2
}

ctl.VirtualCard2 {
        type pulse
        device Virtual2
}

Then run the output with

aplay -v -r 48000 -f S16_LE -DVirtualCard0
aplay -v -r 48000 -f S16_LE -DVirtualCard1
aplay -v -r 48000 -f S16_LE -DVirtualCard2

Now whenever the device 'dissappears' briefly from pulseaudio on an underrun, it will at least come back to the correct sink.

Make sure you create the Virtual sinks first like I described in the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.