Skip to content

Instantly share code, notes, and snippets.

@smortex
Created November 12, 2022 00:12
Show Gist options
  • Save smortex/d4f2385ae3e404381f636322f241e6ae to your computer and use it in GitHub Desktop.
Save smortex/d4f2385ae3e404381f636322f241e6ae to your computer and use it in GitHub Desktop.
freebsd-devd-pulseaudio
#!/bin/sh
# /usr/local/bin/pulseaudio-pcm
set -x
/usr/bin/logger "$0 $*"
action=$1
case $action in
attach)
pcm=$2 dsp=dsp${2#pcm} uaudio=$3
/usr/local/bin/sudo -u romain /usr/local/bin/pacmd load-module module-oss device=/dev/$dsp
ugen=$(devinfo -v | awk '$1 == "'$uaudio'" { split($NF, r, "="); print r[2] }')
echo $dsp > /tmp/uaudio-$ugen
;;
detach)
ugen=$2
if [ -f "/tmp/uaudio-$ugen" ]; then
dsp=$(cat /tmp/uaudio-$ugen)
i=$(/usr/local/bin/sudo -u romain /usr/local/bin/pacmd list-modules | /usr/bin/awk '$1 == "index:" { last_index = $2 } $1 == "argument:" && $2 == "<device=/dev/'$dsp'>" { i = last_index } END { print i }')
/usr/local/bin/sudo -u romain /usr/local/bin/pacmd unload-module $i && rm -f "/tmp/uaudio-$ugen"
fi
;;
esac
# /usr/local/etc/devd/uaudio.conf
attach 10 {
device-name "pcm[0-9]+";
action "/usr/local/bin/pulseaudio-pcm attach $device-name $bus";
};
notify 10 {
match "system" "USB";
match "subsystem" "DEVICE";
match "type" "DETACH";
match "ugen" "ugen[0-9]+.[0-9]+";
action "/usr/local/bin/pulseaudio-pcm detach $ugen";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment