PulseAudio

From ArchWiki
Revision as of 19:05, 9 November 2007 by Abelstern (talk | contribs)
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.

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

Configuration

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

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

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 of 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 won't 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

Many SDL games and applications can use PulseAudio. To make them do this, just set the variable SDL_AUDIODRIVER="esd"

Configuration of OpenAL for PulseAudio

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

(define devices '(esd))

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

Permanently change the daemon priority

Take a look at "schedtoold" [2]


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 enabled, and the pulse-cookie on 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

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