The easiest solution is to overwrite the id attribute based on the USB path.
It seems that the simple solution is to place this in /etc/udev/rules.d/99-myrules.conf:
SUBSYSTEM=="sound",KERNELS=="1-1.4.4:1.0",ATTR{id}="CODEC_7300" SUBSYSTEM=="sound",KERNELS=="1-1.3.4:1.0",ATTR{id}="CODEC_9700"
Take the KERNELS from udevadm info -ap /sys/class/sound/controlC2, where 2 is the index of the audio card.
Good questions and answers on these other threads:
This solves it for programs with a dropdown that exposes the ID.
While this doesn't set a consistent ALSA sound card number, it does make it obvious which is which, from aplay -l:
**** List of PLAYBACK Hardware Devices **** [...] card 2: CODEC_7300 [USB Audio CODEC], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0 card 3: CODEC_9700 [USB Audio CODEC], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
To get consistent ALSA numbering you can create a set of symlinks. E.g.
KERNEL=="controlC[0-9]*", DRIVERS=="usb", PROGRAM="/usr/bin/alsa_name.sh %k", SYMLINK+="%c" KERNEL=="hwC[D0-9]*", DRIVERS=="usb", PROGRAM="/usr/bin/alsa_name.sh %k", SYMLINK+="%c" KERNEL=="midiC[D0-9]*", DRIVERS=="usb", PROGRAM="/usr/bin/alsa_name.sh %k", SYMLINK+="%c" KERNEL=="pcmC[D0-9cp]*", DRIVERS=="usb", PROGRAM="/usr/bin/alsa_name.sh %k", SYMLINK+="%c"
And have a script that checks the path and returns a suitable name. E.g.
#!/bin/bash NAME="$1" if echo "$DEVPATH" | grep 1-1.4; then NAME="$(echo "$NAME" | sed -r 's/(.*)C([0-9]+)(.*)/\1C11\3/')" fi if echo "$DEVPATH" | grep 1-1.3; then NAME="$(echo "$NAME" | sed -r 's/(.*)C([0-9]+)(.*)/\1C12\3/')" fi exec echo "snd/$NAME"
You can then create a consistent PulseAudio device like so:
N=2N=11 DEV="radio-7300" pacmd load-module module-alsa-card \ device_id="${N}" name="${DEV}" \ card_name="alsa_card.platform-${DEV}_audio" \ namereg_fail=false tsched=no fixed_latency_range=no \ ignore_dB=no deferred_volume=yes use_ucm=yes \ card_properties="module-udev-detect.discovered=1" pacmd suspend-sink alsa_output.${DEV}.analog-stereo no pacmd suspend-source alsa_input.${DEV}.analog-stereo no