Linux Audio Guide

Posted on Aug 18, 2024

Understanding Current Audio Solutions

There are three commonly discussed audio abstraction layers in Linux:

  1. Pulseaudio
  • Created as a modern replacement for Enlightenment Sound Daemon (ESD), it provides advanced features like per-application volume control and network audio streaming.
  1. Jack
  • Designed as a professional audio server for Linux, it offers low-latency audio processing and precise control over audio inputs and outputs, making it suitable for professional audio work.
  1. Pipewire
  • The newest abstraction layer, Pipewire integrates seamlessly with both Pulseaudio and Jack.

Understanding the Stack

  1. Kernel layer

The kernel layer provides hardware abstraction. Advanced Linux Sound Architecture (ALSA) is the primary component that interacts with sound cards and manages communication, replacing the older Open Sound System (OSS). Thus, all three abstraction layers previously refered must communicate with ALSA.

  1. Middleware/Backend layer

ALSA Library (libasound): Provides a userspace interface to interact with ALSA.

Problem: ALSA is specific to Linux. What about other operating systems?

Solution: The need for cross-platform support led to the creation of sound servers like Pulseaudio, which works on UNIX like operating systems and even on Windows.

So which one do I use?

You might be asking if you really need sound servers/abtraction layers over ALSA to get audio working on Linux. The short answer is: no. The correct answer is: you should use a sound server (spoiler: PipeWire).

End users can directly use ALSA if they wish and even have pseudo-pulseaudio emulation with apulse software.

But, and this is according to my personal experience, it is highly recommended that you use a sound server, specifically PipeWire and I will explain you why.

By default, ALSA comes with a very poor configuration, and does not (by default) support mixing of multiple streams. You can configure ALSA with various plugins that enable this feature such as dmix, dsnoop, etc.

It is a very tiresome thing to do because even if you apparently configure things properly you will always come accross some problem sooner or later.

Pulseaudio does one thing well: it sets a nice ALSA configuration by default, using its own plugin called pulse, which has multiple stream mixing without having to configure a single thing.

However (and once again I will speak from experience) when you start doing more things such as bluetooth audio or want to re-route audio you will find yourself stuck with pulseaudio, because when it was initally designed it did not prioritize these things. If one wanted to do professional audio, one had to install JACK most likely with pulseaudio already installed, this was a mess.

PipeWire

PipeWire aims to replace both PulseAudio and JACK by providing a unified solution for audio and video handling.

It provides a handful of benefits such as:

  1. ALSA, PulseAudio and JACK compatibility
  2. Low-latency audio
  3. Simplified setup
  4. Bluetooth audio support
  5. Modular architecture

Therefore, if you want the best possible audio experience on Linux, install PipeWire.

PipeWire prerequisites

PipeWire requires three things to work properly:

  1. D-Bus user session bus
  • for inter-process communication and session management
  1. XDG_RUNTIME_DIR environment variable
  • for creating a runtime directory to store temporary files and session-specific data
  1. Pipewire session and policy manager
  • wireplumber is the most commonly used

NOTE: If your DE/WM/Wayland compositor is not configured to provide a D-Bus user session bus, you have to run a dbus session alongside it:

# .xinitrc
exec dbus-run-session mywm

NOTE: To set XDG_RUNTIME_DIR manually you may paste the following in your .profile:

# .profile
if [ -z "$XDG_RUNTIME_DIR" ]; then
	XDG_RUNTIME_DIR="/tmp/$(id -u)-runtime-dir"
	mkdir -pm 0700 "$XDG_RUNTIME_DIR"
	export XDG_RUNTIME_DIR
fi

PipeWire setup

Install pipewire and a PipeWire session manager wireplumber. Additionally, I recommend installing alsa-pipewire to synchronize ALSA audio control with PipeWire’s.

Bluetooth

Install bluez and enable bluetoothd to get access to bluetoothctl and other utilities, PipeWire bluetooth support is built-in and works really well in my experience, with full support for LDAC (A2DP sink) for my Sony WH-1000XM4.

Resources