get uaudio pcm/mixer device name using devd
- Reply: Mazin Fadl : "Re: get uaudio pcm/mixer device name using devd"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 03 May 2022 19:36:25 UTC
Hi all,
Using devd, is it possible to pass through to an action the pcm/mixer
device name created when a usb audio device is attached?
My objective is to set the default sound device to a specific usb audio
device, which can't be hardcoded via sysctl 'hw.snd.default_unit' due to
device order switching with multiple usb audio devices.
I have a working configuration using the following devd.conf:
notify 100 {
match "system" "USB";
match "subsystem" "INTERFACE";
match "type" "ATTACH";
match "vendor" "0x040d";
match "product" "0x340b";
action "/etc/set_usb_audio.sh";
};
and in set_usb_audio.sh:
#!/bin/sh
# get our preferred mixer
cardnumber=$(mixer -a | grep -F 'snd_uaudio (play)' | grep -o '[[:digit:]]\+')
if [ -n "$cardnumber" ]; then
logger set_usb_audio.sh: found usb audio playback on dsp$cardnumber
# set default audio card
mixer -d "$cardnumber" >/dev/null
# unmute our FX-AUDIO dac
mixer -f /dev/mixer"$cardnumber" pcm2=1 >/dev/null
fi
mixer -a doesn't print the usb product names for my devices, its output
is generic, like:
pcm12:mixer: <USB audio> at ? kld snd_uaudio (play)
...
pcm13:mixer: <USB audio> at ? kld snd_uaudio (rec)
which makes my current matching method broad, hence the question about
passing through the pcm/mixer device name variable from devd.
Thanks,
mazin