Let's talk about how the Linux/Arch sound infrastructure works - ALSA, PulseAudio, Jack, Pipewire,
Hello everyone.
I recently purchased Bitwig Studio 2 and this was the first time I really had to tinker around with sound servers (jack2 in my case) on Arch. And while doing so I noticed that I'm not really that familiar with how sound works in Linux/Arch. Of course I consulted the Arch wiki, but I still have a few open questions.
This is how I understood things to be:
- On the "lowest" level there is ALSA. It's basically the sound card drivers and that's why ALSA lives/happens/works in the kernel/as kernel modules. ALSA is the successor of OSS.
- On top of ALSA there's PulseAudio. It sounds like it's supposed to make things easier for developers/apps when it comes to accessing/mixing/playing/etc sounds on Linux. It's basically something like Django but for sound.
- There is also JACK. Which sounds like it's the same thing as PulseAudio, just with a focus on realtime/low-latency audio. You can have both JACK and PulseAudio installed at the same time.
- Pipewire will replace both PulseAudio as well as JACK. (And some video stuff as well, but let's focus on audio/sound for now to keep things simpler)
These are my questions:
- Why do I even need anything "above" ALSA? IIRC way way back in the day I had to set my volume with alsamixer and IIRC even my Desktop could interact directly with ALSA. Meaning different inputs/outputs. So why is there anything like JACK or PulseAudio?
- How can JACK - something that runs on top of ALSA - be faster/more low-latency than ALSA itself? Or why is ALSA not used directly? I get that something like PulseAudio offers some ease-of-use scenarios so I totally understand why it exists, but what about JACK? Wouldn't pure ALSA be even more low-latency?
- If PulseAudio uses ALSA to play sound, then why is there a package like
pulseaudio-alsa. What did I misunderstand here? - When researching Pipewire it sounded like it will fully replace JACK but only partially replace PulseAudio? Is that correct? And if it is: Why not fully replace PulseAudio as well? What are the thoughts behind this?
Other notes:
- Sound on Linux/Arch is a bit messy and unprofessional at the moment. So if Pipewire is what I think it is, then I absolutely welcome it!!
- If any of you are looking for a Linux DAW take a look at Bitwig! It's awesome. It's a full-fledged, professional, modern DAW and it has native Linux support. It's one of the very few commercial pro applications available for Linux, so it received my (almost) instant (monetary) support as well. :-) And there's an AUR package for it. Also it is currently on sale (until January 15th I believe).
That was it. Thanks so much in advance for your input/opinions. I hope this is of interest to others as well!
Edited 9 Jan 2019. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 154 · 100% up
- Kind
- Text
- ID
- ae67oa
44 comments
Mostly correct, except:
pulseaudio-alsais just a configuration file that tells applications that use ALSA directly to go through Pulse instead.Thanks for your input. So it sounds like I'm going to be a big fan of pipewire. I will have to follow its development more closely.
Pipewire is definitely going to be interesting. There's a lot to learn from the mistakes Pulse and JACK made.
It also has the explicit goal of consistent latency. e.g. the software knows that it will always be 20ms from the time when it sends audio data to the api to when the speaker starts moving.
Deleted before we saved it.
more like Waylled garden
...what.
Good pointers so far. I have one more thing to add, which might help clear some of the confusion
ALSA itself can be split into 2 parts: the actual soundcard driver, and ALSAs userspace plugins, where for example dmix and upmix and all these kinds of ALSA configurations come from.
ALSA as-in the kernel driver is the lowest feasible level, this is where all of the other options plug into (which is why JACK is lower latency than "ALSA" doesn't make sense, yes jack is lower latency than the ALSA userspace, however this is different from the kernel drivers everyone else is dependant from), raw access to this device is provided through the hw:0 and similar identifiers you see in ALSA utilities.
That has one big drawback, unless your card itself has a hardware mixer, only one single application can open your card at any given time with their latency and sampling requirements.
To alleviate that, various plugins - the userspace ALSA - have been developed including dmix which mixes everything to a single common configuration and is the one to open the sound card in the end. These are however statically configured and in order to change something, you'd have to restart your applications to adjust to a new configuration.
To that extent JACK and pulseaudio come in, which are daemons that handle that opening of the sound card dynamically according to the requirements of your currently playing audio. Wheras pulseaudio is more general purpose focused and JACK is intended for pro audio providing low latencies. An obvious example where this comes into play is - for example - power saving, where pulseaudio has facilities where applications which aren't latency critical (like music players) can declare that they can live on a bigger buffer, which will lead to less wakeups as the current state doesn't have to be checked and verified as often. Whereas JACK throws that out of the window to provide the quickest response time possible.
Here are some slides (albeit older, though apart from the early stages of pipewire this still holds) from a talk by Paul Davis who is one of the main devs of JACK, on why both are relevant, for a different purpose.
There are two ALSAs, so to speak. One is the kernel infrastructure and drivers that every sound server interfaces with, and the other is the userspace libraries to allow applications to talk with the kernel part. JACK and Pulse only use the kernel stuff, both can also pretend to be the userspace ALSA. So yes, JACK+ALSA can offer lower latency than ALSA+ALSA that way.
Ahhh ok so that means that JACK is faster/lower latency than the userspace part of ALSA? Got it. Thanks for clearing this up!
Linked the post to David which maintains most of the pro-audio stack in Arch. There is also a mailing list for this.
https://lists.archlinux.org/listinfo/arch-proaudio
In my case I just got tired of battling packagers that made a dependency on pulseaudio rather than libpulse. I ran bare Alsa for a long time but it just became too much of a hassle for reasons that were not Alsa's fault. My needs have changed overtime and Pulse became good enough. For me it's not so much that I needed Pulse but that I was goaded into it over time.
I want to second that. I don't remember exactly which packages require pulseaudio (Firefox or Chromium even?), but you end up having it installed eventually as a dependency.
Also in my particular case, I couldn't find a sound volume applet for XFCE (may be i didn't look hard enough). In order to have the speaker icon I had to install pulse and the appropriate XFCE applet. Otherwise managing volume via terminal was the only game in town.
May be someone knows here of a good ALSA volume applet for XFCE?
I thought that the XFCE volume applet was ALSA only and that's why it is so bad. A PulseAudio applet is what we need. You can run the Pulse audio control but it won't work if the XFCE ALSA applet has fubar the controls.
One of the reasons I use Cinnamon is because it has a fully functional Pulse applet.
Unless you're using a professional audio card, it can't be used by more than a single application at a time. Whether it's JACK or PulseAudio or esound or dmix etc... we need an extra piece of software that manages the output of all applications that needs to use the audio hardware.
As mentioned before, this is a confusion caused by ALSA having 2 parts: Kernel and userspace. JACK is lower latency than ALSA's userspace counterpart.
For the same reason as above. pulseaudio-alsa catches the output of applications that uses the ALSA's userspace libraries.
From what I've read Pipewire's initial reason to exist is to have something that can leverage the new sandboxing solutions like Flatpak for the video/audio hardware. Like app permissions in Android for video/audio hardware.
Their secondary mission is to replace/unify JACK and PulseAudio as well because they need to implement most of the same features anyway. Mandatory XKCD here -> https://xkcd.com/927/
Yeah I had issues a few weeks ago with Firefox not playing sounds in manjaro i3. Turns out it requires pulseaudio which isn't installed by default.
I had "fun" playing around with it for half a day before I could get sound working.
Firefox does NOT require Pulse: I'm also on an i3 Manjaro install, with jack2-dbus and Firefox 64. No pulse. Firefox spawns and auto-connects a JACK client called 'AudioIPC Server' whenever needed...
Hmm. Did you need to install anything to get it to work? It even says online that Firefox requires pulseaudio: https://www.omgubuntu.co.uk/2017/03/firefox-52-no-sound-pulseaudio-alsa-linux
Deleted before we saved it.
Another audio server I've heard abut is sndio (www.sndio.org), which is part of the OpenBSD project and has been ported to FreeBSD, Linux and NetBSD.
What can you say about it and how do you compare it to Jack and Pulse?
I genuinely wonder if sndio is a viable alternative I heard and read many positive things about sndio.
Funny, I've actually just been fighting Jack to try to get Pulse applications to output audio when Jack is running (not gonna happen).
I'm looking forward to Pipewire, it's actually already in Arch, and they already have a working JACK subsystem, but I have no clue how to actually get into it (not going to learn right now, I just spent a bunch of time compiling radium and zyn-fusion). If it can free everything up so I can use Pulse and Jack simultaneously, or even replace it and give me real-time audio and let me play other music, I'll be super stoked.
The best way I've found to set audio up is to start qjackctl in your session, and start Jack after you've launched it, after enabling jack2-dbus and pulseaudio-jack. This will keep you from, say, watching YouTube videos while Jack is running, but you'll still be able to control hardware audio levels, which is the compromise I've settled for. This causes Pulse to hand over the hardware, while still controlling the output levels, to JACK, and lets it accept the hardware back when JACK is done with it, completely smooth, and works across distros (I just switched to Debian to be if it was going to be any different, it wasn't so I did it in Arch).
I don't want to start a Bitwig vs X war or anything, but I personally think Renoise is freaking awesome, it's cheap (like 68 euros/75 bucks) to buy, and $30 bucks to renew every full version (I bought at 2.8, we're just at 3.1.1, over five years of slow, stable development). I'm also checking out Radium, which you can build from the AUR (kjetil's builds don't run on Arch), which is an open-source, batshit-crazy tracker.
You should try cadence instead of qjackctl.
I did, the only thing it does differently is create an .asoundrc that pipes alsa output to pulse, it doesn't solve any new problems, and generally obfuscates a whole bunch of settings.
Where does gstreamer fit into all of this?
It doesn't really. GStreamer lives a layer above all the various sound systems, and doesn't actually interact with the hardware directly.
gstreamer is media framework, it contains decoders/encoders for compressed audio formats and passes the decoded audio to your selected backend which can be any of the mentioned.
What K900 said. GStreamer will also be replaced by Pipewire AFAIU. And the video part is already a lot further than the audio part. Gnome is already using it for screen sharing. And there are patches for Chrome and Firefox that are about to be sent upstream.
Very interesting post, I've learned some nice stuff reading the comments...
I would just like to say that I don't know about Bitwig, but on Reaper you can directly use ALSA and it works flawlessly, but I prefer to stick with Jack since this way I can get the output of PulseAudio as well and the latency is the same anyway...
I still hope that Pipewire will be able to offer the same performance of Jack at some time in the future.
I hadn't looked into Pipewire for a while, and call me an idiot or pedantic or something, but the moment I was reminded it is just another pure C implementation of the same thing we have had re-implemented a half dozen times because it gets too complicated and nobody wants to maintain it because its a giant steaming pile of gobject C code...
its the same feeling I get when touching Wayland, GStreamer, etc. But its more annoying to be happening in 2017+ than in 2012+ because now we actually have options like Rust, Go, C++17. All of these C libraries are thousands of lines of extremely insecure operations on raw pointers with bug trackers jammed full of memory leak or segfault exceptions for years after the first release. The onboarding of new contributors is paltry because its all ugly as hell C.
A bit off topic, but I agree. Especially considering the very good experience the librsvg team has had. They recently posted a status update on /r/rust and the general consesus was that choosing Rust was everything they'd hoped for. Pipewire would have been another excellent use case for it. But maybe it's because development has been going on for some time and Rust wasn't stable enough yet. However even then C++ could have been an option. Jack2 after all is written in C++ as well.
C libraries are the most binary compatible libraries out there. Rust and Go don't care about binary compatibility. They mostly target docker users so they don't have a reason to do so, they are not 40 years old industry hardened languages. It's impossible to produce a sane desktop environment before they change their minds completely. For C++ it's up to developer and compiler. Most of the time it works if the software is designed correctly (e.g Qt, KDE) but not everybody who writes things in C++ know that. Using C backends makes creating foreign language interfaces far a lot easier and lets us to upgrade libraries seamlessly.
Both support a C-style FFI IIRC. What do you mean by this?