Raise your hand if you remember when PulseAudio was famous for breaking audio on Linux for everyone. For quite a few years, the standard answer for any audio problem on Linux was to uninstall PulseAudio, and just use ALSA. It’s probably the case that a number of distros switched to Pulse before it was quite ready. My experience was that after a couple years of fixing bugs, the experience got to be quite stable and useful. PulseAudio brought some really nice features to Linux, like moving sound streams between devices and dynamically resampling streams as needed.
The other side of the Linux audio coin is JACK. If you’ve used Ardour, or done much with Firewire audio interfaces, you’re probably familiar with the JACK Audio Connection Kit — recursive acronyms are fun. JACK lets you almost arbitrarily route audio streams, and is very much intended for a professional audio audience.
You may wonder if there is any way to use PulseAudio and JACK together. Yes, but it’s just a bit of a pain, to get the PulseAudio plugin to work with JACK. For example, all of the Pulse streams get mixed together, and show up as a single device on the JACK graph, so you can’t route them around or treat them seapartely.
It’s the conundrum faced by Linux users for years now. PulseAudio isn’t usable for pro audio, and JACK is too complicated for everything else. I’m loathe to suggest that yet another audio system could solve the world’s audio problems, but it would be nice to have the best of both worlds. To let the cat out of the bag, PipeWire is that new system, and it has the potential to be the solution for nearly everyone.
The Audio Video Chosen One
The story told is that [Wim Taymans] was contemplating applications distributed as Flatpaks, and realized that this would be problematic for video input and output. He had been working on making PulseAudio play nicely with containerized applications, and started thinking about how to solve the problem for video streams, too. While doing the initial protocol design, it became apparent that AV synchronization would be a devilish problem if audio and video were routed over separate systems, so it was decided that PipeWire would include audio handling as well. Once that decision was made, it became obvious that PipeWire could replace PulseAudio altogether. To make this a seamless transition, PipeWire was built to be fully compatible with the PulseAudio server. In other words, any application that can talk to PulseAudio automatically has PipeWire support.
If PulseAudio was going to be rebuilt from the ground up, then it might as well address pro audio. If PipeWire could satisfy the needs of pro audio users, it could feasibly replace JACK as the go-to audio backend for digital audio workstations like Ardour. Convincing every project to add support for yet another Linux audio server was going to be an uphill battle, so they cheated. PipeWire would just implement the JACK API. That may sound like a whole lot of feature creep, starting from a simple video transport system, and ending up re-implementing both JACK and PulseAudio.
Let’s make that point again. PipeWire is a drop-in replacement for Pulseaudio and JACK at the same time. Any application that supports Pulse now supports PipeWire, and at the same time it can pull all the clever tricks that JACK can. So far I’ve found two killer hacks that PipeWire makes possible, that we’ll get to in a moment. Pretty much all of the major distros now support running PipeWire as the primary audio server, and Fedora 34 made it the default solution. There were a few bugs to work out in the first couple weeks of using it, but PipeWire now seems to be playing nicely with all the apps I’ve thrown at it.
The Latency Question
JACK gets used for all sorts of hijinks, and one of its killer features is that it can achieve latencies low enough to be imperceptible. Playing audio back with a noticeable delay can throw music or talkers off badly. The effect is so strong, researchers have built a speech jammer that uses the principle to silence speakers from afar. Let’s just say that you really don’t want that effect on your conference call. A 200 ms delay shuts down speech, but even lower latencies can be distracting, especially for musicians.
For PipeWire to really replace JACK, how low do we need the latency to go? The Ardour guide suggests five milliseconds to really be imperceptible, but it depends on what exactly you’re doing. With just a bit of work, on a modern machine, I’ve gotten my latency down to just under 18 ms, over a USB audio device. To put that another way, that’s about the delay you get from standing 18 feet away from an audio source. It’s just enough for your brain to notice, particularly if you’re trying to play music, but not a deal breaker. Need to go lower? You’re probably going to need a real-time kernel.
To get started tuning your latency, copy alsa-monitor.conf
and jack.conf
into their places in /etc/pipewire
. There are a few tweaks here, but the main knobs to turn are api.alsa.period-size
and node.latency
in jack.conf
. To really get low latencies, there are a series of system tweaks that can help, essentially the same tweaks needed for low latency on JACK.
Oh The Fun We Can Have
Now on to those tricks. While JACK can handle multiple streams coming from a single soundcard, it doesn’t handle multiple external sources or sinks easily. You have a pair of USB mics and want to record both of them? Sorry, no can do with JACK or ALSA. Get a bigger, more expensive audio interface.
PipeWire doesn’t have this limitation. It sees all of your audio devices, and can mix and match channels even into Ardour. It’s now trivial to make a three-track recording with multiple soundcards.
OK, I hear you saying now, “I’m not an audio engineer, I don’t need to do multi-track recording. What can Pipewire do for me?” Let’s look at a couple other tools, and I suspect you will see the possibilities. First is Calf Studio Gear, an audio plugin collection. Among the plugins are a compressor, parametric EQ, and a limiter. These three make for a decent mastering toolkit, where “mastering” here refers to the last step an album goes through to put the final polish on the sound. That step is sorely lacking on some of the YouTube videos we consume. Inconsistent audio levels is the one that drive me crazy the most often.
A second tool, qjackctl
, helps put Calf to use. Not only does it allow you to see and manipulate the graph of signal flow, it has the ability to design simple rules to route audio automatically. Those rules use Perl regex matching, and it’s easy enough to set them up to automatically direct audio streams from Chrome into the Calf compressor, and from there to your speakers. Add Calf and qjackctl
to your desktop’s autorun list, and you have an automated solution for bad YouTube mastering. Why stop there? Going to be on a Zoom call? Route your mic through Calf, and do a bit of EQ, or add a gate to cut down on background noise. Since you’re at it, record your audio and the call audio to Ardour.
Work Left To Do
PipeWire was originally intended to shuffle video around. That part works too. Browsers have added PipeWire support for video capture, and if you happen to be running Wayland, desktop capture is a PipeWire affair now, too. OBS has added support for PipeWire video inputs, but output to PipeWire is still unimplemented. And on that topic, while the JACK tools work great for audio, the video control and plugin selection is noticeably lacking.
There is one thing that JACK supports that PipeWire currently can’t touch. JACK supports the FFADO drivers to talk to FireWire audio interfaces, and PipeWire can’t support them at all. (OK, yes, ALSA has a FireWire stack, but it’s not in great shape, and only supports a handful of devices.) USB3 has certainly replaced FireWire as the preferred connection for new devices, but there are plenty of quality interfaces still at work that are FireWire only. Very recently, a new TODO item has appeared on the official list: FireWire backend based on FFADO or fix up ALSA drivers.
So where does that leave us? PipeWire has already changed what I can do with Linux audio. If the video ecosystem develops, it has the potential to make some new things possible, or at least easier, there too. The future is bright for multimedia on Linux.
0 Commentaires