Add PulseAudio sink control to audio select option

This commit is contained in:
Simon Long 2020-10-12 14:48:37 +01:00
parent 78a0a8b916
commit 1a4671f109

View File

@ -1871,49 +1871,66 @@ do_update() {
}
do_audio() {
if aplay -l | grep -q "bcm2835 ALSA"; then
if is_pulseaudio ; then
if [ "$INTERACTIVE" = True ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "Auto" \
"1" "Force 3.5mm ('headphone') jack" \
"2" "Force HDMI" \
3>&1 1>&2 2>&3)
else
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
amixer cset numid=3 "$AUDIO_OUT"
fi
else
ASPATH=$(getent passwd $USER | cut -d : -f 6)/.asoundrc
if [ "$INTERACTIVE" = True ]; then
CARD0=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 0" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD1=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 1" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD2=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 2" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
if ! [ -z "$CARD2" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
"2" "$CARD2" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD1" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD0" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
3>&1 1>&2 2>&3)
oIFS="$IFS"
IFS="/"
list=$(sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pacmd list-sinks | grep -e index -e alsa.name | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'index: '//g | sed s/'alsa.name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/')
if ! [ -z "$list" ] ; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3)
else
whiptail --msgbox "No internal audio devices found" 20 60 1
false
return 1
fi
IFS=$oIFS
else
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
cat << EOF > $ASPATH
sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-sink $AUDIO_OUT
else
if aplay -l | grep -q "bcm2835 ALSA"; then
if [ "$INTERACTIVE" = True ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "Auto" \
"1" "Force 3.5mm ('headphone') jack" \
"2" "Force HDMI" \
3>&1 1>&2 2>&3)
else
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
amixer cset numid=3 "$AUDIO_OUT"
fi
else
ASPATH=$(getent passwd $USER | cut -d : -f 6)/.asoundrc
if [ "$INTERACTIVE" = True ]; then
CARD0=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 0" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD1=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 1" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD2=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 2" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
if ! [ -z "$CARD2" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
"2" "$CARD2" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD1" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD0" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
3>&1 1>&2 2>&3)
else
whiptail --msgbox "No internal audio devices found" 20 60 1
false
fi
else
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
cat << EOF > $ASPATH
pcm.!default {
type asym
playback.pcm {
@ -1936,6 +1953,7 @@ ctl.!default {
card $AUDIO_OUT
}
EOF
fi
fi
fi
}