17

I wish to select a default sound card, or disable all others, in order to have the correct one selected after suspend.

2
  • How many sound cards do you have in the system?
    – Mitch
    Jun 14, 2012 at 15:26
  • 2, but 4 things show up in sound settings for output and 3 things for input.
    – MarkovCh1
    Jun 14, 2012 at 16:37

4 Answers 4

23

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

2
  • 6
    This should be the accepted answer.
    – skolind
    Mar 27, 2020 at 12:02
  • Sometimes the number in cat /proc/asound/cards get swapped after a reboot, how to deal with that?
    – bilogic
    Jan 3 at 11:34
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")

2
  • 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.
    – Tcll
    Nov 29, 2018 at 14:42
  • 1
    well, 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.
    – Tcll
    Dec 19, 2020 at 11:30
5

This is a way set default sound output card dynamically using PulseAudio (not ALSA).

  1. 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
    
  2. 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

3
  • 7
    pactl is for pulseaudio, not alsa
    – slang
    Jan 5, 2016 at 2:57
  • @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.dz
    Jan 5, 2016 at 6:15
  • 3
    Pulse is not a solution to doing something with ALSA. If they wanted to use pulse, they'd have asked about pulse.
    – monokrome
    Aug 8, 2020 at 3:56
-1

I personally use alsamixer

alsamixer

Hit F6 to select sound card.

enter image description here

4
  • 9
    F6 only lets you choose which card to modify sound levels for, no?
    – MarkovCh1
    Jun 15, 2012 at 0:22
  • 3
    Sets the selected card as default as well (at least it does for me).
    – Panther
    Jun 15, 2012 at 1:33
  • 5
    You can select card with alsamixer (F6 or S) and than do sudo alsactl store to save your settings as default. Dec 8, 2015 at 17:31
  • This is not working for me.
    – brandeded
    Dec 18, 2022 at 5:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .