PulseAudio

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.

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.

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

But if need be PA can be manually installed with

Making ALSA-only applications use PA
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 is installed with pulseaudio USE flag (should be the case but it does not hurt to check) and /etc/asound.conf is edited to route them back to PA so that ALSA-only applications, too, can have improved mixing quality and per-application sound controls among other benefits.

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.

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

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.

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.

Using PA without udev
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 is 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.

Links

 * PulseAudio Homepage
 * Ubuntu Feisty LTSP PulseAudio Howto
 * PulseAudio: The Perfect Setup
 * Why you should care about PulseAudio (and how to start doing it)