site  contact  subhomenews

Pulseaudio MSCW change default sink fix

November 19, 2021 — BarryK

As I have reported recently the Multiple Sound Card Wizard is ALSA-centric, with bluez-alsa support bolted on last year, and a first attempt to bolt on pulseaudio support. Now, attempting to improve the pulseaudio support.

The code is still based on setting the default sound card in /etc/asound.conf, though that might turn out to be limiting.

A problem arose when the guys who are testing Easy 3.1.10 plugged in a USB sound "card", and then were unable to get MSCW to change the default back to the internal PCI sound card. Discussion here:

https://forum.puppylinux.com/viewtopic.php?p=41901#p41901

Due to my limited understanding, I thought that the pulseaudio daemon would read /etc/asound.conf when it starts, but, it seems that it doesn't.

The pa daemon has to be told separately what is the default card. Furthermore, and I find this odd, there doesn't seem to be a mapping from the ALSA card and device numbers to the pa sinks. I figured out how to do it though.

Here is code inserted into /usr/sbin/mscw:

   #20211118 need to change pa default...
#simple cases, 1+ pci and 1 usb card...
DEFname=''
DEFUSB="$(echo -n "$SELECTED" | grep -o 'USB')"
if [ "$DEFUSB" ];then
DEFname="$(pactl list short sinks | tr '\t' ' ' | tr -s ' ' | grep 'alsa_output\.usb' | cut -f 2 -d ' ' | head -n 1)"
else
DEFcard="$(grep '^defaults\.pcm\.card' /etc/asound.conf | cut -f 2 -d ' ')"
if [ "$DEFcard" ];then
DEFpci="$(readlink /sys/class/sound/card${DEFcard} | rev | cut -f 3 -d '/' | rev)" #ex: 0000:00:1f.3
if [ "$DEFpci" ];then
DEFpcimod="$(echo -n "$DEFpci" | tr ':' '_')"
DEFname="$(pactl list short sinks | tr '\t' ' ' | tr -s ' ' | grep "alsa_output\.pci-${DEFpcimod}\." | cut -f 2 -d ' ' | head -n 1)"
fi
if [ ! "$DEFname" ];then #precaution...
DEFname="$(pactl list short sinks | tr '\t' ' ' | tr -s ' ' | grep 'alsa_output\.pci' | cut -f 2 -d ' ' | head -n 1)"
fi
fi
fi
if [ "$DEFname" ];then
pactl set-default-sink ${DEFname}
#to make it permanent:
sed -i '/^set-default-sink/d' /etc/pulse/default.pa
echo "set-default-sink ${DEFname}" >> /etc/pulse/default.pa

fi
#note, to verify pa default, "*" prefixed:
## pacmd list-sinks | grep -e 'name:' -e 'index:'

Ha ha, I really am a newbie with pa! It seems that "pactl set-default-sink ${DEFname}" might not be remembered after a reboot. Hmm, this link says to put "set-default-sink ${DEFname}" into /etc/pulse/default.pa:

https://askubuntu.com/questions/980991/pulseaudio-does-not-remember-default-sink

OK, have inserted the red code shown above.   

Tags: easy