PulseAudio

From Gentoo Wiki
Jump to: navigation, search
External resources

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 (P2P and server mode).
  • Per-application volume controls
  • Better cross-platform support
  • Dynamic latency adjustment, which can be used to save power

Installation

Prerequisites

PulseAudio uses either:

Kernel

If you have an Intel HDA soundcard, you probably want the following kernel option to improve power-saving:

Kernel configuration

Device Drivers  --->
    <*> Sound card support  --->
        <*> Advanced Linux Sound Architecture  --->
            [*] PCI sound devices  --->
                <*> Intel HD Audio  --->
                    (2048) Pre-allocated buffer size for HD-audio driver

Software

Portage knows the global USE flag pulseaudio for enabling support for PulseAudio in other packages. Enabling this USE flag will pull in media-sound/pulseaudio automatically:

File/etc/portage/make.conf

USE="... pulseaudio ..."

The recommend USE flags of pulseaudio are:

→ Information about USE flags
USE flag Default Recommended Description
alsa Yes Yes Adds support for media-libs/alsa-lib (Advanced Linux Sound Architecture)
caps Yes Yes Use Linux capabilities library to control privilege
dbus Yes Yes Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc)
gdbm Yes Yes Use sys-libs/gdbm to store PulseAudio databases. Recommended for desktop usage. This flag causes the whole package to be licensed under GPL-2 or later.
glib Yes Yes Add support to dev-libs/glib-based mainloop for the libpulse client library, to allow using libpulse on glib-based programs.
orc Yes Yes Use dev-lang/orc for just-in-time optimization of array operations
udev Yes Yes Enable sys-fs/udev integration (device discovery, power and storage device support, etc)

Optional USE flags of pulseaudio are:

→ Information about USE flags
USE flag Default Recommended Description
X 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.
asyncns Yes Use libasyncns for asynchronous name resolution.
avahi No Add avahi/Zeroconf support
bluetooth Yes Enables Bluetooth Support
doc No Build the doxygen-described API documentation.
equalizer No Enable the equalizer module (requires sci-libs/fftw).
gnome No Use GConf to store user preferences on streams and so on. Don't enable this flag if you want to use a system wide instance. If unsure, enable this flag.
gtk Yes Adds support for x11-libs/gtk+ (The GIMP Toolkit)
ipv6 Yes Adds support for IP version 6
jack No Adds support for the JACK Audio Connection Kit
libsamplerate No No Build with support for converting sample rates using libsamplerate
lirc No Adds support for lirc (Linux's Infra-Red Remote Control)
oss No No Enable OSS sink/source (output/input). Deprecated, upstream does not support this on systems where other sink/source systems are available (i.e.: Linux). The padsp wrapper is now always build if the system supports OSS at all.
realtime No Makes PulseAudio use RealtimeKit (sys-auth/rtkit) to get real-time priority while running.
ssl Yes Use dev-libs/openssl to provide support for RAOP (AirPort) streaming.
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 .
systemd No Build with sys-apps/systemd support to replace standalone ConsoleKit.
tcpd Yes Adds support for TCP wrappers
test No Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore
webrtc-aec Yes Uses the webrtc.org AudioProcessing library for enhancing VoIP calls greatly in applications that support it by performing acoustic echo cancellation, analog gain control, noise suppression and other processing.
xen No Builds a special paravirtualized module for running in a Xen guest.

After setting this you want to update your system so the changes take effect:

root # emerge --ask --changed-use --deep @world

Addons

  • media-sound/pavucontrol - Pulseaudio Volume Control, a GTK+ based mixer for PulseAudio.
  • media-sound/paprefs - PulseAudio Preferences, a configuration dialog for PulseAudio.
  • KDE's Phonon integrated PulseAudio configuration and mixing, but it is not as powerful as pavucontrol or paprefs.

Configuration

Permissions

Note
This is the only supported configuration by upstream and Gentoo developers.

PulseAudio uses udev and ConsoleKit to dynamically give access to the soundcards to the currently "active" user. If you are running Systemd it will also take care of this without needing to use ConsoleKit.

To make this possible ACLs (Access Control Lists) are required:

Kernel configuration

File systems  --->
   Pseudo filesystems  --->
      [*] Virtual memory file system support (former shm fs)
      [*]   Tmpfs POSIX Access Control List

If you're not using a desktop profile, check that sys-auth/consolekit or sys-apps/systemd are installed with enabled acl USE flag and that ConsoleKit is running if you are not running Systemd:

root # /etc/init.d/consolekit status
* status: started

If not, enable it at boot time:

root # rc-update add consolekit default

When you're finished, check, if your permissions are working correctly:

user $ getfacl /dev/snd/controlC0 | grep -Eo "user:.+:" | cut -d: -f2
YOUR_USERNAME
Important
For ConsoleKit/Systemd Logind managed permissions to be respected no one may be part of the audio group (not even even the user pulse). Remove any and all users from the audio group:
root # gpasswd -d <user> audio

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.

ALSA
Note
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.

You need to install media-plugins/alsa-plugins with pulseaudio USE flag enabled:

root # emerge --ask alsa-plugins
OSS

You need to enable the following module in /etc/pulse/default.pa:

File/etc/pulse/default.pa

load-module module-oss
GStreamer

You need to set several GConf keys:

  • You can use the graphical tool gstreamer-properties (part of gnome-extra/gnome-media). Select under Audio Input and Audio Output each PulseAudio Sound Server.
  • Manual with gconftool:
user $ gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosink pulsesink
user $
gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosrc pulsesrc
  • Note that some programs might still require you to set the GStreamer output plugin manually to PulseAudio Audio Sink.
ESD

You need to enable the following module in /etc/pulse/default.pa:

File/etc/pulse/default.pa

load-module module-protocol-esound-unix

Also you need to select with eselect the PulseAudio implementation:

root # eselect esd set esdcompat
libao

You need to set the following in /etc/libao.conf:

File/etc/libao.conf

default_driver=pulse
OpenAL

You need to set the following in /etc/openal/alsoft.conf:

File/etc/openal/alsoft.conf

drivers = pulse
MPlayer

You need to set the following in /etc/mplayer/mplayer.conf:

File/etc/mplayer/mplayer.conf

ao=pulse

Without udev/systemd

Warning
Using PA without udev/systemd is 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 --oneshot 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.

Troubleshooting

No sound after installation

If you have no sound while using ALSA, consider unmute the sound card. Launch alsamixer and make sure each column has a green 00 under it (Use m to toggle mute/unmute). Install pavucontrol and check if there is any output on the pavucontrol panel when playing an audio.

Enable debug mode

To get more informations you need to set the following in /etc/pulse/daemon.conf:

File/etc/pulse/daemon.conf

log-level=debug

Afterwards restart the daemon:

user $ pulseaudio -k

Audio/Video out of sync

When using PulseAudio over your local network, you can experience out-of-sync problems. Solve this by adding tsched=0:

File/etc/pulse/default.pa

load-module module-udev-detect tsched=0

This disables time scheduling. Afterwards restart the daemon:

user $ pulseaudio -k

Dummy Output

If the only playback device is the Dummy Output, PulseAudio can not access your sound devices. Either the user has no permissions (see section Permissions or another program blocks the access. Try:

user $ fuser -v /dev/snd/*

It shows the relevant program. Close the program and reconfigure it to use PulseAudio.

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. Also PA has the ability, if certain conditions are met, to automatically switch sinks between common sampling rates, this effectively can avoid some re-sampling.

FAQ

See PA's Frequently Asked Questions.

External resources