PulseAudio
From ArchWiki
| 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 |
Installation
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:
# pacman -S paprefs pavucontrol pavumeter
Obsolete:
# pacman -S padevchooser paman
Realtime scheduling
It is a good idea to allow PulseAudio to run with realtime scheduling, which can help performance. To do this, add the following lines to /etc/security/limits.conf:
@pulse-rt - rtprio 9 @pulse-rt - nice -11
Afterwards, you need to add your user to the pulse-rt group:
# gpasswd -a <user> pulse-rt
Running
PulseAudio can be started with:
$ pulseaudio --start
And stopped with:
$ pulseaudio --kill
Backend Configuration
ALSA
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
In order for ALSA to use PulseAudio you need to edit (or 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
}
pcm.!default {
type pulse
}
ctl.!default {
type pulse
}
If you omit the last two groups, Pulseaudio will not be used by default. You will then need to change the ALSA device to "pulse" in the applications that you use to make it work.
Monitor source
To be able to record from a monitor source (a.k.a. "What-U-Hear", "Stereo Mix"), use pactl list to find out the name of the source in Pulseaudio (e.g. alsa_output.pci-0000_00_1b.0.analog-stereo.monitor). Then add lines like the following to /etc/asound.conf or ~/.asoundrc:
pcm.pulse_monitor {
type pulse
device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}
ctl.pulse_monitor {
type pulse
device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}
Now you can select pulse_monitor as a recording source.
OSS
To prevent applications from using ALSA's OSS emulation and bypassing Pulseaudio (thereby preventing other applications from playing sound), remove the snd-pcm-oss module by executing:
$ rmmod snd-pcm-oss
Also, blacklist the module by adding !snd-pcm-oss to MODULES in rc.conf.
padsp 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
osspd
This method is more elaborate, but will allow you to avoid having to use a wrapper script.
You will need to add soundcore.preclaim_oss=0 to the kernel parameters and also blacklist snd-pcm-oss and snd-mixer-oss in rc.conf.
Install osspd (e.g. ossp-git from the AUR) and start it using:
/etc/rc.d/osspd start
Afterwards, add it to DAEMONS in rc.conf.
GStreamer
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
SDL
SDL in the extra repository does not provide Pulseaudio support. You will need to rebuild it from the ABS. No change to the PKGBUILD is neccessary.
OpenAL
OpenAL in the extra repository does not provide Pulseaudio support. You will need to rebuild it from the ABS. No change to the PKGBUILD is neccessary.
OpenAL Soft should be configured to use PulseAudio:drivers=pulse,alsa
libao
# pacman -Su libao-pulse
Edit the libao configuration file:
default_driver=pulse
PortAudio
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.
xine
Install xine-lib-pulseaudio from AUR - tested with Amarok 1.x
Desktop Environments
General X11
Start Pulseaudio after X using:
$ start-pulseaudio-x11
This will start Pulseaudio and load the X11 plugins.
If you use GNOME or KDE, Pulseaudio may already launch on login automatically.
X11 bell
To make Pulseaudio play a sample when an X11 bell event happens (e.g. to make your terminal go 'Ping!' instead of 'Beep!'), add the following to /etc/pulse/default.pa:
load-sample-lazy x11-bell /usr/share/sounds/freedesktop/stereo/dialog-error.ogg load-module module-x11-bell sample=x11-bell
You can also use another sample. dialog-error.ogg is provided by sound-theme-freedesktop.
GNOME
gnome-media-pulse from the AUR provides a gnome-media built with Pulseaudio support. This will provide you with a Pulseaudio-compatible Sound Preferences.
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.
Applications
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 called mpd-pulse in the AUR.
You will need to configure mpd to use Pulseaudio.
If you run a system-wide daemon, you will need to add the mpd user to the pulse-access group in order for mpd to connect to the daemon.
On a desktop, running mpd as yourself and not using the mpd user is preferred.
Alternative configurations
Surround sound systems
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.
# Default default-sample-channels=2 # For 5.1 default-sample-channels=6 # For 7.1 default-sample-channels=8
After doing the edit, you will need to restart Pulseaudio.
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.
System-wide daemon
By default, PulseAudio is run per-user and will be started automatically when it is needed. This is simpler, more efficient and more secure.
Note: This is a bad idea on a desktop. Read [What Is Wrong With System Mode].
First you need to add the "pulseaudio" daemon to /etc/rc.conf. Example:
DAEMONS=(syslog-ng network netfs crond pulseaudio)
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
Edit /etc/pulse/system.pa, and change the following region:
.ifexists module-hal-detect.so load-module module-hal-detect .else
to the following:
.ifexists module-udev-detect.so load-module module-udev-detect .else
To enable the TCP module, add (or uncomment, if already there) this to /etc/pulse/system.pa:
load-module module-native-protocol-tcp
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, 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
Zeroconf (Avahi) publishing
For the remote Pulseaudio server to appear in the PulseAudio Device Chooser (padevchooser), you will also need to add the avahi-daemon to the DAEMONS in rc.conf on both server and clients.
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. However, this will prevent Pulseaudio from directly writing to the sound card buffers, which will increase overall CPU usage.
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-udev-detect.so load-module module-udev-detect .else ### Alternatively use the static hardware detection module (for systems that ### lack udev 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-udev-detect.so #load-module module-udev-detect #.else ### Alternatively use the static hardware detection module (for systems that ### lack udev support) #load-module module-detect #.endif
Basically, this prevents module-udev-detect from loading. module-udev-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
padevchooser
If you cannot launch the PulseAudio Device Chooser, first (re)start the Avahi daemon as follows:
$ /etc/rc.d/avahi-daemon restart
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-udev-detect
in /etc/pulse/default.pa by:
load-module module-udev-detect tsched=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).
See also
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://www.pulseaudio.org/wiki/FAQ - PulseAudio FAQ