From 629699ff9b2e73c92bafe45280515d816fbcaaf5 Mon Sep 17 00:00:00 2001 From: Simon Long Date: Mon, 20 Jan 2020 11:40:07 +0000 Subject: [PATCH] Add audio switching for discrete internal ALSA devices --- debian/changelog | 6 ++++ raspi-config | 75 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8b7aad1..b0a1232 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +raspi-config (20200120) buster; urgency=medium + + * Add audio switching for discrete internal ALSA devices + + -- Simon Long Mon, 20 Jan 2020 11:38:37 +0000 + raspi-config (20200117) buster; urgency=medium * Add proxy configuration diff --git a/raspi-config b/raspi-config index 40d31b4..2a53bff 100755 --- a/raspi-config +++ b/raspi-config @@ -1573,17 +1573,72 @@ do_update() { } do_audio() { - 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) + 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 - AUDIO_OUT=$1 - fi - if [ $? -eq 0 ]; then - amixer cset numid=3 "$AUDIO_OUT" + ASPATH=$(getent passwd $USER | cut -d : -f 6)/.asoundrc + if [ "$INTERACTIVE" = True ]; then + CARD0=$(aplay -l | grep bcm2835 | grep "card 0" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-) + CARD1=$(aplay -l | grep bcm2835 | grep "card 1" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-) + CARD2=$(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 { + type plug + slave.pcm "output" + } + capture.pcm { + type plug + slave.pcm "input" + } +} + +pcm.output { + type hw + card $AUDIO_OUT +} + +ctl.!default { + type hw + card $AUDIO_OUT +} +EOF + fi fi }