User Tools

Site Tools


persistent_sound_interface

This is an old revision of the document!


Persistent Sound Interfaces in Linux

If you've got several sound interfaces in Linux it can be useful to give them persistent names. I'm using identical sound interfaces which don't have a unique identifier of any description, so instead I can assign them names depending on which USB port they're plugged into. Note, for the sound interface to retain the same name it must always be plugged into the same port.

This has been tested on Debian, may work for others.

Sound Card Names

Source: https://gist.github.com/Aishou/f39c2f970c6db20e1845925c5cc0890e

With your USB Sound Card unplugged, run the following:

udevadm monitor --subsystem=sound

Plug the card in and you'll see something like:

KERNEL[2359.362661] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5 (sound)
KERNEL[2359.362888] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/pcmC5D0p (sound)
KERNEL[2359.363027] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/pcmC5D0c (sound)
KERNEL[2359.363450] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/dsp5 (sound)
KERNEL[2359.363580] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/audio5 (sound)
KERNEL[2359.363722] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/controlC5 (sound)
UDEV  [2359.502712] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5 (sound)
UDEV  [2359.509638] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/pcmC5D0p (sound)
UDEV  [2359.519518] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/audio5 (sound)
UDEV  [2359.519747] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/pcmC5D0c (sound)
UDEV  [2359.520593] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/dsp5 (sound)
KERNEL[2359.536869] change   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5 (sound)
UDEV  [2359.576643] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5/controlC5 (sound)
UDEV  [2359.776741] change   /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5 (sound)

For the example above the bit we're interested in is:

/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card5

Edit /etc/udev/rules.d/95-static-soundcard-name.rules and add the path to your soundcard. Drop the final digit and replace it with a question mark:

SUBSYSTEM!="sound", GOTO="alsa_naming_end"
ACTION!="add", GOTO="alsa_naming_end"
DEVPATH=="/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/sound/card?", ATTR{id}="MyCard1"
LABEL="alsa_naming_end"

The next time you plug it in, ALSA will refer to it as CARD=MyCard1,DEV=0

HID Device Names

Some sounds cards expose a HID interface that's used for triggering the PTT. We can give it the same treatment so it has a persistent name associated with the USB Port.

With your USB Sound Card unplugged, run the following:

udevadm monitor --subsystem=hid

Plug the card in and you'll see something like:

KERNEL[1274.954368] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:0D8C:0012.0005 (hid)
KERNEL[1275.020621] bind     /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:0D8C:0012.0005 (hid)
UDEV  [1275.066325] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:0D8C:0012.0005 (hid)
UDEV  [1275.325542] bind     /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/0003:0D8C:0012.0005 (hid)

Edit /etc/udev/rules.d/94-static-hid-name.rules

persistent_sound_interface.1686433917.txt.gz · Last modified: 2023/06/10 21:51 by 2e0sip