Running A University Linux-based Audio Lab: Part 2 — Linux Audio

“Running a Linux Audio Lab was fun, he said! You should try it, he said! He didn’t say anything about ALSA and JACK and Pulseaudio! Aaaaaah!”

-Horrified individual the first time they try to get low-latency audio working in Linux with an Ubuntu base.

To be clear, in Part I of this series I never made the claim that creating and maintaining a Linux audio lab at a University was fun. I *did* say it was beneficial in a number of ways, both to students and the institution. However, I was also careful to point out that the endeavor is not for everyone. If you have *not* read that post please do. It provides an overview of what we do and why. In this second installment I will present the Linux Audio world *fairly* and then talk about how I set up our Linux digital audio workstations (DAW) to work as optimally as possible.

Part I: Linux Audio is the Worst

I’m allowed to say this because I’m a Linux audio dude from way back. (My friend Matt can attest to this. He is why I am in this mess, having pulled me in at Fedora Core 3 when configuring your audio and video took three days and an animal sacrifice!) Also, every other Linux audio developer or user out there also knows this to be true. The problem(s) with Linux audio are, well, complex. Paul Davis, original developer of JACK talks about it on this podcast if you want more details. But essentially the situation is this:

ALSA is the kernel level software interface for audio on most (but not all) Linux systems. It has limitations, the most salient of which is that ALSA can only talk to one hardware connection at a time. Now, you can duplex multiple sources (in and out), but only one software process can address those sources at a time. This means you need something sitting higher up in the OS that can interact with ALSA, essentially mixing audio sources in and out to various applications.

Pulseaudio is one of those solutions and it ships with Ubuntu by default. It’s essentially a middleware software mixer and allows multiple audio clients (things like audio players and browsers) to send audio to your speakers at the same time. But Pulseaudio is complicated, fiddly, and prone to breakage:

In a typical installation scenario under Linux, the user configures ALSA to use a virtual device provided by PulseAudio. Thus, applications using ALSA will output sound to PulseAudio, which then uses ALSA itself to access the real sound card.

Yikes! One specific problem with Pulse that makes it unsuitable for professional audio environments is that it is not a low-latency application. To support audio applications like high sample rate recording you need a realtime, low-latency system to avoid audio dropouts that occur when other processes take processor precidence.

Enter JACK.

JACK is a recursive acronym that stands for the JACK Audio Connection Kit. It offers realtime any-to-any connections (audio multiplexing) and high tunability (read: low latency.) Once configured properly, it is extremely reliable and solves the problems inherant with the ALSA + Pulseaudio combination mentioned above. But (yes, you guessed it) there are some problems here as well.  1) JACK doesn’t configure itself and getting it up and running in combination with Pulseaudio can take some time, especially for the newly converted. 2) Many, if not most, common user-land apps are not JACK clients. This means if you want to listen to YouTube while you have JACK running you are out of luck. Or rather, you have to have Pulseaudio installed (which is what your browser wants to talk to) and bridged to JACK/ALSA.

The solution? Glue all of them together in a Trio de Sade of unwholesomeness. Joking aside, configuring them is actually pretty easy provided you have *even more* software installed. But before I launch into that I must mention that Linux Audio will not always be “the worst.”

Pipewire is the future of Linux audio. Currently, it offers acceptable if fiddly service and can do *much* of what most users require. A few distros are even rocking it as the default audio solution, including Fedora. For a few things like pro audio, however, it’s a ways away.

Part II: Get your low-latency kernel installed

One of the key ingredients to the Linux digital audio workstation is the low-latency kernel. In my day (prehistoric times) we used kernels with the rt patch provided by Fernando Lopez-Lezcano who is still building them for Fedora (33, 34, and 35!). However, the new Fedora kernel allows configuring preempt (skip all this if your eyes are glazing over) at boot via grub so it’s not even required for low-latency audio on Fedora anymore. Anyway, Ubuntu doesn’t like any of that nonsense at all and encourages you to simply use the low-latency kernel. In my experience, this is acceptable provided you also disable any system CPU governance to eliminate the possibility of the processor moving to a lower speed when you don’t want it to (resulting in xruns in JACK.) This means installing cpufrequtils and running a few commands. (These have changed relatively recently, so check your sources based on what kernel you are using and proceed with caution!)

$ sudo apt-get install cpufrequtils
$ echo 'GOVERNOR="performance"' | sudo tee /etc/default/cpufrequtils
$ sudo systemctl disable ondemand

In the lab we use the latest stable lowlatency-hwe kernel. This version uses a more recent version of the kernel than lowlatency, which can lag behind even the generic versions. We have had to switch kernels when bugs or instability occurred with the HWE, but not often.

Part III: Making ALSA, PulseAudio and JACK Play Nice

In Part I of this series I mentioned that part of our Linux-cluster overlay consists of adding the KXStudio repositories. From those repositories, and among other notable great software are two outstanding applications Carla and Cadence. Using Cadence alone it’s possible to configure JACK, ALSA, and PulseAudio all in one place. (Well, provided you already have an ‘audio’ group or have created it correctly and that your users are in the audio group and that audio settings have been configured for JACK previously in /etc/security/limits.d/audio.conf. This is fun and easy!)

Opening Cadence shows you some important things up front. I’ll just mention a few quickly here.

First, in the System Checks area at the bottom left Cadence tells you if you are running a low-latency kernel and whether your user is in the audio group. This can save you troubleshooting time and headaches as well. In the lower right, in the bridges section, you configure ALSA to talk to JACK and bridge PulseAudio to JACK as well. Provided your JACK settings are sane, everything just works. If it doesn’t, you will want to look at your hardware settings, your JACK settings, and last (and amazingly?) in the alsamixer (you might have to apt install it) to make sure PulseAudio and ALSA agree on the available hardware and settings. (I’ve seen ALSA mute channels that PulseAudio is unaware of, etc. I have no idea how/why this occurs. Still looking into that one!)

One more thing

Depending on which lowlatency kernel you install, you *may* have to tell grub (your bootloader) which kernel you want to use. By default grub will use the kernel with the highest version number. Thus, using the HWE kernel means that will *always* have a higher kernel number and will be the kernel used by your system. If you want the standard lowlatency kernel, however, you will have to change a few things. Instructions for doing so are here, specifically in the section marked “specific entries” referring to the file /etc/default/grub.

There are some consequences to changing defaults manually. Most importantly, the kernel you enter there will be the one used forever, even after updating/installing newer kernels. The system keeps n number of kernels as you “update” using sudo apt update (or sudo pkcon update). This means, eventually, you will have a pile of kernels installed. You can (and should) use ‘sudo apt autoremove’ when prompted by the system to remove older kernels.

Next Episode: a Script and some details

Next time I will talk about our post-installation script and comment on the packages and process in a more detailed way than I have in these first two posts. If you are interested in getting notifications when I post a new article please click the Subscribe tab above and sign up!

1 Comment

  1. […] Issue: An overview of the Linux audio system (as implemented in our lab). Click the Subscribe link at the top of the page to be alerted when new […]