Getting rid of pulseaudio without breaking your system

When you (occasionally) want to use a normal linux desktop
computer as a bit perfect music streamer, its
underlying sound system (called alsa) needs exclusive access to the
audio interface like an external USB DAC. However, in normal linux
desktop installations this leads to errors because of pulseaudio
sitting in the way.

Pulseaudio is sound software which is installed by default in all current linux distributions and desktop installations and acts as proxy for the “real” sound software, like alsa or OSS. Desktop environments and applications expect pulseaudio to be present and functional. So even when it would be possible to remove the pulseaudio software–which isn’t the case in many distributions– it is not a good option and could break the system configuration, preventing applications and software management from functioning properly .

For dedicated headless audiophile audio playback computers, I would
advice against installing a desktop environment and pulseaudio.

However, even though pulseaudio can’t (and shouldn’t be) un-installed, it can easily be told to stay out of the way.

Manually disabling pulseaudio

This is done by setting the parameter autospawn to off in the pulseaudio client configuration file ~/.config/pulse/client.conf. Using your favorite text editor, like gedit or nano, add the following line to that file (if it exists, or create it when it doesn’t). Replace any other line that starts with autospawn=, and make sure the line is uncommented, ie. remove the pound # sign at the beginning of such a line:

Save the file, and log off and on again for the setting to take effect.

From then on pulseaudio clients –like your desktop environment, mediaplayers and web browsers– will not be able to (re)start the real pulseaudio application (called pulseaudio daemon) when needed. This gives you control over pulseaudio, instead of the desktop environment. This of course also means that this setting prevents the pulseaudio daemon from starting at logon.

If you want to play audio using a pulseaudio client, you’ll have to start it by hand first:

Afterwards, when you want to get it out of the way again, you can simply stop pulseaudio daemon with:

Alternative: disabling pulseaudio client and stopping pulseaudio daemon on the fly

Alternatively, one may set this option and stop any running pulseaudio daemon by copying and pasting the following commands in a terminal, after having stopped any application that might use audio, like your webbrowser:

The effect is the same as the previous step, without having to log off and on again.

Disabling pulseaudio for a single command

Sometimes all you need is to run a single command, for instance aplay -l to get a list of alsa cards. For those scenario’s you don’t need to create or modify the client.conf file or kill pulseaudio. You can just use pasuspender as a pseudo shell for your command:

In fact, it’s the method I use in my alsa-capabilities script.

Some explanation

Although pulseaudio is distributed as a single package (simply called pulseaudio), it essentially consists of a server component (called “pulseaudio daemon”), a client interface which is used by modern dektops and desktop applications, like webbrowsers, called “pulseaudio clients”, utilities (like pasuspender and pacmd), and lots of “modules” (84 in my system).

Schematic of pulseaudio components
The relationship between various pulseaudio components and alsa

Whenever one of the pulseaudio clients needs to play (or record) audio, the request is targeted at the pulseaudio client interface, which communicates with the users’ pulseaudio daemon instance. If the daemon is not running, it will automatically start it, and then transfers the audio request to it. The daemon then locks the (automatic or manual) configured alsa interface, to prevent it from being used by other software. Also see David Henningsson blog “Pulseaudio buffers and protocol.” (Nov 2014).

This process, called “(auto) spawning”, is managed by the XDG-session autostart script /usr/bin/start-pulseaudio-x11, which is executed by the file /etc/xdg/autostart/pulseaudio.desktop. Like all other XDG desktop starters in that directory , it is triggered when a user logs in (in the desktop environment). Both files, the executable and the desktop file, are provided and installed by the pulseaudio package. See the diagram at the right for an overview of the relationship between the various pulseaudio components and alsa. A detailed diagram is provided by Manuel Amador.

Contrary to popular perception, the pulseaudio daemon in itself does not lock the alsa interface. It just waits for a client application to connect to the daemon, which will then lock the alsa device. This means that if one disables the autospawning, one can manually start and stop pulseaudio.

LTSP-specific instructions

I used to use LTSP for getting a remote booted mpd client. LTSP adds its own logic to the startup environement, and needs an additional setting. The LTSP startup scripts try very hard to redirect audio from the server (where audio applications normally run) to the client (in which the sound card is present and where the kernel including alsa is running) through a virtual pulseaudio interface.

Simply adding the following line to /var/lib/tftboot/ltsp/i386/lts.conf on the server disables this autoconfiguring mechanisme of pulseaudio and leaves alsa intact:

(thanks “alkisg” at #ltsp@freenode)

References

2 thoughts on “Getting rid of pulseaudio without breaking your system

  1. Hi
    i am not linux guy but my friend helped me to setup Alix2d2/voyage mpd .
    is there any need to do any thing after running your bit-perfect script?
    i mean should i run other scripts or manually disable Pulse audio ?
    Amir

Leave a Reply

Your email address will not be published. Required fields are marked *