How do ALSA and PulseAudio relate?

31

14

While trying to get my sound to work, I was wondering about the roles of ALSA and PulseAudio. I have both installed and was wondering, for example, which of them needs to know about my sound card.

Both seem to be able to use each other, there's a pulseaudio plugin for ALSA, and on my system, alsa shows up as a sound card in pulseaudio.

Which of the two does what, are they alternatives or complementary?

Hanno Fietz

Posted 2010-05-24T12:05:26.630

Reputation: 1 045

Answers

34

ALSA is the kernel level sound mixer, it manages your sound card directly. ALSA by itself can only handle one application at a time. Of course, there is 'dmix', which was written to solve this problem. (It's an ALSA module.)

PulseAudio is a software mixer, on top of the userland (like you'd run an app). When it runs, it uses Alsa - without dmix - and manages every kind of mixing, the devices, network devices, everything by itself.

In 2014, you can still run only ALSA. But unless you compile your applications for yourself and enable ALSA support everywhere - or use a source-based distribution like Gentoo - you might get mixing problems. Pre-compiled applications that distros ship are usually only built with support for Pulseaudio, not pure ALSA. Ubuntu for example prefers PulseAudio. It comes with PulseAudio by default, so every application is compiled to only use PulseAudio.

PulseAudio does have its benefits. People say that it is good for working with audio across a network, and it solves some issues with multi-channel audio streams that happened under pure ALSA. It's also supposedly easier to develop apps for PA. On the end-user side of things, it's easy to select new devices, to control volume by app, etc.

However, in the default configuration it adds a not insignificant amount of latency into the mix. This is a big con for certain types of tasks that require low latency like some games and software.

OSS is an alternative to both of these, but it's not licensed under the GPL, which makes it not likely to see a lot of adoption by distros.

Illustration:
Typical PulseAudio-powered sound systems, like Ubuntu:
Kernel: ALSA -> Userland: PulseAudio -> app1, app2, app3
In the typical Linux system, PulseAudio mixes audio from all your different apps and feeds them up the chain to ALSA.

ALSA:
Kernel: ALSA -> dmix -> Userland: app1, app2, app3
With just pure ALSA, you need dmix to mix multiple apps. Without it, ALSA can only play an audio stream from one app at a time.

OSS:
Kernel: OSS -> Userland: app1, app2, app3
With OSS, the userland apps talk directly to OSS in the kernel, which mixes the streams itself.

So to sum up, in your typical system these days, ALSA talks directly to your sound cards, and Pulseaudio talks to your apps and programs and feeds that into ALSA.

Apache

Posted 2010-05-24T12:05:26.630

Reputation: 14 755

2@Skiki - I realize the answer is outdated now, but can you please provide references where Valve has abandoned Linux? Far as I can see they're still going ahead full steam, mind the pun. – aggregate1166877 – 2014-10-15T07:32:09.280

@Shiki You updated your answer with "Valve has abandoned linux" in late June. Yet I have sources from July and August that say otherwise. Valve is still working on SteamOS and the Steam Machine, which are based on Linux. July SteamOS review: http://www.techradar.com/reviews/pc-mac/software/operating-systems/steamos-beta-1209037/review ; August Steam Machine news article: http://www.techradar.com/us/news/gaming/consoles/valve-steam-box-release-date-news-and-features-1127072

– Braden Best – 2014-10-21T18:11:01.370

@B1KMusic: Steam Machine came out with Windows 8.1 and it was done by Alienware. The Linux machine is still "WIP", no ETA. No announcements, no nothing. So that part of my answer still stands correct. – Apache – 2014-10-22T19:04:56.770

2Actually, everytime I found Pulseaudio I found PROBLEMS! Funny thing is that it seems (at least based on my experiences) to have problem also with the RT version of the kernel, that is to say...do you want an easy linux environment to play music? Are you thinking about the new UbuntuStudio? Well, think again... :D – dag729 – 2010-05-24T12:40:28.423

There is an rt (daemon) argument for PA, try launching with that. You have to add your user to "pulse-rt" group (at least on Arch) in order to be able to use it like that. Well. For Audio studio stuff, use JACK audio connector. (Jesus... a new system again? :)) Or stick to OSS. – Apache – 2010-05-24T13:33:28.323

I wonder why sound is so complicated in Linux. Graphics or networking hardware support seems to be much less diversified. – Hanno Fietz – 2010-05-24T15:07:28.250

4Oh don't think. Graphics are also a pile of.. Linux is NOT for desktop use to put it simply and bluntly. Xorg is a X server so you basically start a SERVER and you WATCH it (what a nonsense? yeah). On MAC, Windows, Haiku, GUI runs from the kernel (okay its inside the kernel). Well. It would make sense doesnt it? Also, there is no native interface. Like on Windows, Windows.Forms. On MAC Cocoa. Here, you can only use FAT toolkits, like GTK, Qt.| Network is agreed, its in kernel, its OK (okay if the manufacturer provides good driver like Intel does)... so thats it. – Apache – 2010-05-24T15:24:50.227

Sounds like a rant but its not really that. Linux is great, for servers. For desktop use ... I don't know. They should re-design ALSA, fork Kernel for desktop use and create a new GUI for that. Guess that would already solve all the current problems. (Xorg is too old, the code is too complex to maintain. No way they could solve it easier.) – Apache – 2010-05-24T15:25:52.063

3On MAC, Windows, Haiku, GUI runs from the kernel (okay its inside the kernel). Well. It would make sense doesnt it? Actually it doesn't. Remember the bad old days of "NT 4 video drivers that crapped out the system"? Yeah, that's what caused it - running crappy drivers in kernel space. Why do you think Microsoft suddenly went all up-in-arms about getting signed drivers into Windows? Bingo! Because crummy drivers were causing system crashes. Getting them signed meant getting them vetted, and a smidgeon of QA goes a long ways... – Avery Payne – 2010-05-24T17:14:31.620

Re: game development. One word: SDL. http://www.libsdl.org/intro.en/toc.html

– Avery Payne – 2010-05-24T17:19:50.140

1Avery: It supports unloadable modules now. So if it crashes, it'll simply reload the module for the graphics adapter. But as far as I know they are still modules. (Not running in the userspace.. that is unpossible). | About SDL: It s..ks. Every game writer complains about it because it gives slow performance, complicated problems, etc etc. (I won't list them, check through a search.) Even the open source transport tycoon is slow with SDL. – Apache – 2010-05-24T17:39:35.897

Okay, I'll rewrite this answer. It's outdate enough. PulseAudio stopped to be a miserable mess. The CPU problems are over too. It's the best choice now, instead of the worst one. – Apache – 2012-09-03T22:25:45.787