PulseAudio

From Gentoo Wiki
Revision as of 21:01, 12 March 2012 by Nfk (Talk | contribs)

Jump to: navigation, search

PulseAudio or PA for short is a sound server that provides a number of features on top of the low-level audio interface (ALSA) on Linux, such as:

  • Networking support
  • Per-application volume controls
  • Better cross-platform support
  • Dynamic latency adjustment, which can be used to save power

PulseAudio allows for playing audio applications on the server, while hearing it through the client's soundcard. The application running on the server sends its audio output to the Pulse server instead of the server's soundcard. The Pulse client on the client receives this output and lets Alsa process it to the client's soundcard.

Contents

Setup

PA USE flags

Currently PulseAudio has quite a few USE flags but some of them are more important than others hence only portion of the available USE flags are being explained here.


→ Information about USE flags
USE flag Default Recommended Description
alsa Yes Yes PA is the top part of an audio stack hence PA itself needs support for some form of audio output, ALSA being the most common for non-professional systems.
udev Yes Yes Provides hardware detection, helps greatly if ALSA applications are being routed via PA by default (see Making ALSA-only applications use PA).
realtime No Yes Makes PulseAudio use RealtimeKit (sys-auth/rtkit) to get real-time priority while running.
caps Yes Yes Allows PA to drop unneeded capabilities, increasing security.
orc Yes Yes Improves performance of re-sampling (available only starting with PA 1.0).
X Yes Yes Build the X11 publish module to export PulseAudio information through X11 protocol for clients to make use. Don't enable this flag if you want to use a system wide instance. If unsure, enable this flag.
libsamplerate No No Provides exceptionally CPU intensive re-samplers that are generally regarded as not worth it.
system-wide No No Allow preparation and installation of the system-wide init script for PulseAudio. Since this support is only supported for embedded situations, do not enable without reading the upstream instructions at http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode .

Relevant USE flags for other ebuilds

→ Information about USE flags
USE flag Default Recommended Description
pulseaudio No Yes Please enable this if you want to use PA on your system.

PA installation

The recommend way is to set pulseaudio USE flag for desired ebuilds and then run

root # emerge --ask --deep --newuse --update --verbose @world

But if need be PA can be manually installed with

root # emerge media-sound/pulseaudio

Making ALSA-only applications use PA

Note
Starting with media-plugins/alsa-plugins-1.0.25-r1 having it installed with the pulseaudio USE flag is enough. If you previous had followed this article, upon upgrade to a fixed version (there should also be an einfo reminder), please remove the asound.conf file.

For applications with PA support, no additional setup is required but for ALSA-only applications to be able to benefit from PA, it is highly recommended that media-plugins/alsa-plugins is installed with pulseaudio USE flag (as of media-sound/pulseaudio-1.1-r1 it's not yet pulled in as a dependency).

Note
It's highly important that udev is being used for hardware detection, else PA itself will be unable to access sound devices without custom configuration!

Fast user switching

For fast user switching to work with PA where each session has its own PulseAudio process, ConsoleKit is used to know which session is active and therefore most likely to be the desired one to be granted exclusive control over device files in /dev/snd/. To make this possible Access Control Lists (or ACL for short) are required and because /dev is usually devfs, which is a form of tmpfs, ACL support for tmpfs is a must.

Kernel configurationEnabling ACL for tmpfs

File systems  --->
   Pseudo filesystems  --->
      [*] Virtual memory file system support (former shm fs)
      [*]   Tmpfs POSIX Access Control List
Warning
For ConsoleKit managed permissions to be respected no one may be part of the audio group (not even even the user pulse). In fact, for users to be able to output sound vai PA they do not have to be part of any specific group. Also it is recommended that the acl USE flag is globally enabled (Desktop profiles do this by default).
Note
For obvious reasons ConsoleKit has to be running for this to work which is usually the case but, if it is not started by default, please enable it. In case of OpenRC, this can be accomplished using
root # rc-update add consolekit default

Without udev

Warning
Using PA without udev is highly not recommended. It should be noted that this not only breaks auto-detection but hot-plugging as whole needlessly making your life harder as well as disabling use of ConsoleKit essentially voiding the article. Please, if you have the possibility to use udev (and you most certainly have), just use it.

In case that you are using ALSA as a PulseAudio sink (output) and routing ALSA apps to PA but not using udev, you must make sure to have set a specific device to be used. Else, PulseAudio will use ALSA device "default" as sink which may be routed back to PulseAudio, forming a loop. To avoid this, add the parameter device=hw:0,0 (you can find the correct IDs by running aplay -l). In the following example, we use two soundcards, of which card 0, device 0 is used as a sink (audio output, e.g. speakers) and card 1, device 0 as a source (audio input, e.g. microphone). PulseAudio will still be able to access other cards than these but it needs these settings to avoid looping the default device in this setup.

File/etc/pulse/default.paUsing a specific ALSA device as PulseAudio sink/source

load-module module-alsa-sink device=hw:0,0
load-module module-alsa-source device=hw:1,0
Note
If you forget to specify this when using the ALSA sink/source modules, you may not notice any problems until you restart PulseAudio (e.g. by logging out and back in or rebooting). You will be left with (obviously) no audio and a slowed down desktop environment and hanging applications until you resolve the loop, restart alsasound and kill all running pulseaudio processes.

Headless server

These instructions are for setting up a headless pulse audio server. Meaning a server which has no display on it but does have speakers. This provides the ability to use the remote server's speakers for audio output.

You will get warned in a dozen places for doing this, but it is the proper method.

Server

First configure use flags and emerge the package. The system-wide use flag is masked, so we have to unmask it.

root # mkdir -p /etc/portage/profile
root #
echo "-system-wide" >> /etc/portage/profile/use.mask
root #
echo "media-sound/pulseaudio system-wide" >> /etc/portage/package.use
root # emerge --ask media-sound/pulseaudio

Add the following 2 lines somewhere in the system.pa file

File/etc/pulse/system.pa

load-module module-native-protocol-tcp auth-ip-acl=1.2.3.0/24
load-module module-alsa-sink

Replace 1.2.3.0/24 with the network mask that you want to be able to access the server.

Note
If you have multiple ALSA devices, you will need to specify the device to use by adding device or device_id to the module-alsa-sink module

Tell the init script that we really do want to do this, and then start it up.

root # echo "PULSEAUDIO_SHOULD_NOT_GO_SYSTEMWIDE=1" >> /etc/conf.d/pulseaudio
root #
rc-update add pulseaudio default
root #
rc-service pulseaudio start

Client

user $ pacmd load-module module-tunnel-sink server=1.2.3.4

server (1.2.3.4) is the IP of the server.

For a more permanent solution you can add the following to your default.pa file

File/etc/pulse/default.pa

load-module module-tunnel-sink server=1.2.3.4

Now in the pulse audio volume control you should see the remote server listed under Output Devices. Under playback you should have a button next to the Mute audio button that when clicked will let you switch that audio stream to whichever output you want.

Usage

A handy cross-desktop graphical tool is available for setting various aspects of PA. Install it with

root # emerge media-sound/pavucontrol

KDE users can to some extent use Phonon`s configuration but it is not a full replacement for pavucontrol.

Configuring other applications

Some applications need to be configured to output to PulseAudio by default. A detailed list of these can be found on the PulseAudio wiki's PerfectSetup page.

Known problems and limitations

No guarantees on actual latencies

Currently PA provides whatever latency at that moment is possible be it some milliseconds to hundreds of milliseconds without regard to what applications ask for.

In case of buffer under-run latencies are never decreased

Currently, if a buffer under-run occurs, PA buffers for longer increasing latency, but it then never tries to buffer for less until restart.

Re-sampling using up a lot of CPU time

Re-sampling can require quite a lot of computational power, PA defaults are rather conservative but in certain cases can still take a significant toll, in such cases edit /etc/pulse/daemon.conf and consider changing resample-method to something less CPU intensive, default-sample-format and default-sample-rate can also affect CPU utilization with higher bit-depth and larger difference in sample-rate generally needing more resources (e.g. re-sampling 44.1 kHz to 48 kHz is faster than re-sampling either to 192 kHz). Since re-sampling is done per each channel per input, channel configuration and number of applications can affect performance as well.

Note

Using a version of PA with Orc support can noticeably decrease CPU usage, too.


Links

Personal tools
Namespaces

Variants
Actions
Gentoo Websites logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Navigation
Toolbox
Categories