You are not logged in.

#1 2023-01-13 09:48:47

Onyros
Member
From: Lisbon, Portugal
Registered: 2007-10-11
Posts: 307

[SOLVED] Can't set default ALSA device - Card order changes every boot

This particular one is driving me insane, so any help will be GREATLY appreciated.

I've always used ALSA on all my systems and never ran into this kind of issue before, it's really leaving me scratching my head and clawing at the walls.

I have new hardware and am not able to set my default device card, as the sound device order changes on every boot.

On this specific boot, for instance, here's the random order of devices I got:

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /proc/asound/cards
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │  0 [HDMI           ]: HDA-Intel - HDA ATI HDMI
   2   │                       HDA ATI HDMI at 0xfcc20000 irq 77
   3   │  1 [C920           ]: USB-Audio - HD Pro Webcam C920
   4   │                       HD Pro Webcam C920 at usb-0000:07:00.3-1, high speed
   5   │  2 [Generic_1      ]: HDA-Intel - HD-Audio Generic
   6   │                       HD-Audio Generic at 0xfc748000 irq 79
   7   │  3 [Generic        ]: HDA-Intel - HD-Audio Generic
   8   │                       HD-Audio Generic at 0xfc740000 irq 80
   9   │  4 [Device         ]: USB-Audio - USB Audio Device
  10   │                       C-Media Electronics Inc. USB Audio Device at usb-0000:07:00.3-4, full speed
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────

Here's the accompanying modules list:

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /proc/asound/modules
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │  0 snd_hda_intel
   2   │  1 snd_usb_audio
   3   │  2 snd_hda_intel
   4   │  3 snd_hda_intel
   5   │  4 snd_usb_audio
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────

This probably hints at the first mild complication.

I need my default audio device to be USB-Audio with id=Device there on the list. It could've been a somewhat straightforward setup, by defining the device order by creating the following file, as per the Wiki instructions on how to configure the index order via kernel module options :

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /etc/modprobe.d/alsa-base.conf
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ options snd_usb_audio id=Device index=0
   2   │ options snd_usb_audio id=C920 index=1
   3   │ options snd_hda_intel id=HDMI index=2
   4   │ options snd_hda_intel id=Generic index=3
   5   │ options snd_hda_intel id=Generic1 index=4
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────

I even thought the first two lines alone should suffice, as I was defining the default by having snd_usb_audio first, and the right device id order anyway.

But nope. Upon my next boot, my snd_usb_audio device with id=Device not only is not the default audio device in ALSA, but the IDs for all snd_hda_intel devices have also changed, and a random one was assigned as default.

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /proc/asound/cards
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │  0 [Generic_1      ]: HDA-Intel - HD-Audio Generic
   2   │                       HD-Audio Generic at 0xfc748000 irq 79
   3   │  1 [C920           ]: USB-Audio - HD Pro Webcam C920
   4   │                       HD Pro Webcam C920 at usb-0000:07:00.3-1, high speed
   5   │  2 [Generic        ]: HDA-Intel - HD-Audio Generic
   6   │                       HD-Audio Generic at 0xfc740000 irq 80
   7   │  3 [Device         ]: USB-Audio - USB Audio Device
   8   │                       C-Media Electronics Inc. USB Audio Device at usb-0000:07:00.3-4, full speed
   9   │  4 [Generic1       ]: HDA-Intel - HDA ATI HDMI
  10   │                       HDA ATI HDMI at 0xfcc20000 irq 77
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────

Notice how device formerly ID=HDMI now is ID=Generic1. Also notice that even though I explicitly made snd_usb_audio device id=Device index=0 it jumped to index=3

This one's beyond me, now. I've tried several things. I tried index -2 on snd_hda_intel devices so they'd never be default. I've tried the alternative method but as the index order changes on every boot, card index number as displayed with aplay -l also changes on every boot... so, no dice.

Am I missing anything really, really simple here? I want to keep on using ALSA: setting it and forgetting it as I've done for the previous... 15 years? Not really keen on using Pipewire or whatever the cool kids are using these days.

Last edited by Onyros (2023-01-13 23:38:00)

Offline

#2 2023-01-13 10:16:11

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 18,288

Re: [SOLVED] Can't set default ALSA device - Card order changes every boot

Your main problem is that snd-hda-intel does indeed not have any tooling to properly guarantee a specific default device and the id parameter is not actually there for identification purposes of a specific device but for naming one. Your second problem will be that defining the options like you are doing here will always logically override the ones specified earlier since the expectation for the params is an array..  Luckily if you do care about the usb devices, these do actually have a parameter to identify and guarantee one specific card gets the correct index.

So your correct definition would be

options snd_usb_audio vid=$VIDOFMAIN$,$VIDOFWEBCAM$ pid=$PIDOFMAIN$,$PIDOFWEBCAM$ index=-1,-2
options snd_hda_intel index=-2,-2

You can find the relevant vids and pids checking lsusb from usbutils and then replace the $placeholder$ with the correct id.The rest needs to be as mentioned, including the commas (... unless you wanted to be more fine grained here with which exact ordering is going where, but i'd still reccommend "negative" indices since those will not lead to loading failure should the index not be available for any reason, you can control that by going to the "next lower" index, e.g. -2 will ensure the module never gets device 0 but anything above is fair game, -3 for device 1 and so forth).

FWIW If you wanted to do this with ALSA configuration you should rather do https://wiki.archlinux.org/title/Advanc … aults_node but with the string identifier logic mentioned in the linked section you see in asound cards, so:

defaults.pcm.!card "Device"; # The override operation mode is necessary here, because of
defaults.ctl.!card "Device"; # different value types.

Last edited by V1del (2023-01-13 10:33:43)

Offline

#3 2023-01-13 23:37:34

Onyros
Member
From: Lisbon, Portugal
Registered: 2007-10-11
Posts: 307

Re: [SOLVED] Can't set default ALSA device - Card order changes every boot

V1del, thank you, so, so much. The one piece I was missing was defining the default device in my .asoundrc with the right identifier -- but I could only get the device strings sorted and with non-changing IDs by also having them defined in my alsa-base.conf file -- otherwise the device nomenclature would randomly change at boot: USB "Device" would change to "Device_1" if USB device "C920" was indexed before thus changing its name to "Device" which changed "Device" to "Device_1". (Hope that made sense, even I am a little confused.)

I really can't thank you enough! Let me know how I can pay you a beer, or whatever floats your boat!

Marking this as solved, hope it helps out people going through the same ALSA shenanigans.

Offline

#4 2023-01-19 18:21:59

Grant
Member
From: Italy
Registered: 2012-12-15
Posts: 237

Re: [SOLVED] Can't set default ALSA device - Card order changes every boot

As a side note, you may find asoundconf useful to readily set up your sound card system. It's got a GTK GUI as well.

Last edited by Grant (2023-01-19 18:22:10)

Offline

#5 2023-01-19 19:16:22

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 18,288

Re: [SOLVED] Can't set default ALSA device - Card order changes every boot

Not really, asoundconf has a tendency to break by doing overly verbose configuration which can conflict with alsa-lib defaults and it would not have been able to do anything about the peculiarities that have been present here (duplicated device names, unstable index ordering are out of scope for it).

Offline

Board footer

Powered by FluxBB