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

From: Alban Hertroys <haramrae_at_gmail.com>
Date: Sun, 29 Sep 2024 10:09:24 UTC
Hello,

I am generally rather happy with this change in 14.1-RELEASE:

"Audio now supports asynchronous device detach. This greatly simplifies hot plugging and unplugging of things such as USB headsets, and eases use of PulseAudio in cases that require operating system sleep and wake (suspend and resume). d692c314d29a (Sponsored by The FreeBSD Foundation)"

It allows me to play music over my USB DAC through musicpd, without needing virtual-oss anymore, resulting in lower CPU load and potentially higher bit-rates (voss doesn’t go beyond 192kHz). Much appreciated.


It’s almost perfect now, BUT…

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

These do get set properly after booting the machine, but after I turn off my audio equipment (the DAC among them) and turn them back on the next day, I see:

#> sysctl -i dev.pcm.2.%desc dev.pcm.2.play.vchans dev.pcm.2.bitperfect 
dev.pcm.2.%desc: Topping D90SE
dev.pcm.2.play.vchans: 0
dev.pcm.2.bitperfect: 0 <--- Supposed to be 1!


Is there a way to persist those settings when re-attaching the device?


Frankly, I am a bit confused about why this apparently wasn’t a problem before (14.0-RELEASE with virtual-oss), perhaps I just never noticed and this isn’t a new problem with 14.1. I only started monitoring this setting relatively recently.


The periodic security run output reports the detach/attach sequence quite correctly (as far as I can tell) as:

+ugen0.6: <Topping D90SE> at usbus0 (disconnected)
+uaudio0: at uhub4, port 4, addr 8 (disconnected)
+pcm2: detached
+uaudio0: detached
+uhid3: at uhub4, port 4, addr 8 (disconnected)
+uhid3: detached
+ugen0.6: <Topping D90SE> at usbus0
+uaudio0 on uhub4
+uaudio0: <Topping D90SE, class 239/2, rev 2.00/1.88, addr 9> on usbus0
+uaudio0: Play[0]: 384000 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer. (selected)
+uaudio0: Play[0]: 352800 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 192000 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 176400 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 96000 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 88200 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 48000 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: Play[0]: 44100 Hz, 2 ch, 32-bit S-LE PCM format, 2x4ms buffer.
+uaudio0: No recording.
+uaudio0: No MIDI sequencer.
+pcm2 on uaudio0
+uaudio0: No HID volume keys found.
+uhid3 on uhub4
+uhid3: <Topping D90SE, class 239/2, rev 2.00/1.88, addr 9> on usbus0


Regards,
Alban Hertroys
--
There is always an exception to always.