PulseAudio

From ArchWiki
Revision as of 11:03, 2 April 2008 by Abelstern (talk | contribs) (PulseAudio over network)
Jump to navigation Jump to search


Introduction

PulseAudio is a sound server for POSIX and Win32 systems. It allows to have multiple programs playing sound at one machine and even more advanced features. PulseAudio is a drop-in replacement for the enlightened sound daemon (esd) or arts if you use kde.


This article focuses on the more basic PulseAudio features.

Install

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

pacman -Sy pulseaudio 

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

pacman -Sy padevchooser paman paprefs pavucontrol

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

pacman -Sy alsa-plugins

Drop-in replacement for ESD (EsounD)

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

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 start esd (esdcompat actually) automatically as a user you should edit the file /etc/pulse/default.pa to make it use the default socket as expected by most gnome apps:

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.

Configuration

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 as root).

gpasswd -a <user> pulse-access

Now you just need to set all the applications that you use to work with pulse, possibly through a plugin.

Configuration of the ALSA PulseAudio plugin

It's 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 we need to edit /etc/asound.conf (recommended) or ~/.asoundrc 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 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/default.pa 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-hal-detect


If you haven't 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'll 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
}

Configuration of the Adobe Flash plugin for PulseAudio

The default Adobe Flash plugin for Mozilla doesn't work well with the PulseAudio plugin for ALSA so you'll get no sound but there is a way to make the Flash plugin work with PulseAudio even though you might end up with a little delay. This is done through the libflashsupport and there is a package for it on the AUR. Link : [1]

This lib version should correctly auto detect PulseAudio and work, if it doesn't we can force it to use PulseAudio. We can do this through the environment variable FLASH_FORCE_PULSEAUDIO and in order for all users to have this working without any trouble we can create the variable at the login of a user. We do this by editing the script /etc/profile.d/libflashsupport.sh (create it if it doesn't exist):

export FLASH_FORCE_PULSEAUDIO="1"
# export FLASH_AUDIODEBUG="1" If you want to see debug from the flash audio
# export FLASH_PULSEDEBUG="1" If you want to know the delay from the sound

If your PulseAudio daemon is running remotely Flash cannot autodetect it. Therefore, you'll need to specify the PULSE_SERVER environment variable:

export PULSE_SERVER=192.168.0.5

Replacing the IP address with your server's, of course.

Configuration of SDL for PulseAudio

Since SDL version 1.2.12, SDL has native pulseaudio support. 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.). If this driver does not work for you or if you are using an older version of SDL, export SDL_AUDIODRIVER="sdl" might do the trick.

Configuration of GStreamer for PulseAudio

To make GStreamer use PulseAudio, you'll need to install the gstreamer0.10-pulse package and set /system/gstreamer/0.10/default/audiosink and /system/gstreamer/0.10/default/audiosrc to the desired values:

 pacman -Sy gstreamer0.10-pulse
 gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosink pulsesink
 gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosrc pulsesrc

Alternately, you could use the gstreamer-properties application to set the gconf entries:

 gstreamer-properties

Configuration of OpenAL for PulseAudio

Games that uses OpenAL can use PulseAudio directly writing this line in ~/.openalrc:

(define devices '(esd))

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

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 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 this to /etc/pulse/default.pa:

load-module  module-native-protocol-tcp

If you're 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).

root@server ~ $ scp /var/run/pulse/.pulse-cookie client:/etc/pulse-cookie
root@client ~ $ chown pulse:pulse-access /etc/pulse-cookie
root@client ~ $ 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

That's it!

Troubleshooting

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/default.pa:

 #load-module module-x11-publish


If PulseAudio fails to start as a daemon and the message

 E: main.c: daemon startup failed.

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

.fail

Simply add a "#" as a comment in front of that line.

Audacity

According to the PulseAudio.org Wiki, Audacity doesn't currently support PulseAudio. Therefore they suggest killing pulseaudio before using it.

PulseAudio Device Chooser (padevchooser)

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

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

See also

Allow multiple programs to play sound at once

External Links

http://www.pulseaudio.org/wiki/PerfectSetup - A good guide to make your configuration perfect
http://www.alsa-project.org/main/index.php/Asoundrc - Alsa wiki on .asoundrc
http://www.pulseaudio.org/ - PulseAudio official site
http://mpd.wikia.com/wiki/PulseAudio#Version_0.12.0_and_later - Configuring MPD for PulseAudio