> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-11-multimedia-and-external-devices/di-11.1-jie-sheng-ka.md).

# 11.1 Sound Cards

FreeBSD automatically detects the sound card used by the system by default.

The FreeBSD kernel supports Intel HDA specification sound cards through the snd\_hda module. This section explains sound device detection and volume control methods. Looking back at its development history, FreeBSD's sound support began in 1993, when Jordan K. Hubbard ported the generic Linux sound card driver to FreeBSD, which later became known as the VoxWare sound card driver. In 1997, Luigi Rizzo built the foundation of the modern FreeBSD sound system. In 1999, Cameron Grant rewrote the sound card system for FreeBSD 4.0, using the newbus interface to support a large number of hardware devices. In 2005, Ariff Abdullah took over the maintenance of the FreeBSD sound code, after which sound support underwent significant changes and multiple device driver restructurings.

FreeBSD's sound API is called OSS, which stands for "Open Sound System." It was once the default sound API for Linux, but was later replaced by ALSA. FreeBSD still uses OSS, which provides a simple and clear interface through standard device files (**/dev/dsp\*** for sound cards, **/dev/mixer\*** for mixers) and operates through a small number of common POSIX system calls.

> **Warning**
>
> The default audio management component (plasma-pa) for KDE 6 in FreeBSD Ports uses PulseAudio as its audio backend. PulseAudio, as an audio server, takes over system audio output management, forming a global audio routing. If you do not fully understand the configuration details, do not manually switch to other audio backends (such as PipeWire), as this may cause the audio system to malfunction.

## HDA Sound Card Driver

`snd_hda` is the driver module in the FreeBSD kernel that supports Intel High Definition Audio (HDA) specification sound cards, applicable to the vast majority of modern integrated sound cards. This driver is usually loaded automatically at system startup. You can use the `kldstat` command to check whether the driver is loaded.

> **Note**
>
> Only load the sound card module when FreeBSD fails to correctly detect the sound card.

To confirm the audio devices recognized by the system, use the following command to view the current sound card device list:

```sh
$ cat /dev/sndstat
Installed devices:
pcm0: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm2: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm3: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm4: <Realtek ALC892 (Rear Analog 5.1/2.0)> (play/rec) default
pcm5: <Realtek ALC892 (Front Analog)> (play/rec)
pcm6: <Realtek ALC892 (Rear Digital)> (play)
No devices installed from userspace.
```

If no `pcm` devices are listed, check whether the correct device driver is loaded.

The device marked as `default` in the output is the default audio device of OSS (Open Sound System). OSS is FreeBSD's native audio subsystem, providing direct audio device access interfaces. If software uses OSS as its audio output interface and the output device is set to default, audio will be output from this device.

To obtain more detailed sound card information for in-depth diagnosis, you can increase the debug output level by adjusting kernel parameters:

```sh
# sysctl hw.snd.verbose=4  # Set FreeBSD sound card driver debug output level to 4
```

This command sets the sound card driver's debug output level to 4. The debug level ranges from 0 to 4; the higher the value, the more detailed the output information. Level 4 outputs the most complete debug information. This setting takes effect temporarily and will revert to the default value after a system restart.

The audio output interface for most software in FreeBSD is OSS. Some software uses PulseAudio by default (such as the Firefox browser); for related settings, see the instructions below. Firefox can view the current audio backend through the `about:support` page. Firefox supports multiple audio backends, with automatic detection order: pulse-rust (PulseAudio Rust backend, requires PulseAudio), JACK (requires jackit), sndio (requires sndio), ALSA (requires alsa-lib), OSS (always available). You can also manually specify through the `media.cubeb.backend` configuration item in `about:config`.

The following command sets the default OSS audio device unit number to 5, where the number corresponds to the device number after `pcm`:

```sh
# sysctl hw.snd.default_unit=5
```

This setting takes effect temporarily and will revert to the default value after a system restart. To make it permanent, write the configuration to the **/etc/sysctl.conf** file.

The `pcm6: <Realtek ALC892 (Rear Digital)> (play)` in the above output is a digital output interface. The sampling rate of analog interfaces on integrated sound cards is typically 48 kHz, and some HDA codecs can support 96 kHz or higher; digital interfaces bypass the onboard DAC's sampling rate limitations and can use external DACs that support higher sampling rates. The S/PDIF interface is based on the IEC 60958 standard and can directly transmit PCM stereo signals up to 192 kHz/24 bit; the IEC 61937 standard is used to encapsulate compressed audio bitstreams (such as Dolby Digital, DTS, etc.) within IEC 60958 frame structures. Some TOSLINK optical interface implementations may be limited by bandwidth and only support up to 96 kHz.

If there is a digital output but no corresponding interface on the chassis front panel, and the motherboard provides S/PDIF (Sony/Philips Digital Interface Format) header pins, you can install an S/PDIF bracket (usually including both optical and coaxial interfaces), and it will be usable after connection.

## Automatic Switching to Headphones

FreeBSD can configure audio automatic switching in **/boot/device.hints**.

Identify the audio outputs enumerated by the system by running the following command:

```sh
% dmesg | grep pcm
```

The output may look similar to the following:

```sh
pcm0: <Realtek ALC892 Analog> at nid 23 and 26 on hdaa0
pcm1: <Realtek ALC892 Right Analog Headphones> at nid 22 on hdaa0
```

Add the following lines to the **/boot/device.hints** file:

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

> **Note**
>
> The configuration values in the above example only apply to the corresponding hardware environment. Node numbers may differ across different systems and must be adjusted according to the actual situation.

## Configuration File Example

```sh
# cat /dev/sndstat # Irrelevant information omitted
pcm1: <Realtek ALC897 (Rear Analog Line-in)> at nid 26 on hdaa0
pcm0: <Realtek ALC897 (Analog)> at nid 27 and 26 on hdaa0
```

This device is not a combo audio jack (Combo Jack, i.e., not a 2-in-1 speaker and microphone interface), and currently only one speaker is plugged in. Under the default configuration, this device will not output sound.

To resolve this issue, use the following commands to debug the audio configuration in real time (the commands take effect immediately but will be lost after a system restart):

```sh
# sysctl dev.hdaa.0.nid26_config="as=1 seq=0"   # Set HDA sound card node 26 audio stream to association 1, sequence 0
# sysctl dev.hdaa.0.nid27_config="as=1 seq=15"  # Set HDA sound card node 27 audio stream to association 1, sequence 15
```

* `as=1`: Group both into the same association group.
* `seq=0`: Main output (speaker), highest priority.
* `seq=15`: Headphone; when headphones are plugged in, the speaker will be automatically muted.

At this point, audio output has returned to normal. Edit the **/boot/device.hints** file and add the following lines to make the configuration permanent:

```ini
hint.hdaa.0.nid26.config="as=1 seq=0"    # Configure HDA sound card node 26 audio stream to association 1, sequence 0
hint.hdaa.0.nid27.config="as=1 seq=15"   # Configure HDA sound card node 27 audio stream to association 1, sequence 15
```

## Appendix: Volume Adjustment

You can use the system's built-in command-line tool `mixer` to adjust the system volume.

For example, the following command increases the system volume by 5%:

```sh
$ mixer vol=+5%  # Increase volume by 5%
```

## Troubleshooting and Outstanding Issues

### Compiling the Kernel to Enable Special Sound Cards

Some special sound cards require compiling the kernel manually. See Open Sound System for BSD\[EB/OL]. \[2026-03-25]. <http://www.opensound.com/bsd.html>.

### obs-studio

OSS has certain technical limitations as a low-level audio interface: its design does not provide an audio stream loopback mechanism, so when using software like `obs-studio`, it is not possible to directly record OSS output audio. According to the official forum, you can use the `virtual_oss` tool to simulate an audio device to achieve this functionality (using the `-M` parameter of `virtual_oss` to complete channel routing, redirecting OSS output to OSS input).

`obs-studio` can record PulseAudio output audio (the default "Desktop Audio" input source corresponds to PulseAudio output), so some software can be configured to use PulseAudio as the audio output interface. Software using PulseAudio is not controlled by the aforementioned OSS commands; you need to use the PulseAudio mixer to manage devices.

### AMD APU Display Driver Mode 2 Reset

Due to driver issues with initializing empty rendering contexts, when using an AMD APU (Accelerated Processing Unit) with the `drm-kmod` graphics driver, opening an empty player window without loaded media content may trigger a display driver mode 2 reset error (i.e., the driver reset mechanism), which in severe cases may cause a Kernel Panic.

Avoid opening player or audio player windows without any media content loaded. It is recommended to play audio files through terminal command lines.

## References

* FreeBSD Project. snd\_hda -- Intel High Definition Audio driver\[EB/OL]. \[2026-04-17]. <https://man.freebsd.org/cgi/man.cgi?query=snd_hda&sektion=4>. Intel HDA sound card driver manual page.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-11-multimedia-and-external-devices/di-11.1-jie-sheng-ka.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
