Skip to content
Lucas Holt edited this page Aug 1, 2023 · 2 revisions

MidnightBSD includes the sound module in the GENERIC kernel. Typically, you do not need to load the sound kernel modules unless you built a customer kernel without sound. (if sound, kldload sound or kldload snd_hda often works)

Checking for audio devices

Run the dmesg command and look for pcm and hdac devices. They could be included on your motherboard, sound card, or even your graphics card.

You can change the default device by running the following command:

 sysctl hw.snd.default_unit=n

Replace n with the device you want to use from the dmesg output. (0,1,2,3,4, etc) You can then add hw.snd.default_unit=n to /etc/sysctl.conf to make it persist across reboots.

Finally, you can check the configuration

cat /dev/sndstat
Installed devices:
pcm0: <NVIDIA (0x0081) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x0081) (HDMI/DP 8ch)> (play)
pcm2: <Realtek ALC897 (Rear Analog 5.1/2.0)> (play/rec) default
pcm3: <Realtek ALC897 (Front Analog)> (play/rec)
pcm4: <Realtek ALC897 (Rear Digital)> (play)
pcm5: <Intel (0x2816) (HDMI/DP 8ch)> (play)
No devices installed from userspace.

Switching between headphones and regular speakers

(this example from the FreeBSD audio guide https://freebsdfoundation.org/freebsd-project/resourcesold/audio-on-freebsd/)

You can add devices from dmesg output in /boot/device.hints to configure the priority order for audio devices.

For example,

dmesg | grep pcm
pcm0: <Realtek ALC892 Analog> at nid 23 and 26 on hdaa0
pcm1: <Realtek ALC892 Right Analog Headphones> at nid 22 on hdaa0

In device.hints,

hint.hdac.0.cad0.nid22.config="as=1 seq=15 device=Headphones" 
hint.hdac.0.cad0.nid26.config="as=2 seq=0 device=speakers"