I wish to select a default sound card, or disable all others, in order to have the correct one selected after suspend.
24 Answers
Find your desired card with:
cat /proc/asound/cardsand then create /etc/asound.conf with the following entries:
defaults.pcm.card 1
defaults.ctl.card 1Replace 1 with number of your card determined above.
Source:
This is a way set default sound output card dynamically using PulseAudio (not ALSA).
Check list of Sources and Sinks
$ pactl list short sources 0 alsa_output.pci-0000_00_1b.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED 1 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED 2 combined.monitor module-combine-sink.c s16le 2ch 44100Hz SUSPENDED $ pactl list short sinks 0 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING 1 combined module-combine-sink.c s16le 2ch 44100Hz IDLE 2 alsa_output.pci-0000_01_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNINGSet defaults:
$ pactl set-default-source alsa_input.pci-0000_00_1b.0.analog-stereo $ pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
It is possible even to set ports too. See How to switch sound output with key shortcut
Reference: man pactl
Seeing as I don't have Pulse, the accepted answer isn't valid for others like me.
This should provide a decent solution here that works off of ALSA alone.
I have a bit of detail since I have 3 devices (onboard 2-channel, video card HDMI, PCI 5.1-channel) in my machine, with my preferred device being last.
what worked for me was editing /etc/asound.conf with the following:
(resource: )
pcm.!default { type hw card 0
}
ctl.!default { type hw card 0
}If I would've intuitively set my default device as 2, the order of the above devices would've flipped to this after restarting:
0: [CMI8738 ]
1: [Nvidia ]
2: [Nvidia_1 ]with the default device being 2.
(this would continue after every reboot, and no restarting alsa did not make apps play audio)
To stop my machine from trolling me, I had to edit /etc/modprobe.d/alsa-base.conf and add the following line:
(resource (search for the 6th occurrence of "order"): )
options snd slots=snd-cmipci,which forced my preferred device at 0 so the default card would match:
Hopefully I'll never have to touch these settings again, and it'll help others like me who don't want to deal with PulseAudio dropping audio streams.
(yes this means poorly developed apps like Discord and Firefox won't identify your audio devices without Pulse)
EDIT: just to update now that I've had trouble with this issue...
if you have multiple devices sharing the same driver, the solution here is quite dirty:
options snd-hda-intel index=1,0 vid=0x####,0x#### pid=0x####,0x####for some reason, ordering the index inversely orders the devices properly for me...
if you'd like other device drivers ordered before or after this, you can combine this with:
options snd slots=snd-cmipci,snd-hda-intel,to obtain the vid/pid info, you use the command:
lspci -nn | grep Audiowhich should list your audio devices for you with the ids in [vid:pid] at the end of each line.
(use caution if your audio device name doesn't contain "Audio")
I personally use alsamixer
alsamixerHit F6 to select sound card.