Sound

Sound

Introduction

MidnightBSD's GENERIC kernel includes support for common onboard HDA audio and USB audio devices. In most cases, speakers or a headset work without extra configuration. The system can expose several audio devices at once: for example, HDMI or DisplayPort outputs on a graphics card, an onboard codec, and a USB headset.

Use the following steps to identify the devices, select the output you want, and check its mixer settings. Run commands that change system configuration with doas or as root.

Checking audio devices

List sound devices detected during boot:

dmesg | grep pcm
cat /dev/sndstat

Each pcm entry is an audio device. In /dev/sndstat, play means it can produce sound, rec means it can record sound, and default marks the device selected for applications that do not choose one explicitly.

For example, a graphics card's HDMI outputs may appear before the onboard analog device. This is normal, but it can cause sound to be sent to an unused monitor output.

If no pcm device appears, inspect the boot messages for the audio controller:

dmesg | grep -E 'pcm|hdac|uaudio'

The sound(4) and snd_hda(4) manual pages list the supported audio framework and HDA hardware.

Selecting the default device

Set the default output temporarily by using its number from /dev/sndstat. For example, to select pcm2:

doas sysctl hw.snd.default_unit=2

Confirm the change with cat /dev/sndstat. To retain it after a reboot, add the following line to /etc/sysctl.conf:

hw.snd.default_unit=2

Use the number for your own intended device. Restart the affected application, mixer, or audio session after changing the default device.

Volume and recording controls

The base-system mixer command displays the available playback and recording controls:

mixer
mixer recsrc

Controls vary by hardware. Start by checking that the main volume, PCM volume, and the relevant microphone input are not muted or set to zero. mixer(8) documents changing a control and choosing a recording source.

After selecting an output and checking levels, test playback with a browser or a local media file. The mpv and vlc packages are available in mports:

doas mport install mpv
mpv /path/to/audio-file

USB audio, headsets, and HDMI

USB DACs, headsets, and docking stations normally appear as additional pcm devices when connected. Run cat /dev/sndstat after connecting the device, select its number with hw.snd.default_unit, then restart the application that should use it.

HDMI and DisplayPort audio are also separate devices. If a monitor has no speakers, choose the onboard or USB device instead. For calls, confirm that the chosen device has rec capability and that the microphone source is enabled in mixer.

Headphones and speakers

Some HDA codecs expose headphones and speakers as separate pcm devices. Others switch automatically. If automatic switching does not work, first identify the codec nodes from dmesg | grep pcm. A codec-specific configuration can be added to /boot/device.hints; for example:

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

These values are only an example for one Realtek codec. Do not copy them unchanged: the controller, codec address, and node IDs must match the output from your own system. Keep a backup of the file before editing it and reboot to test the change.

Optional desktop audio services

The base sound system is sufficient for many applications. mports also contains pulseaudio, its GTK mixer pavucontrol, and the PipeWire stack with its wireplumber session and policy manager:

doas mport install pulseaudio pavucontrol
doas mport install pipewire wireplumber

These services can provide per-application output selection and desktop mixer integration. Configure one audio-service stack at a time and follow its installed documentation; mixing PulseAudio and PipeWire setups without a plan can make device selection harder to diagnose. Bluetooth audio should likewise be configured through the selected desktop audio stack.

Troubleshooting

Further reading