> 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.5-jie-yin-pin-bo-fang-qi.md).

# 11.5 Audio Players

The main audio players on FreeBSD include Audacious, VLC, and MPD. This section provides pkg installation methods and introduces the configuration process for playing DSD audio with MPD.

## Audacious

### Installing Audacious

* Install using pkg (binary package manager):

```sh
# pkg install audacious audacious-plugins
```

> **Note**
>
> The `audacious-plugins` plugin package is a necessary dependency for the Audacious main program to run. Without installing this plugin package, the `audacious` main program cannot start properly.

* Or compile and install using Ports (source code package manager):

```sh
# cd /usr/ports/multimedia/audacious/ && make install clean
# cd /usr/ports/multimedia/audacious-plugins/ && make install clean
```

### Using Audacious

Test compatibility with music formats such as `.m4a` (MPEG-4 audio container format), `.flac` (lossless audio compression encoding), `.av3a` (AVS3 audio raw bitstream format), etc. `.m4a` is a container format that can contain various encodings (such as AAC, ALAC, etc.); `.av3a` is a raw bitstream, and in practice AVS3 audio is also commonly encapsulated in MP4 containers with the `.m4a` extension.

> **Tip**
>
> Based on testing, Audacious with its default build supports `.flac` and `.m4a` (AAC encoding) formats among the above, but currently does not support `.av3a` (AVS3 audio raw bitstream) and other encoding formats. Appropriate plugins must be installed or separate configuration is required.

![Audacious](/files/A0GnDJW6qugvkFE088mu)

## VLC

The installation method for the VLC (originally VideoLAN Client) player can be found in the video player section of this book. The `ffmpeg` multimedia framework in FreeBSD (where "FF" stands for "Fast Forward" and "mpeg" refers to the MPEG standard) does not enable libuavs3d (AVS3 decoding) and libdavs2 (AVS2 decoding) support in its default build configuration. This section does not cover the configuration method for recompiling.

Through actual testing, with `ffmpeg` installed and AC-4 decoding support enabled at compile time, the VLC player can play AC-4 encoded m4a format audio (note that the standard `ffmpeg` build does not enable AC-4 decoding by default; you need to patch and compile it yourself):

![Playing AC-4 Encoded m4a Format Audio](/files/8SdcKYlODP51MgVqJkcC)

## Playing DSD with MPD

Music Player Daemon (MPD) is a music player daemon that can run on a server or personal computer and be remotely controlled through various client programs.

MPD's main features include: support for decoding multiple audio formats, client-server separated architecture, playlist management, streaming support, and cross-platform operation.

### Hardware Preparation

You need a sound card or DAC (Digital-to-Analog Converter) that supports the DSD (Direct Stream Digital) format, and a DSD-encoded audio file for testing.

The following configuration instructions are based on the FreeBSD 14.0 operating system, using the HiBy R3 as the external DAC example device (the configuration method for other similar sound cards is basically the same), and using the OSS (Open Sound System) audio driver.

### Installing Music Player Daemon

```sh
# pkg install musicpd
```

Or compile and install via Ports source code:

```sh
# cd /usr/ports/audio/musicpd/
# make install clean
```

### Hardware Settings

The current system sound card and audio device status is as follows:

```sh
# cat /dev/sndstat
pcm0: <Realtek ALC269 (Analog 2.0+HP/2.0)> (play/rec) default
pcm1: <Intel Cougar Point (HDMI/DP 8ch)> (play)
pcm2: <USB audio> (play)
No devices installed from userspace.
```

This example uses the pcm2 device, whose corresponding device file path is **/dev/dsp2**, which will be used in the configuration below.

You can use the `sysctl -d dev.pcm.2` command to view the detailed meaning of relevant hardware parameters. The three key parameters are excerpted below:

```sh
dev.pcm.2.bitperfect: bit-perfect playback/recording (0=disable, 1=enable)
dev.pcm.2.play.vchanrate: virtual channel mixing speed/rate
dev.pcm.2.play.vchanmode: vchan format/rate selection: 0=fixed, 1=passthrough, 2=adaptive
```

Set the parameters as shown below (you can write these configurations to the `sysctl.conf` file to make them persist across system reboots):

```sh
# sysctl dev.pcm.2.bitperfect=1           # Set sound card 2 to bit-perfect mode
# sysctl dev.pcm.2.play.vchanrate=352800  # Set sound card 2 playback sampling rate to 352800 Hz
# sysctl dev.pcm.2.play.vchanmode=1       # Set sound card 2 playback channel mode to passthrough
```

Parameter descriptions:

* Since the OSS audio driver is used, Music Player Daemon can only use DoP (DSD over PCM) transmission mode, and DoP mode requires enabling bit-perfect mode.
* Sampling rate (vchanrate): The sampling rate of DSD audio is an integer multiple of 44.1 kHz, so it should not be set to an integer multiple of 48 kHz, as this may produce audio noise; when hardware conditions permit, it should be set to the highest possible value. The example here is set to 352.8 kHz.
* `dev.pcm.2.play.vchanmode` virtual channel mode parameter description:

| Value | Mode        | Description                                                                                                                                              |
| ----- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0     | fixed       | The audio device uses a fixed sampling rate and format to process multiple audio streams                                                                 |
| 1     | passthrough | The audio device preserves the original sampling rate and format of the input audio stream as much as possible, without additional conversion processing |
| 2     | adaptive    | The audio device automatically adapts and converts the sampling rate and format of the input audio stream as needed                                      |

> **Tip**
>
> You can use the `dmesg` command to view the available sampling rates supported by the hardware in the kernel log. When playing non-DSD files, it is more appropriate to set the sampling rate to the same as (or an integer multiple of) the audio file's own sampling rate, as this avoids audio quality loss caused by resampling. A higher sampling rate is not always better; multiple tests are needed to determine the value suitable for the current hardware configuration.

View kernel messages related to the pcm2 sound card:

```sh
# dmesg | grep -i pcm2

pcm2 on uaudio0

# dmesg | grep -i uaudio0

uaudio0 on uhub0
uaudio0: <HiBy R3, class 239/2, rev 2.00/ff.ff, addr 1> on usbus1
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: Play[0]: 32000 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.
```

### Music Player Daemon Basic Settings

The configuration file for Music Player Daemon (musicpd) is **/usr/local/etc/musicpd.conf**.

The default directory structure used is as follows:

```sh
/
├── var
│   └── mpd
│       ├── music                     # MPD music storage directory
│       └── .mpd
│           └── playlists            # MPD playlists directory
├── usr
│   ├── ports
│   │   └── audio
│   │       └── musicpd              # MPD audio player Port
│   └── local
│       └── etc
│           └── musicpd.conf          # MPD configuration file
└── dev
    ├── sndstat                        # Sound card device status file
    └── dsp2                           # Audio device file (example)
```

Some directories used by MPD by default need to be created manually:

```sh
# mkdir -p /var/mpd/music            # Create MPD music storage directory
# mkdir -p /var/mpd/.mpd/playlists  # Create MPD playlists directory
# chown -R mpd:mpd /var/mpd  # Set the directory owner to mpd user to avoid permission issues
# chmod 777 /var/mpd/music  # Used for storing music files, set to 777 for convenience of adding and deleting files; adjust permissions as needed in practice
```

Edit the **/usr/local/etc/musicpd.conf** file and add a new section after the `"Default OSS Device"` section:

```ini
audio_output {
        type            "oss"
        name            "OSS Device (dop mode)"
        device          "/dev/dsp2"     # Specify the device to use; no need to set the DAC or sound card as the default device. dsp2 can be dedicated to music playback, while the default device can be used for other purposes
        dop             "yes"           # Enable dop mode
}
```

> **Tip**
>
> You can specify multiple output devices and enable or disable the corresponding output devices as needed in various clients.

Enable the musicpd service:

```sh
# service musicpd enable  # Set MPD service to start at boot
# service musicpd start  # Start the MPD service
```

### Client Usage

You can use various clients such as ncmpc (character interface), MaximumMPD (iPhone), and others. There is a rich variety of clients available.

For PC GUI clients, Cantata (Port **audio/cantata**) is recommended. The original author of Cantata stopped development in 2022, but a community fork (nullobsi/cantata) has taken over maintenance and ported it to Qt6. The `audio/cantata` in FreeBSD Ports has already switched to this actively maintained fork.

For command-line environments, ncmpc (Port **audio/ncmpc**) is recommended, suitable for binding to desktop environment global hotkeys.


---

# 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.5-jie-yin-pin-bo-fang-qi.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.
