Re: uaudio device re-attach and persisting dev.pcm.$pcm.bitperfect sysctl

From: Alban Hertroys <haramrae_at_gmail.com>
Date: Wed, 02 Oct 2024 20:11:57 UTC
> On 2 Oct 2024, at 13:24, Dag-Erling Smørgrav <des@freebsd.org> wrote:
> 
> Alban Hertroys <haramrae@gmail.com> writes:
>> I have a number of sysctl’s in /etc/sysctl.conf to tune my audio output:
>> 
>> hw.snd.default_unit=2
>> hw.snd.maxautovchans=0
>> dev.pcm.2.play.vchans=0
>> dev.pcm.2.bitperfect=1
> 
> This only works by accident because your DSP happens to be switched on
> and attached to pcm2 when sysctl.conf is processed during boot.  If you
> boot your machine with the DSP switched off or unplugged, you will see
> errors during boot because these sysctl nodes do not exist until the DSP
> is turned on and the driver attaches to it.  You need to set up devd to
> run the correct sysctl commands (with the correct device unit numbers,
> don't assume your DSP is always pcm2!) when your DSP is attached.

Those sysctl's happen to be what several posts on the FreeBSD forums advise for setting up USB DACs. That’s where I got my info when setting this up a while ago (during 13.1-RELEASE, I’d be a little hard-pressed to provide URL’s now). Just pointing out the trap there.

Meanwhile, several people here suggested that devd is the way to go about this. I had actually looked into that a bit, but that seemed to require a related device node in /dev, and there’s neither one for pcm nor for uaudio, so I discarded that as not being a viable option. Perhaps too soon.

I’ve been trying a bit, but I’m unfamiliar with devd.conf, so I got stuck at the point of:

notify 100 {
        match "system"          "USB";
        match "subsystem"       "DEVICE";
        match "type"            "ATTACH";
        match "vendor"          "0x152a";
        match "product"         "0x8750";
        action "PCM=`sysctl dev.pcm | grep 'Topping D90SE' | cut -d . -f 3` && sysctl 'hw.snd.default_unit=${PCM} dev.pcm.${PCM}.play.vchans=0 dev.pcm.$
};

I can see devd looking to match uaudio0 and pcm2 devices to several names it knows (probably from other devd confs?), but it doesn’t seem to match my attempt. Let alone that it got around to attempting to parse my sh tidbit.

Sysctl reports the device as:

dev.uaudio.0.%pnpinfo: vendor=0x152a product=0x8750 devclass=0xef devsubclass=0x02 devproto=0x01 sernum="" release=0x0188 mode=host intclass=0x01 intsubclass=0x01 intprotocol=0x20
dev.uaudio.0.%location: bus=0 hubaddr=5 port=4 devaddr=6 interface=0 ugen=ugen0.6dev.uaudio.0.%driver: uaudio
dev.uaudio.0.%desc: Topping D90SE, class 239/2, rev 2.00/1.88, addr 14
dev.uaudio.%parent: 

Corrections and improvements are welcome. How to use the actual device name from the event as a variable in grep instead of hard-coding it, for example.

Meanwhile, I have my hopes up for what Christos comes up with.

Regards,

Alban Hertroys
--
Als je de draak wilt steken met iemand,
dan helpt het,
als die een punthoofd heeft.