Here is how I got things working in case anyone else want to know. It may save you some time.
The problem seemed to be that pulse audio was send sound to card 1 device 3 which produced no sound with sound-test command. I needed to switch it to card 1 device 7, which did produce sound with sound-test.
I added two lines to the file /etc/pulse/default.pa
load-module module-alsa-sink device=hw:1,7
set-default-sink output 2
The hw:1,7 corresponds to the "card 1" and "device 7" shown for the device in the output of the "aplay -l". This was the card and device that played sound from sound-test. Number for the default sink is the index of the device shown by "pacmd list-sinks"
I also had to turn off the device corresponding the hw:1,3 using pavucontrol.
Also helpful was the site PulseAudio/Examples, in particular the section on HDMI output configuration.
Thanks to the discussion with @Thomas I realised the proper therms (key words) are profile and card. In the terms of the question profiles are the inputs and outputs. The cards are the audio devices. And the sink numbers are not so important, but we need them.
We can find all available profiles for each card name by the command pacmd list-cards
or pactl list cards
that outputs the same information:
$ pactl list cards
Card #0
Name: alsa_card.pci-0000_00_1b.0
...
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
output:analog-surround-21: Analog Surround 2.1 Output (sinks: 1, sources: 0, priority: 800, available: yes)
...
Active Profile: output:iec958-stereo+input:analog-stereo
...
Card #1
Name: alsa_card.pci-0000_03_00.1
...
Profiles:
output:hdmi-stereo: Digital Stereo (HDMI) Output (sinks: 1, sources: 0, priority: 5400, available: yes)
output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (sinks: 1, sources: 0, priority: 5200, available: yes)
output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (sinks: 1, sources: 0, priority: 100, available: yes)
...
Active Profile: output:hdmi-stereo
...
A certain profile can be set by command with format as this:
pactl set-card-profile output:hdmi-stereo <card name|number> <profile name>
According to the question for the four mentioned outputs the commands are:
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo # LG ULTRAWIDE
pactl set-card-profile alsa_card.pci-0000_03_00.1 output:hdmi-stereo-extra1 # LG TV
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:iec958-stereo # Digital Output
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo # Headphones
As it is shown in this answer, when the new profile is set next things to do are:
pacmd set-default-sink <sink number of the target profile>
pacmd move-sink-input "$i" <sink number of the target profile>
# where $i is the index number of any active input: pacmd list-sink-inputs
According to my needs, described in the question, I've created the following script:
#!/bin/bash
# Name: /usr/local/bin/audioswitch
# Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4
CARD_1="pci-0000_03_00.1" ### HDMI Audio Controller of NVidia GTX 660
CARD_1_PROFILE_1="hdmi-stereo" # LG ULTRAWIDE
CARD_1_PROFILE_2="hdmi-stereo-extra1" # LG TV
CARD_0="pci-0000_00_1b.0" ### Built-in Audio
CARD_0_PROFILE_1="iec958-stereo" # Digital Output
CARD_0_PROFILE_2="analog-stereo" # Headphones
# Read the user's input
CHOICE="${@}"
choice() {
if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE
elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV
elif [ "$CHOICE" == 3 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_1" # Digital Output
elif [ "$CHOICE" == 4 ]; then CARD="$CARD_0"; PROF="$CARD_0_PROFILE_2" # Headphones
else
echo -e "\nYou should choice between:"
echo -e "\n\t[1] LG ULTRAWIDE\n\t[2] LG TV\n\t[3] Digital Output\n\t[4] Headphones\n"
echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again
fi
}; choice # call the function
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.${CARD}" "output:${PROF}";
# Set the default sink to the new one
pacmd set-default-sink "alsa_output.${CARD}.${PROF}" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk '{print $2}'); do
pacmd move-sink-input "$i" "alsa_output.${CARD}.${PROF}" &> /dev/null
done
The script is ready to be used with custom keyboard shortcuts, because it can handle the value (1
-4
) of the first positional parameter. When it is called without additional paraneter it will ask for your choice:
$ audioswitch
You should choice between:
[1] LG ULTRAWIDE
[2] LG TV
[3] Digital Output
[4] Headphones
Your choice: 1
Best Answer
I'm just experiencing similar audio problems, too.
I guess it is a problem, related to a recent update since it never happened before (1 to 2 weeks on Xubuntu 20.04 LTS) and will be fixed in a coming update. Until then, following command helped me to solve the problem for some hours without restart:
It takes 2 to 3 seconds for pulseaudio, which will restart automatically, and often the programs, doing audioo, will work again without further intervention; sometimes I have to restart the affected programs (browser, vlc).
At least I don't have to logout or restart the computer, as YT-Videos often suggest.
I hope this helps and a real update fix will be provided soon.