I wish to select a default sound card, or disable all others, in order to have the correct one selected after suspend.
4 Answers
Find your desired card with:
cat /proc/asound/cards
and then create /etc/asound.conf
with the following entries:
defaults.pcm.card 1
defaults.ctl.card 1
Replace 1
with number of your card determined above.
Source:
https://www.alsa-project.org/wiki/Setting_the_default_device
-
6
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: http://www.alsa-project.org/main/index.php/Asoundrc )
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"): https://alsa.opensrc.org/MultipleCards#How_to_choose_a_particular_order_for_multiple_installed_cards )
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 Audio
which 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")
-
never mind, this stopped working for me after the 3rd or 4th reboot (doesn't mean this won't continue to work for others), the default card was set appropriately, but still failed to output audio (I couldn't get it working again), so I fixed it by removing it (yes the card still works, it's not a hardware problem) after finding I could use my headphone out for my rear speakers, which has yet to give me a problem.– TcllNov 29, 2018 at 14:42
-
1well, after years of use, I can safely say this actually does work properly, though I still have no idea whatever caused it to stop working for that moment.– TcllDec 19, 2020 at 11:30
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 RUNNING
Set 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
-
6
-
@slang, thanks, you are correct, I put a note for that. However the OP has alsa in title, nothing in description and tagged for both. This give me an impression that the user was looking for a solution at any level. BTW, my self I want to know if there is a way using ALSA, this is an old question stayed unresolved for two years.– user.dzJan 5, 2016 at 6:15
-
3Pulse is not a solution to doing something with ALSA. If they wanted to use pulse, they'd have asked about pulse. Aug 8, 2020 at 3:56
I personally use alsamixer
alsamixer
Hit F6 to select sound card.
-
9
-
3
-
5You can select card with alsamixer (
F6
orS
) and than dosudo alsactl store
to save your settings as default. Dec 8, 2015 at 17:31 -