PulseAudio

From ArchWiki

Jump to: navigation, search
i18n
English
Italiano
Türkçe

PulseAudio is a sound server for POSIX and Win32 systems. It allows to have multiple programs playing sound at one machine, among even more advanced features. PulseAudio is a drop-in replacement for the enlightened sound daemon (ESD). This article focuses on the more basic PulseAudio features.

Please note, PulseAudio is not a drop-in replacement for aRts. If you use KDE 3, it is not currently possible to use PulseAudio.

Contents

Install

All packages are from the community repository so you need to have it enabled. Then, to install pulseaudio:

# pacman -S pulseaudio 

Optionally you can install some GTK front-ends for PulseAudio (recommended):

# pacman -S padevchooser paman paprefs pavucontrol pavumeter

For the applications that do not support PulseAudio and support ALSA it is recommended to install the PulseAudio plugin for alsalibs. This plugin is available in the alsa-plugins package.

# pacman -S alsa-plugins

Drop-in replacement for ESD (EsounD)

Current GNOME versions have support for starting ESD on session startup. Because PulseAudio can be used as drop-in replacement for ESD you can fool GNOME to load the PulseAudio daemon just like the traditional ESD daemon. To achieve this use the esdcompat script shipped with PulseAudio. Create a symlink from /usr/bin/esd to this script:

# ln -sf /usr/bin/esdcompat /usr/bin/esd

Now GNOME should load and make use of PulseAudio automatically on each login.

Pulseaudio uses by default a different socket (/tmp/.esd-xxxx) as the stock to prevent different users to access the same socket. If you want gnome to start esd (esdcompat actually) automatically as a user you should edit the file /etc/pulse/system.pa to make it use the default socket as expected by most gnome apps. Find the line "load-module module-esound-protocol-unix" and edit it as follows:

load-module module-esound-protocol-unix socket=/tmp/.esd/socket 

This works only if you are the only user of the computer however, as soon as a second user starts gnome on the same computer problems are likely to appear. To have a more general solution for the problem start esdcompat on a server basis. Though some users did not have to edit the above line.

Configuring your system for Pulse

System-wide daemon (optional)

By default, PulseAudio is run per-user and will be started automatically when it is needed. This is simpler, more efficient and more secure. If for some reason you need a system-wide daemon e.g. multiple users log in at the same time, do the following:

First you need to add the "pulseaudio" daemon to /etc/rc.conf. Example:

DAEMONS=(syslog-ng ipw3945d network netfs crond fam hal avahi-daemon pulseaudio)

To use the PulseAudio Device Chooser (padevchooser), you might also need to add the 'avahi-daemon' to this list.

Then you need to add the user(s) to the pulse-access group, even for root (if you want to have sound:

# gpasswd -a <user> pulse-access

If you run PulseAudio as a daemon you will have to edit /etc/pulse/system.pa when you configure PulseAudio. If you run PulseAudio on a per-user basis you will have to edit /etc/pulse/default.pa.

Permissions for per-user daemon

It is a good idea to add your user to the pulse-rt group, this can help performance but does not seem to be done automatically in installation.

# gpasswd -a <user> pulse-rt

Configuration of the ALSA PulseAudio plugin

It is recommended to configure ALSA for PulseAudio, since most applications use ALSA. This is done through the PulseAudio plugin for alsalibs (the ALSA PulseAudio plugin is available through the alsa-plugins package). In order for ALSA to use PulseAudio you need to edit (and most likely create) /etc/asound.conf (system wide settings) (recommended) or ~/.asoundrc (settings on a per user basis) to have these lines:

pcm.pulse {
    type pulse
}
ctl.pulse {
    type pulse
}

pulse in pcm.pulse and ctl.pulse is just the name, you can change it but it would change the next steps.

If you want ALSA to use PulseAudio by default (every program using ALSA as sound output will now use the PulseAudio plugin for ALSA) you should also add this to /etc/asound.conf or ~/.asoundrc:

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

If you selected pulse to be your default device you need to either specify the hardware device to PulseAudio in /etc/pulse/system.pa if you are using the PulseAudio daemon or in /etc/pulse/default.pa if you are using PulseAudio on a per-user basis. Example:

load-module module-alsa-sink device=hw:0
load-module module-alsa-source device=hw:0

or you can use automatic detection using hal with:

load-module module-udev-detect

The above line should be set by default in /etc/pulse/system.pa when running pulse as a system daemon or in /etc/pulse/default.pa when running pulse in per-user mode. It is "module-hal-detect" in older versions of pulseaudio. Make sure it is uncommented.

If you have not configured PulseAudio as the ALSA default, you need to change the ALSA device to "pulse" in the applications that you use to make it work.

Multiple PulseAudio ALSA devices

If you want to use multiple sound cards or multiple virtual PCMs of your sound card (for example, to separate front and rear outputs), you will need to tell PulseAudio to use multiple ALSA sinks:

load-module module-alsa-sink device=front
load-module module-alsa-sink device=rear

If you want the client to have separate Pulse/ALSA outputs for each device, edit /etc/asound.conf or ~/.asoundrc:

pcm.pulsefront {
    type pulse
    device front
}
pcm.pulserear {
    type pulse
    device rear
}

And specify the appropriate ctl elements:

ctl.pulsefront {
    type pulse
    device front
}
ctl.pulserear {
    type pulse
    device rear
}

To list the available ALSA devices:

$ aplay -L

If you have a multichannel soundcard you can for example route the sound from player1 to the front channels and the sound from player2 to the rear channels.

User the aplay command as listed above:

$ aplay -L

Now edit your /etc/pulse/system.pa or /etc/pulse/default.pa (see Configuration of the ALSA PulseAudio plugin) and add the desired outputs. Example:

 load-module module-alsa-sink device=front
 load-module module-alsa-sink device=surround51

Disable load-module module-detect if you just want to show up those two devices in the Output Devices section of pavucontrol.

Configuration of GStreamer for PulseAudio

To make GStreamer use PulseAudio, you will need to install the gstreamer0.10-pulse package:

# pacman -S gstreamer0.10-pulse

Then, execute gstreamer-properties (part of gnome-media package) and select PulseAudio Sound Server in both Audio Input and Output. Alternatively, this can be done by setting the gconf variables /system/gstreamer/0.10/default/audiosink to pulsesink and /system/gstreamer/0.10/default/audiosrc to pulsesrc:

 $ gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosink pulsesink
 $ gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosrc pulsesrc

Some applications (like Rhythmbox) ignore the audiosink property, but rely instead on musicaudiosink, which can't be configured using gstreamer-properties but needs to be manually set using gconf-editor or the gconftool-2:

 $ gconftool-2 -t string --set /system/gstreamer/0.10/default/musicaudiosink pulsesink

Configuration of SDL for PulseAudio

Since SDL version 1.2.12, SDL has native pulseaudio support. Add this to your .profile or similar:

export SDL_AUDIODRIVER="pulse"

to use it. Other environment variables to configure: set PASERVER to the host of the PulseAudio server and set PADEVICE to the device used on the server. (the "pulse" driver has no support, yet, for reading your pulseaudio configuration, it seems.).

Or, if this driver does not work for you or if you are using an older version of SDL,

export SDL_AUDIODRIVER="esd"

might do the trick.

Note: You may need to use the ABS to compile SDL with pulseaudio support. Until the quality of the driver is fixed upstream, please use the patch located here: SDL PulseAudio Patch. It should fix most if not all the sound issues you may be having. You might have luck with sdl-pulse in AUR.

Configuration of OpenAL for PulseAudio

OpenAL Soft

Latest OpenAL Soft, an implementation of OpenAL, supports PulseAudio starting from release 1.8.466. By default OpenAL Soft will try first to open ALSA and OSS, and there is currently an issue with alsa output. Instead OpenAL Soft should be configured to use PulseAudio via /etc/openal/alsoft.conf:

# drivers=pulse

This setting has been tested with warzone2100 & Glest.

Configuration of libao for PulseAudio

# pacman -Sy libao-pulse

Edit /etc/libao.conf, add:

default_driver=pulse

Using OSS apps with PulseAudio wrapper

If you have a program that uses OSS you can make it work with PulseAudio by starting it with padsp:

$ padsp OSSprogram

A few examples:

$ padsp aumix
$ padsp sox foo.wav -t ossdsp /dev/dsp

If you prefer you can rename the program OSSprogram-real and replace it with a script like this:

#!/bin/sh
if test -x /usr/bin/padsp ; then
    exec /usr/bin/padsp /usr/bin/OSSprogram-real "$@"
else
    exec /usr/bin/OSSprogram "$@"
fi

PulseAudio with KDE 4

Add the following lines to your /etc/asound.conf:

 pcm.phononpulse {
   type plug
   slave.pcm {
     type pulse
   }
   hint {
     show on
     description "PulseAudio"
   }
 }

Now you can change the output device in "System Settings -> Multimedia -> Device Preference" to PulseAudio.

Remember, if you have added the pcm.!default lines to your asound.conf you cannot switch between the ALSA and the PulseAudio playback.

PulseAudio over network

One of PulseAudio's magnificent features is the possibility to stream audio from clients over TCP to the server running the PulseAudio daemon, allowing sound to be streamed through your LAN. To accomplish this, one needs to enable module-native-protocol-tcp, and copy the pulse-cookie to the clients. To enable the TCP module, add (or uncomment, if already there) this to /etc/pulse/system.pa:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/16

To allow remote connections to the TCP module, you also have to remember to unblock the service in /etc/hosts.allow with for example the following line:

pulseaudio-native: ALL

If you are running a system-wide PulseAudio instance, which makes sense for networked audio, the cookie is located in /var/run/pulse/.pulse-cookie. This cookie needs to be sent to the client and placed somewhere the pulse-access group can read (and with permissions so only they can read it). Alternatively, you may add auth-anonymous=1 to the end of the load-module module-native-protocol-tcp line to disable authentication.

# scp /var/run/pulse/.pulse-cookie client:/etc/pulse-cookie
# chown pulse:pulse-access /etc/pulse-cookie
# chmod 640 /etc/pulse-cookie

The pulse client needs to know where to look for the cookie. /etc/pulse/client.conf:

### Cookie file
cookie-file=/etc/pulse-cookie

Then the client needs to be configured to connect to the specified server. /etc/pulse/client.conf:

## The default server to connect to
default-server=192.168.0.5

Pulseaudio through JACK

The JACK-Audio-Connection-Kit is popular for audio work, and is widely supported by Linux audio applications. It fills a similar niche as Pulseaudio, but with more of an emphasis on professional audio work. In particular, audio applications such as Ardour and Audacity (recently) work well with Jack. Pulseaudio provides module-jack-source and module-jack-sink which allow Pulseaudio to be run as a sound server above the JACK daemon. This allows the usage of per-volume adjustments and the like for the apps which need it, play-back apps for movies and audio, while allowing low-latency and inter-app connectivity for sound-processing apps which connect to JACK.

To use pulseaudio with JACK, JACK must be started up before pulseaudio, using whichever method you prefer. Pulseaudio then needs to be started loading the 2 relevant modules. Edit /etc/pulse/default.pa, and change the following region:

### Load audio drivers statically (it is probably better to not load
### these drivers manually, but instead use module-hal-detect --
### see below -- for doing this automatically)
#load-module module-alsa-sink
#load-module module-alsa-source device=hw:1,0
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#load-module module-null-sink
#load-module module-pipe-sink

### Automatically load driver modules depending on the hardware available
.ifexists module-hal-detect.so
load-module module-hal-detect
.else
### Alternatively use the static hardware detection module (for systems that
### lack HAL support)
load-module module-detect
.endif

to the following:

### Load audio drivers statically (it is probably better to not load
### these drivers manually, but instead use module-hal-detect --
### see below -- for doing this automatically)
#load-module module-alsa-sink
#load-module module-alsa-source device=hw:1,0
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#load-module module-null-sink
#load-module module-pipe-sink
load-module module-jack-source
load-module module-jack-sink

### Automatically load driver modules depending on the hardware available
#.ifexists module-hal-detect.so
#load-module module-hal-detect
#.else
### Alternatively use the static hardware detection module (for systems that
### lack HAL support)
#load-module module-detect
#.endif

Basically, this prevents module-hal-detect from loading. module-hal-detect will always try to grab your sound-card (JACK has already done that, so this will cause an error). Also, the jack source and sink must be explicitly loaded.

Pulseaudio from within a chroot (ex. 32-bit chroot in 64-bit install)

Since a chroot sets up an alternative root for the running/jailing of applications, pulseaudio must be installed within the chroot itself ("pacman -S pulseaudio" within the chroot environment).

Pulseaudio, if not set up to connect to any specific server (this can be done in /etc/pulse/client.conf, through the PULSE_SERVER environment variable, or through publishing to the local X11 properties using module-x11-publish), will attempt to connect to the local pulse server, failing which it will spawn a new pulse server. Each pulse server has a unique ID based on the machine-id value in /var/lib/dbus. To allow for chrooted apps to access the pulse server, the following directories must be mounted within the chroot:-

/var/run
/var/lib/dbus
/tmp
~/.pulse

/dev/shm should also be mounted for efficiency and good performance. Note that mounting /home would normally also allow sharing of the ~/.pulse folder.

For specific direction on accomplishing the appropriate mounts, please refer to the wiki on installing a bundled 32-bit system, especially the additional section specific to Pulseaudio.

Troubleshooting

authkey.c: Failed to open cookie file '/home/<user>/.esd_auth': Permission denied

If this error message appears in /var/log/errors.log, then add:

if [ -e /var/run/pulse/.esd_auth ]; then
  chown pulse:pulse-access /var/run/pulse/.esd_auth
  chmod 640 /var/run/pulse/.esd_auth
fi

before "add_daemon pulseaudio" in /etc/rc.d/pulseaudio.

module-x11-publish

If PulseAudio fails to start and the messages

 x11wrap.c: XOpenDisplay() failed
 module.c: Failed to load  module "module-x11-publish" (argument: ""): initialization failed.
 main.c: Module load failed.
 main.c: failed to initialize daemon.

appear in your logs, you need to disable module-x11-publish in /etc/pulse/system.pa:

 #load-module module-x11-publish

"daemon startup failed"

If PulseAudio fails to start as a daemon and the message

 E: main.c: daemon startup failed.

appears, you may need to disable the line in /etc/pulse/system.pa that reads

.fail

Simply comment that line.

Glitches and high CPU usage since 0.9.14

The PulseAudio sound server has been rewritten to use timer-based audio scheduling instead of the traditional interrupt-driven approach. Timer-based scheduling may expose issues in some Alsa drivers. To turn timer-based scheduling off, replace the line:

load-module module-hal-detect 

in /etc/pulse/default.pa by:

load-module module-hal-detect tsched=0

Audacity

Note: As of Audacity 1.3.8, PulseAudio and other non-mmap ALSA devices are supported without killing PulseAudio. Upgrading to this version is recommended.

According to the PulseAudio.org Wiki, Audacity does not currently support PulseAudio. Therefore they suggest killing pulseaudio before using it. look here

PulseAudio device chooser (padevchooser)

If you cannot launch the PulseAudio Device Chooser, first (re)start the Avahi daemon as follows:

$ sudo /etc/rc.d/avahi-daemon restart

VLC

If you are having audio problems with the audio playback of DVDs in VLC, uninstall VLC and install the vlc-nightly package from the AUR, and set the audio output method to "Pulseaudio".

Alternative: vlc-pulse from AUR

mpd

There is a pulseaudio enabled version of mpd in the AUR. You will need to add the mpd user to the "pulse-access" group in order for mpd to connect to the daemon.

module-hal-detect

If you receive an error message about HAL, module-hal, or something along those lines, you will need to remove module-hal-detect from your /etc/pulse/system.pa and explicitely specify the ALSA devices yourself, for example:

load-module module-alsa-sink device=hw:0
load-module module-alsa-source device=hw:0

No sound after install

If you experience no audio output via any means while using ALSA as your default device, you may have to unmute your sound card. To do this, you will want to launch alsamixer and make sure each column has a green 00 under it (this can be toggled by pressing 'm')

$ alsamixer -c 0

Sometimes the snd_pcsp driver conflicts with the snd_hda_intel driver (for those of you using Intel cards) and no sound output is experienced. To fix this, you can blacklist the snd_pcsp driver in the MODULES array of /etc/rc.conf (by appending !snd_pcsp).

I have a surround sound card, but PulseAudio uses just the front speakers.

Many people have a surround card, but have speakers for just two channels, so PulseAudio cannot really default to a surround setup. To enable all the channels, edit /etc/pulse/daemon.conf: uncomment the default-sample-channels line (i.e. remove the semicolon from the beginning of the line) and set the value to 6 if you have a 5.1 setup, or 8 if you have 7.1 setup etc. After doing the edit, restart pulseaudio daemon.

# Default
default-sample-channels=2
# For 5.1
default-sample-channels=6
# For 7.1
default-sample-channels=8

PortAudio applications

The current binary of PortAudio in the community repository does not support PulseAudio and non-mmap audio devices. This can be remedied by building PortAudio from ABS and applying a patch to the sources.

Amarok

Install xine-lib-pulseaudio from AUR - tested with Amarok 1.x

See also

External links

Personal tools