Pulseaudio is a sound server which acts as drop in replacement for Esound. It allows users without a sound card capable of hardware mixing to playback multiple sounds at once. It also allows users to send sounds over a network. Learn more here:
http://pulseaudio.org/

Pulseaudio pretty much drops in and replaces Esound without a problem, so this How-To focuses on getting a perfect setup after it has been installed. I use a combination of Dmix and Pulseaudio to get just about every app on my desktop to work perfectly. I am assuming you have decent Linux knowledge and do not mind messing with your sound setups.

Before we can begin we have to install Pulseaudio in the first place. You can go into synaptic and search for Pulseaudio and install every package by that name, which will work, or you can try this:

Code:

sudo apt-get install pulseaudio libao-pulse paprefs libpulse-mainloop-glib0 pulseaudio-module-jack pavucontrol alsaplayer-alsa pulseaudio-module-hal pulseaudio-module-x11 libgstreamer-plugins-pulse0.10-0 pulseaudio-module-lirc pulseaudio-utils pulseaudio-module-zeroconf libasound2-plugins padevchooser paman pulseaudio-module-gconf libgconfmm-2.6-1c2 libpulse-browse0 pavumeter libglademm-2.4-1c2a pulseaudio-esound-compat libpulse0 libpulse-dev


Obviously all those are not needed but who cares. Please note that entering the above command will uninstall Esound!

After you have installed pulseaudio
add yourself and the user “pulse” to the groups “pulse” “pulse-access” “pulse-rt” and “audio” if this has not been done already.

Now copy an asound.conf from below and copy it to /etc/asound.conf. You must create the file! As we go along we will add some settings to this file in order to extend its functionality.

This is directly from the Pulseaudio Wiki.

Code:

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}


Then start the pulseaudio server with the following command:
Code:

sudo pulseaudio –system=1 –high-priority=1 -D


You can play with the command but this starts the server as a system-wide daemon and sets its priority to high.

Then go into Preferences and Sounds and check the box that says “Enable Software Mixing.” This will make Pulseaudio start automatically on startup. Another way to do this is to go into /etc/pulse/client.conf and edit a line and make it look like this:
Code:
autospawn = yes

Pulseaudio will now start whenever it is needed.

Now since you have gotten your hands wet with the Pulseaudio server lets begin to optimize the system to use Pulseaudio. Some apps will work with Pulseaudio automatically, some you must specify to use Pulseaudio, some you can fool into using Pulseaudio, and some will not work at all like Audacity. (more on Audacity later).

As far as I am concerned there are two basic setups for Pulseaudio, the default setup and what I will refer to as the “Gentoo Setup” (because it comes from the Gentoo Alsa Wiki). Both have advantages and disadvantages which I will explain.

First up is the default setup, as the name implies it is default and will work pretty much automatically.

This creates virtual Pulseaudio devices and sets them as the default outputs for Alsa. Most applications will run like this or after you tinker them a little. (refer to the Tinker section towards the end).

To enable even more applications to run you can edit you /etc/asound.conf to create virtual dmix devices which enable multiple sounds through Alsa. We keep the Pulseaudio devices but add the dmix devices. Much of this is from the Dmix Wiki and it is my current personal setup.
Code:

# Part I directly from ALSA Dmix Wiki

pcm.paul { # paul is my name, you can use your name, just make sure you use it below too
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"     
        period_time 0
        period_size 1024
        buffer_size 8192
       #format "S32_LE"
       #periods 128
        rate 44100
    }
}

pcm.dsp0 {
    type plug
    slave.pcm "paul"
}

# This following device can fool some applications into using pulseaudio
pcm.dsp1 {
    type plug
    slave.pcm "pulse"
}

ctl.mixer0 {
    type hw
    card 0
}

# Part II directly from Pulseaudio Wiki

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

# Optional, set defaults

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}

This creates virtual devices in Alsa which applications which cannot use Pulseaudio directly to play sounds. The default device is still Pulseaudio however. This setup will play every application on my system. Including Audacity.

Note on Audacity: Audacity is not compatible with Pulseaudio. There are plans to make it in the future but as of right now it does not work. The current common practice is to kill the Pulseaudio server in order to use Audacity. With my setup this is unnecessary. All you must do is delete all the lines in the asound.conf that appear after “#Optional”. Audacity will then work when you specify the correct device. You will have to add those lines back into the asound.conf in order to restore your setup to its original state. You will have to do this every time you want to use audacity. (Or you could probably write a script to do it.) Read the Troubleshooting and Tinkering sections for more details.


Next we have the “Gentoo Setup”
The Gentoo setup has the advantage of allowing many applications to work automatically, but they will still use Alsa until you specify that they use Pulseaudio. It is a bit harder to setup but may be best for some people. The disadvantage is that the “Gentoo Setup” should not perform as well as the “Default Setup” because it takes a performance hit by specifying Dmix as the Alsa output for Pulseaudio. This means sounds are mixed twice, once in dmix and once in Pulseaudio which is unnecessary. However I have found the difference to be negligable and it may be non existant on some machines.

For the “Gentoo Setup” copy the following to your /etc/pulse/default.pa

This is from the Gentoo Alsa Wiki and also the Pulseaudio Wiki.
Code:

#!/usr/bin/pulseaudio -nF

#
# This file is part of pulseaudio.
#
# pulseaudio is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# pulseaudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pulseaudio; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.


# Load audio drivers statically

#load-module module-alsa-sink sink device=dmix
#load-module module-alsa-source device=plughw: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 audio drivers automatically on access

# ALSA
add-autoload-sink output module-alsa-sink sink_name=output device=dmix
add-autoload-source input module-alsa-source source_name=input

# OSS
add-autoload-sink output module-oss device="/dev/dsp" sink_name=output source_name=input
add-autoload-source input module-oss device="/dev/dsp" source_name=input sink_name=output

#add-autoload-sink output module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#add-autoload-source input module-oss-mmap device="/dev/dsp" sink_name=output source_name=input

# Load several protocols
load-module module-esound-protocol-unix
#load-module module-esound-protocol-tcp
load-module module-native-protocol-unix
#load-module module-simple-protocol-tcp
#load-module module-cli-protocol-unix

# Load the CLI module
load-module module-cli

# Make some devices default
set-default-sink output
set-default-source input

.nofail

# Load something to the sample cache
load-sample x11-bell /usr/share/sounds/generic.wav
#load-sample-dir-lazy /usr/share/sounds/*.wav

# Load X11 bell module
load-module module-x11-bell sample=x11-bell sink=output

# Publish connection data in the X11 root window
load-module module-x11-publish

#load-module module-pipe-source
#load-module module-pipe-sink


Copy the following to your /etc/asound.conf

Code:

# Part I directly from ALSA Dmix Wiki

pcm.paul { # paul is my name, you can use your name, just make sure you use it below too
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"     
        period_time 0
        period_size 1024
        buffer_size 8192
       #format "S32_LE"
       #periods 128
        rate 44100
    }
}

pcm.dsp0 {
    type plug
    slave.pcm "paul"
}
# This following device can fool some applications into using pulseaudio
pcm.dsp1 {
    type plug
    slave.pcm "pulse"
}

# mixer0 like above
ctl.mixer0 {
    type hw
    card 0
}

# Part II directly from Pulseaudio Wiki

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

Now startup the Pulseaudio Daemon the same way I mentioned before. You'll have to kill it first if you already have it running. Remember you will have to specifically request that programs use Pulseaudio (see the Tinkering section below).

Note to Totem-xine and Gxine users: I use these applications and they do not appear to work with the above setup unless you add in the following lines to your asound.conf. If any other applications do not work, the first thing to try is to add these lines to the end of your asound.conf.
Code:

# Optional, set defaults

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}


I encourage people to play with these setups and find what works best for them. Linux is about choice! I am not going to specify which setup to use, it is up to you. Just tinker away with your sound setup. You can always revert to what you had before!


Tinkering
Getting Applications to work with Pulseaudio.
If your application does not work with Pulseaudio, I would try the following steps in this order. But before you try on your own, check the applications section of this How-To and the Pulseaudio wiki http://pulseaudio.org/wiki/PerfectSetup for directions for specific applications.

1.Try to specify that the program use the device “Pulse” [no quotes]
2.Try to specify that the program use the device “pcm.pulse” [always without quotes]
3.Try to specify that the program use the device “pcm.dsp1” (You must have an asound.conf that I created (or similar))
4.Try to specify that the program use the device “pcm.paul” or “paul” (or whatever name you used in your asound.conf)
5.Try to specify that the program use “dmix”
6.Try to specify that the program use the OSS sound driver. Then wrap the program with “padsp” [no quotes] (padsp is similar to aoss, except that it outputs to Pulseaudio and it seems to work much faster.)
7.Try deleting the lines after “#Optional” in the asound.conf


Applications
Getting specific applications to work with Pulseaudio.

I will only mention applications which do not appear at the Pulseaudio Wiki or that I am unhappy with the Pulseaudio Wiki's explination of. http://pulseaudio.org/wiki/PerfectSetup
The methods used in this section were performed using the “Default Setup” from above.

Avidemux

This one is easy, specify “Pulse” [no quotes] as the Alsa device in Edit,Preferences,Audio. Or you can tell Avidemux to use OSS and then start the application using “padsp Avidemux”
(Make sure you are using “Xvideo Accel” in Edit,Preferences,Video)

Audacity

Audacity is not compatible with Pulseaudio. There are plans to make it in the future but as of right now it does not work. The current common practice is to kill the Pulseaudio server in order to use Audacity. With my setup this is unnecessary. All you must do is delete all the lines in the asound.conf that appear after “#Optional”. Audacity will then work when you specify the correct device. You will have to add those lines back into the asound.conf in order to restore your setup to its original state. You will have to do this every time you want to use audacity. (Or you could probably write a script to do it.)

Iceweasel

Iceweasel can be tricky. First I would attempt to purge previous versions of Flash and install the latest version of flash from http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW
Then download the debian package for flashsupport.c. Compiling manually is nearly impossible.
Download
http://pulseaudio.vdbonline.net/libflashsupport/libflashsupport_1.0~2219-1_i386.deb or go here http://pulseaudio.revolutionlinux.com/PulseAudio

Install that package and then,

Code:
sudo cp /usr/lib/iceweasel/plugins/libflashplayer.so /usr/lib/libflashplayer.so


Then edit your /etc/iceweasel/iceweaselrc and change a line to look like this:

Code:
ICEWEASEL_DSP="padsp"


Now, flash should work, and work pretty well too. (I have youtube videos perfectly in sync (as if it matters)).

There are some problems which may arise if you use a video card with composite or what not. Go here for a solution:http://ubuntuforums.org/showthread.php?t=75527

Basically it says edit /usr/bin/iceweasel

find where it looks like this:

##
## Variables
##
MOZ_DIST_BIN="/usr/lib/mozilla-firefox"
MOZ_PROGRAM="/usr/lib/mozilla-firefox/firefox-bin"

and make it look like this



##
## Variables
##
##Added for composite extension to work
export XLIB_SKIP_ARGB_VISUALS=1
MOZ_DIST_BIN="/usr/lib/mozilla-firefox"
MOZ_PROGRAM="/usr/lib/mozilla-firefox/firefox-bin"

I would not recommend it if you are not using composite.


Troubleshooting

1.Make sure the Pulseaudio Daemon is currently running. Check gstreamer-properties (Multimedia Systems Selector) to be sure. It may have crashed or whatever.
2.Make sure you copied the asound.conf exactly.
3.Try copying the asound.conf to /.asoundrc (this means make a file in your home directory called “.asoundrc” [no quotes] and put the same contents as you /etc/asound.conf into it.) The file will be a hidden file. For me only asound.conf works but it may be different for other people especially if you are not on debian.
4.Try a restart
5.Try a different setup, maybe the “Gentoo Setup”
6.Try the commands “sudo dpkg-reconfigure pulseaudio” and “sudo dpkg-reconfigure pulseaudio-utils” to set things back to default.
7.Try a different device as stated in the Tinkering section.
8.“sudo apt-get alsa-utils gnome-audio” then type the command “aplay -D pulse /usr/share/sounds/startup3.wav” This will check if Pulseaudio is running and that your asound.conf or /.asoundrc is correct. Again, no quotes.

Notes

I have tried the oss2pulse daemon which emulates oss devices. It is kind of a tricky install, but it is meant to be included in Pulseaudio versions to come. Also in the works are similar projects for Alsa. The plan is to get rid of Dmix, which will mean all applications will work with Pulseaudio naturally and this How-To will no longer be needed and I will have wasted 2 hours of my life.

Acknowledgements/Sources

A special thanks to all the guys at the Pulseaudio Mailing List, without whom I would not even have Pulseaudio working.

Thanks to the forum member Rickh.

http://ubuntuforums.org/showthread.php?t=75527
http://pulseaudio.revolutionlinux.com/PulseAudio
http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW
http://pulseaudio.org/wiki/PerfectSetup
http://pulseaudio.org/
http://alsa.opensrc.org/index.php?title=DmixPlugin#The_Dmix_Howto
http://gentoo-wiki.com/HOWTO_ALSA_sound_mixer_aka_dmix
http://pulseaudio.vdbonline.net/libflashsupport/



I hope this How-To is helpful. I'm always available for questions, comments, additions, or positive feedback.

And maybe a little constructive criticism.