This is an old revision of the document!


Build a Linux audio system

A minimal, basic and KISS manual on how to build a Linux audio system. This manual comprises installation and configuration of a Linux audio system based on Debian 12 with a XFCE desktop environment and a Liquorix kernel.

Hardware

This manual assumes you're on a X86_64 platform. Any notebook or desktop computer using this platform should work but bear in mind that the more powerful your computer, the better it will run a Linux audio system. Linux audio applications and plugins can be very resource intensive so the more CPU and memory, the better. Using an Solid State Drive (SSD) as the main hard drive is also recommended.

When using an USB audio interface make sure you're using a quality USB cable in working order and that the USB interface is attached to a USB port with as little other peripherals or other devices connected to it as possible. This can be checked with the lsusb command. lsusb indicates bus numbers and devices so it's a matter of figuring out which physical USB port is attached to which bus and then picking the port connected to a bus that has as little other devices attached to it.

An example of a quality USB cable: https://shop.klotz-ais.com/usb-ab.html

Operating system

This manual starts from a standard Debian 12 “Bookworm” installation with XFCE installed from a live CD.

Download the operating system

Download the Debian 12 live ISO here: https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-12.2.0-amd64-xfce.iso

And transfer it to a USB flash drive with enough space. Bear in mind this operation will erase any data that is currently on the drive.

sudo dd if=<file> of=<device> bs=16M status=progress oflag=sync

Where <file> is the path to the downloaded ISO file and <device> is the device name of the USB flash drive. Make sure you get the device name right otherwise you might risk overwriting the wrong drive. You can list your drives/device names with fdisk -l. More information can be found here: https://www.debian.org/CD/faq/#write-usb

When the copy process is finished you can try booting your computer with the USB flash drive.

Install the operating system

Once booted from the USB flash drive select “Live System (amd64)” from the boot menu. This will boot your computer into a live Debian environment. This way you can verify if your system can run Debian 12 properly.

Now you can click the “Install Debian” icon and select “Launch anyway” when asked. This will start the installation process. Go through all the steps as you see fit. Some tips:

  • Modern systems with enough memory (>= 16GB) can live without swap
  • The default filesystem Ext4 is fine for audio work

Once the installation is finished reboot your computer into the freshly installed OS and update the system:

sudo apt update && sudo apt dist-upgrade

Configuration

Install the following packages from the default Debian repositories:

  • rtirq-init
  • vlc
  • a2jmidid
  • htop
  • usbutils (when using an USB audio interface)

They can be installed in one go:

sudo apt install rtirq-init vlc a2jmidid htop usbutils

Select “Yes” during the installation of jackd2 when asked to enable real time process priority.

Boot settings

Boot settings are taken care of in different locations, /etc/default/grub for the boot loader which allows to set kernel options for kernel parts that are compiled into the kernel and /etc/modprobe.d/ to set kernel module options for kernel parts that get loaded when needed, i.e. when you plug in an USB audio interface after having booted your system.

:!: Warning: Using mitigations=off will make your machine less secure! Use with caution! For more information on the risks see https://meltdownattack.com/

For /etc/default/grub add the following options to the line that starts with GRUB_CMDLINE_LINUX:

mitigations=off usbcore.autosuspend=-1 threadirqs

You can do this with an editor as root, so with sudo vi, sudo nano in a terminal session. Make sure the line looks like this now:

GRUB_CMDLINE_LINUX="mitigations=off usbcore.autosuspend=-1 threadirqs"

And update the Grub configuration with sudo update-grub. For an explanation of the above options, see System configuration. usbcore.autosuspend=-1 only applies if you're working with an USB audio interface. This option makes sure your USB device will never be put in a sleep state.

For /etc/modprobe.d/ it's a matter of personal preferences i.e. whether you'd want to load USB devices in a certain order or if you'd like to block certain drivers from loading. An example configuration file could look as follows:

# Onboard audio
options snd-hda-intel index=10 vid=0x8086 pid=0x1e20

# RME Babyface
options snd-usb-audio index=0 vid=0x0424 pid=0x3fb7

# Arturia BeatStep Pro
options snd-usb-audio index=1 vid=0x1c75 pid=0x0287

# Behringer BCR2000
options snd-usb-audio index=2 vid=0x1397 pid=0x00bc

# Edirol UA-25
options snd-usb-audio index=3 vid=0x0582 pid=0x0074

# Akai MPK Mini
options snd-usb-audio index=5 vid=0x09e8 pid=0x007c

# Prevent Bluetooth modules from loading
blacklist bnep
blacklist bluetooth
blacklist btusb

# Prevent nouveau driver from loading
blacklist nouveau
options nouveau modeset=0

If you'd like to make use of kernel module options you can create a file like /etc/modprobe.d/audio.conf and add your settings there. These will be picked up during boot time. What the above file does is configuring specific index numbers for different USB devices which ensures a consistent listing of these devices in audio software and prevent certain drivers from loading.

User settings

Add your user to the audio group.

sudo usermod -a -G youruser audio
newgrp audio

Power management

Allow the audio group to set CPU DMA latency.

curl -s https://raw.githubusercontent.com/Ardour/ardour/master/tools/udev/99-cpu-dma-latency.rules | sudo tee /etc/udev/rules.d/99-cpu-dma-latency.rules
sudo udevadm control --reload-rules
sudo udevadm trigger

For more info:

System settings

The easiest option to finish up setting your system when starting it up is with a script in /usr/local/bin that you call as a service through systemd. Name the script something like rt-audio-setup and make sure it contains at least the following lines:

# Disable CPU frequency scaling
systemctl mask ondemand

echo -n performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Create a corresponding systemd service unit file in /etc/systemd/system/rt-audio-setup.service with the following lines:

[Unit]
Description=Prepare system for real-time audio

[Service]
Type=oneshot
ExecStart=/usr/local/bin/rt-audio-setup

[Install]
WantedBy=multi-user.target

And enable and start it with sudo systemctl enable –now rt-audio-setup.

The script could be extended to configure other settings like disabling hyper threading or unloading unneeded kernel modules when desired.

IRQ settings

Because of the threadirqs kernel option it is now possible to prioritize specific IRQ's. Especially USB audio interfaces can benefit from this, having such an interface connected to a port with a prioritized IRQ can reduce crackling and popping caused by xruns. Configuration for these settings is done in /etc/default/rtirq.

A generic example could look like this:

# IRQ thread service names
# (space separated list, from higher to lower priority).
RTIRQ_NAME_LIST="xhci ehci snd"

# Highest priority.
RTIRQ_PRIO_HIGH=90

# Priority decrease step.
RTIRQ_PRIO_DECR=5

# Lowest priority.
RTIRQ_PRIO_LOW=51

# Whether to reset all IRQ threads to SCHED_OTHER.
RTIRQ_RESET_ALL=0

After having adjusted these settings restart rtirq with sudo systemctl restart rtirq. You can check the current IRQ priorities with sudo /etc/init.d/rtirq-init status.

Liquorix kernel

Photo by Pikaluk from UK - Flickr, CC BY 2.0The Liquorix project provides a kernel flavor that works well for low latency audio. Download the installer:

curl -s -O "https://liquorix.net/install-liquorix.sh"

Inspect it if you wish so and when having verified that the script is safe you can run it:

sudo bash /path/to/install-liquorix.sh

This will install the latest Liquorix kernel available. Reboot to start your system with the Liquorix kernel.

KX Studio packages

kxstudio.jpgThe KX Studio repositories contain a lot of audio applications and plugins not available in the default repositories. Instructions can be found here: https://kx.studio/Repositories

Installing the kxstudio-default-settings package is not necessary, in fact, given the age and content of this package it might be better to not install it at all.

Wrapping it up

Your system should now be properly configured to be used as a Linux audio system. You can now install your favorite applications and/or plugins. You can of course go further by trying out a real-time kernel, tweaking your filesystem settings or reducing swap usage but in practice the differences will probably be minute.

To check if the most important conditions for a well working Linux audio system are met you could run the rtcqs script, see rtcqs.

wiki/system_build.1697461074.txt.gz · Last modified: 2023/10/16 14:57 by autostatic