User Tools

Site Tools


persistent_sound_interface

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}="USBSND1"
LABEL="alsa_naming_end"

Your Sound Interface should now be available as CARD=USBSND1,DEV=0 next time its plugged in or the system is restarted.

Note you can repeat the process for additional sound interfaces, just add the additional lines above the alsa_naming_end label.

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)

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

/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/

Edit /etc/udev/rules.d/94-static-hid-name.rules and add rules to create symlinks for the HID device. Update the DEVPATH to match your own system. Note the * is used as a wildcard:

SUBSYSTEM=="hidraw", DEVPATH=="/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.3/*", SYMLINK+="USBPTT1"

Your HID device should now be available as /dev/USBPTT1 next time its plugged in or the system is restarted.

Note you can repeat the process for additional HID Devices, just add them to the existing rules file.

Transceiver Device Names

If your radio can be controlled and provide audio through a USB ↔ USB connection, you may find that turning the radio off and on results in the Linux device names changing from ttyUSB0 & ttyUSB1 to ttyUSB1 & ttyUSB2, which means either restarting the PC, or changing the software to use the new device names.

First, check for the Vendor and Product id's by running lsusb. In the screenshot below, the Icom IC-7100 shows as “Silicon Labs CP210x UART Bridge” for two different devices. They both show the same Vendor (10c4) and Product (ea60) id's, so that can't be used to separate them.

Next, check the device serial numbers, changing ttyUSB1 and ttyUSB2 in the example below to match your current device names.

In the example, both the USB devices that are provided by the radio have different Serial Numbers, making it easy to separate them and assign individual, static names.

Edit /etc/udev/rules.d/99-static-radio-name.rules and add rules to create symlinks for the devices:

KERNEL=="ttyUSB*", ATTRS{serial}=="IC-7100 03008872 A", SYMLINK+="icom7100-a" 
KERNEL=="ttyUSB*", ATTRS{serial}=="IC-7100 03008872 B", SYMLINK+="icom7100-b"

You can then use /dev/icom7100-a instead of /dev/ttyUSB0 when configuring programs.

persistent_sound_interface.txt · Last modified: 2023/07/05 17:47 by mi7emg