Wikia

Music Player Daemon Community Wiki

PulseAudio

Talk0
520pages on
this wiki

Description Edit

From the PulseAudio website:

PulseAudio, previously known as Polypaudio, is a sound server for POSIX and Win32 systems. A sound server is basically a proxy for your sound applications. It allows you to do advanced operations on your sound data as it passes between your application and your hardware. Things like transferring the audio to a different machine, changing the sample format or channel count and mixing several sounds into one are easily achieved using a sound server.

Setting up PulseAudio Edit

On Linux Edit

If you happen use one of the distributions with PulseAudio packages you should first try installing it from that. Other users will have to download and compile it themselves. If at all possible though, try and use a recent distro with pulse support enabled.

Once installed, you may need to take a glance at the PulseAudio first steps page for the basics of running and configuring PulseAudio.

MPD + Pulse Audio on a Headless Linux ServerEdit

Most of the documentation you will find for Pulse Audio assumes you will be running your system in normal "graphical" mode. However if you're running MPD, there's a good chance you aren't planning on logging in to your server locally! This means most of the GUI tools and examples aren't really appropriate. This section will cover using MPD + pulseaudio on a headless server where nobody is logged in locally.

Note: With this configuration MPD will spawn its own pulseaudio daemon, which will then in turn take possession of the audio device you are using. If you then log in to the system locally, you will find you have no sound (apart from MPD!)


Configuring MPDEdit

We now need to configure MPD to use pulseaudio for playback. Add the following to /etc/mpd.conf (or whatever config file your MPD instance is using)

audio_output {

        type                    "pulse"
        name                    "MPD PulseAudio Output"
#       sink                    "your-sink-name-here"

}

The 'sink' option is only required if you want to play back on something OTHER than the default sink - more on that later. For now leave that line commented out.

Don't start up MPD yet!!

Configuring Pulse AudioEdit

For the most part, the default configuration included with pulseaudio should suffice. For the purposes of this guide, we are assuming that you want to output audio from a local sound device (like a sound card or a built in speaker). If you want to do something more complicated (rtp streaming, etc) you will have to refer to the pulseaudio documentation.

By default, playback applications such as MPD will automatically spawn a pulseaudio session when they open their playback device. This is controlled by the 'autospawn' directive in /etc/pulse/client.conf:

; autospawn = yes

(the ';' character is a comment in pulseaudio's config files - in this case the statement is commented out, however as mentioned above autospawn is enabled by default). You shouldn't need to change this unless your distro has disabled autospawn for some reason.

While you are getting things sorted out, it would be helpful to have additional log messages from pulseaudio. Again, in /etc/pulse/client.conf add this statement:

extra-arguments = --log-target=syslog -vvvv


Once you have everything working you can comment this out to reduce the amount of data logged. On Ubuntu (and probably many other debian-based distros), pulseaudio will write to /var/log/user.log

Starting CleanEdit

You didn't start MPD up yet, did you? ;)

Check to see if there are any running pulseaudio daemons already:

$ ps wwup `pgrep pulse`
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mpd      18241  0.6  0.1 331796  6444 ?        Ssl  11:15   0:05 /usr/bin/pulseaudio --start

Looks like pulseaudio is already running! In this case it was started by the 'mpd' user, so someone probably started MPD already. Ensure that MPD is shut down, and then kill the pulseaudio process:

/etc/init.d/mpd stop
killall pulseaudio


At this point everything is shut down - this is important since any changes you made to the pulseaudio config files won't have been seen if pulseaudio was already running. Any time you change anything in your pulseaudio configuration, you will need to stop MPD and kill the pulseaudio daemon.

We can now start up MPD:

/etc/init.d/mpd start


As soon as MPD starts, it will open its pulseaudio device which in turn causes a pulseaudio daemon to be spawned (if one is not running already for the mpd user).

And we will now see that pulseaudio is running with our logging options we put in the client.conf file above:

$ ps wwup `pgrep pulse`
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mpd      18241  0.6  0.1 331796  6444 ?        Ssl  11:15   0:05 /usr/bin/pulseaudio --start --log-target=syslog -vvvv

Adjusting Volume / Sinks / etc.Edit

Most likely the user you are logging on to your server as is not the MPD user. Since MPD has started its own private pulseaudio session, your user account knows nothing about it! Further by default the MPD user is probably configured to not allow session logins (its shell will be /bin/false and there will be no password configured for the user).

$ pacmd list-sinks
No PulseAudio daemon running, or not running as session daemon.

There's a few ways around this:

  • Configure the MPD user to allow logins
  • Use sudo to become the MPD user

We will assume that we intend to leave the overall system configuration / security as-is so we will use sudo to become the MPD user (the -s flag tells sudo to use the shell defined in $SHELL rather than the mpd user's /bin/false non-shell):

$ sudo -s -u mpd
$ whoami
mpd

If the above command doesn't work, check the mpd user exists and your $SHELL environment variable is set correctly, or specify it directly via '-s /bin/sh'. You should not need to change mpd user's shell nor the edit /etc/passwd.

If sudo fails, try su from the root account:

$ sudo /bin/bash
# su - -s /bin/bash mpd
$ whoami
mpd

Once the whoami command says "mpd", you're good to go.

You now should be able to control MPD's pulseaudio daemon:

$ pacmd list-sinks
Welcome to PulseAudio! Use "help" for usage information.
>>> 1 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: RUNNING
	suspend cause: 
	priority: 9959
	volume: 0:   0% 1:   0%
	        0: -inf dB 1: -inf dB
	        balance 0.00
	base volume: 100%
	             0.00 dB
	volume steps: 65537
	muted: yes
	current latency: 209.85 ms
	max request: 36 KiB
	max rewind: 344 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 1
	linked by: 1
	configured latency: 210.00 ms; range is 0.50 .. 1999.82 ms
	card: 0 <alsa_card.pci-0000_00_1b.0>
	module: 4
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "AD198x Analog"
		alsa.id = "AD198x Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "HDA Intel"
		alsa.long_card_name = "HDA Intel at 0xef7f8000 irq 19"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:00:1b.0"
		sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card0"
		device.bus = "pci"
		device.vendor.id = "8086"
		device.product.id = "27d8"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "352768"
		device.buffering.fragment_size = "176384"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Internal Audio Analog Stereo"
		alsa.mixer_name = "Analog Devices AD1988B"
		alsa.components = "HDA:11d4198b,104381f6,00100200"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output: Analog Output (priority 9900)
		analog-output-headphones: Analog Headphones (priority 9000)
	active port: <analog-output>
>>>


Hopefully you see something like the output above! Here we can see that pulseaudio is running and has found our sound card no problem. In particular look at the volume and muted lines:

	volume: 0:   0% 1:   0%
	        0: -inf dB 1: -inf dB
	        balance 0.00
	base volume: 100%
	             0.00 dB
	volume steps: 65537
	muted: yes

Not going to hear anything set up like that!! Our sink is both muted and has its volume set to zero. We need to fix that. First find the index number for your sink from the output above - it is PROBABLY zero unless you have multiple sound cards:

​* index: 0

Now we can turn up the volume and unmute our source. The first 'zero' in each command below is the sink index - if your sink is index: 5 then you'd substitute '5'. Also we want to turn the volume to 100% - from the 'volume steps' above we see that there are 65537 volume steps, so to turn the volume to 100% we need to specify the highest step. 50% would be half of that number, about 32768.

$ pacmd set-sink-volume 0 65537

$ pacmd set-sink-mute 0 0

If everything has gone according to plan, you now have music playing from your output device and list-sinks will show this:

volume: 0: 100% 1: 100%
        0: 0.00 dB 1: 0.00 dB
        balance 0.00
base volume: 100%
             0.00 dB
volume steps: 65537
muted: no


If you have multiple output devices, you may still need to do a little bit of configuration. Look at the sink name above:

name: <alsa_output.pci-0000_00_1b.0.analog-stereo>

Remember the 'sink:' section in our mpd.conf file above? If you need to specify a particular output sink for MPD, then this is the name you need to copy (without the angle brackets) into that line in mpd.conf.

audio_output {
    type "pulse"
    name "MPD PulseAudio Output"
    sink "alsa_output.pci-0000_00_1b.0.analog-stereo"
}

Again, if you make changes to your pulseaudio configuration, or your MPD configuration it is wise to stop both MPD and pulseaudio completely and then start them up again to be sure you are running with your updated configuration.

On Windows Edit

Start by downloading and unzipping the Windows PulseAudio binaries .

Because MPD doesn't currently run on Windows you'll have to configure PulseAudio to allow remote TCP connections. Create a new file named default.pa in the unzipped pulseaudio-x.x.x directory. Open it with your favourite text editor and add the following text:

load-module module-native-protocol-tcp listen=0.0.0.0
load-module module-waveout

The first line will load the TCP protocol module with a single argument: listen=0.0.0.0. This argument will cause the TCP protocol module to accept connections from anywhere, instead of just from the computer PulseAudio is running on. The second line will load the module needed to play sound on Windows.

You can now simply double click on pulseaudio.exe to run it.

To prevent random people from playing audio on your computer, PulseAudio requires authentication before accepting connections. To authenticate MPD you need to copy C:\Documents and Settings\<Your Windows Username>\.pulse-cookie (generated the first time you run pulseaudio.exe) to the home directory of the user MPD is running as. Alternatively, you may add auth-anonymous=1 to the end of the load-module module-native-protocol-tcp line to disable authentication.

If you experience skipping while under load you may want to try increasing the priority of the pulseaudio.exe process. This can be done manually by right clicking on it and choosing a new priority in the Windows Process Explorer (on Windows XP, press ctrl+shift+esc (or ctrl+alt+del) to bring it up). You can also start PulseAudio by running pulseaudio.exe --high-priority to set the default priority to "High".

Setting up MPD Edit

You can check that your copy of MPD includes PulseAudio support by running mpd --version and making sure "pulse" is in the list of supported outputs.

If your copy of MPD supports PulseAudio, you just need to add a new audio_output section with the type set to "pulse". You can also specify a server and sink parameter. An example audio_output section:

audio_output {
        type    "pulse"
        name    "My MPD PulseAudio Output"
        #server  "localhost"   # optional
        #sink    "alsa_output" # optional
}

For controlling the master mixer volume with mpd, you can use the following configuration (tested with Ubuntu 10.04):

audio_output {
	type           "alsa"
	name           "MPD"
	device         "pulse"
	mixer_control  "Master"
}

## This settings have to be commented out:
#mixer_type			"hardware"
#mixer_type			"software"
#mixer_type			"disabled"

Note that this can be specified in addition to your usual outputs. This will allow you to enable and disable the PulseAudio output (and any other audio outputs) at will. You should run mpd as the logged-in user on desktop systems. Alternately, you can run in System Mode and give the mpd user membership in the pulse-access group. Good howto for system mode with networking here. (N.B. you really shouldn't do this on a desktop system: see WhatIsWrongWithSystemMode.)

For Distros where PulseAudio output is broken Edit

As PulseAudio is a ESD replacement, the ESD plugin can work in cases where PulseAudio support is missing or broken. First remove the MPD PulseAudio setting. Configure MPD to use esd as shown, this assumes that MPD and PulseAudio are running on the same system.

audio_output {
type "ao"
driver "esd"
options "host=127.0.0.1:16001"
name "esd"
}

Another solution found at Ubuntuforums.org is to replace the "ao" with "pulse", which works in some cases where ao fails.

audio_output {
type "pulse"
driver "esd"
options "host=localhost"
name "esd"
}

For Distros where PulseAudio access rights are broken Edit

If you still can't get connectivity, your mpd will possibly log to a location specified in mpd.conf, e.g. /var/mpd/errors.log, the following lines:

Feb 15 21:41 : problems opening audio device while playing "Electric Universe/Divine Design/02 - High Fly.mp3"
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

E: client-conf-x11.c: XOpenDisplay() failed
W: main.c: WARNING: called SUID root, but not in group 'pulse-rt'.
Feb 15 21:45 : Cannot connect to server in PulseAudio output "pulseaudio" (attempt 1): Connection refused

In this case, your problems are twofold:

  1. You are running mpd as user mpd which has no rights to access pulseaudio as you, the interactive user, have.
  2. You are enjoying PulseAudios X11-bell plugin which requires access to your X11 session, a right mpd was not granted before.

Solutions: To remedy cause 1, add user mpd to the pulseaudio groups so that mpd can even start pulseaudio on demand:

  $ sudo usermod -a -G pulse-access mpd
  $ sudo usermod -a -G pulse mpd
  $ sudo usermod -a -G pulse-rt mpd
To further fix cause 2, open your X11 session to mpd either by
xhost +local:mpd
or get rid of the X11-bell-plugin.

Also, if you don't have sound access from e.g. gdmflexiserver spawned sessions, it may be necessary to do either xhost +local or remove the X11-bell plugin...

An alternate solution for fixing access rights Edit

This is required in Ubuntu Jaunty.

Another solution, found on [Ubuntu Forums] is to adjust the network access permissions using the paprefs tool. On Ubuntu:
  $ sudo aptitude install paprefs
  $ paprefs

Note: For Ubuntu 10.4 (Lucid), paprefs must not be called directly but via System / Preferences / PulseAudio Preferences.

Select the following settings:

  • Enable network access to local sound devices
  • Don't require authentication

(Note: in a headless system where mpd and pulseaudio are not run under your account, you can't use your paprefs GUI to configure options for that account. Use the command line to make a system-wide change:

On all systems that need to communicate, edit /etc/pulse/default.pa and uncomment:
load-module module-native-protocol-tcp
Then on all systems for the account that will run mpd/pulseaudio, make sure ~/.pulse-cookie is the same.)
Set mpd.conf as follows and restart mpd
audio_output {
	type    "pulse"
	name    "My MPD PulseAudio Output"
}

Note: if you're running a headless configuration where you're running mpd as user "mpd" (and therefore pulseaudio as user "mpd") pulseaudio usually won't quit and restart if you do a "sudo service mpd restart".

So when you've made changes to the pulseaudio configuration (either with the GUI paprefs or with the default.pa edit above) you'll want to either "sudo service mpd stop" and then wait for the pulseaudio task to timeout on its own (use "ps wwup `pgrep pulse`" to check) or just sudo kill it once you've stopped mpd.

Then do a "service mpd start" (after which launching a client like ncmpcpp will cause mpd to relaunch pulseaudio.)

To restrict access, you may want to configure your firewall on tcp-port 4713 (I just found this through trial&error&digging, so take it with a rock of salt ;-))


Adding the right for TCP wrapper on Ubuntu 8.04(hardy)
After adjusting the network access permissions, in syslog I found a messeage like this.

pulseaudio[6389]: socket-server.c: TCP connection refused by tcpwrap

In my case, My config file /etc/hosts.deny is "ALL: ALL".

Edit hosts.allow file.
$ sudo gedit /etc/hosts.allow
In gedit add this line to make pulseaudio accept mpd in tcp port.
pulseaudio-native: LOCAL
Reboot inetd by this command
sudo killall -HUP inetd

see here. reference: FAQ-PulseAudio

Mixer settings Edit

Versions of MPD older than 0.15~alpha1 don't support pulseaudio mixers, so by default, MPD probably won't have mixer settings which work with pulseaudio. Edit your mpd.conf and uncomment the following:

mixer_type "software"

Running MPD as user Edit

As PulseAudio usually runs on a per-user session it makes sense, especially if MPD is used by a single user, to run MPD as a single user. Instructions are here: [1]

Around Wikia's network

Random Wiki