http://www.raptorman18.110mb.com/Linux/ ... udio1.html
http://www.raptorman18.110mb.com/Linux/ ... udio2.html
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/
If you're wondering why one should switch to Pulseaudio, consider reading this article by Nathan Willis on Linux.com, where he mentions this very How-To.
http://www.linux.com/feature/119926
This article talks about some of the many features Pulseaudio has.
http://arstechnica.com/journals/linux.a ... y-to-linux
On with the How-To:
Pulseaudio has always been easy to configure, as it is intended to neatly replace esd. It is even easier to configure now. Just install the packages, run the command and presto.
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: Select all
apt-get install pulseaudio libao4 paprefs libpulse-mainloop-glib0 pulseaudio-module-jack pavucontrol pulseaudio-module-hal pulseaudio-module-x11 gstreamer0.10-pulseaudio pulseaudio-utils libasound2-plugins paman pulseaudio-module-gconf libgconfmm-2.6-1c2 libpulse-browse0 pavumeter libglademm-2.4-1c2a pulseaudio-esound-compat libpulse0 libpulse-dev pulseaudio-module-bluetooth pulseaudio-module-zeroconf
That command just includes the packages and modules that I just deemed most useful. All of those aren't needed, and there are other modules that add more functionality for pulseaudio such as pulseaudio-module-lirc.
After you have installed pulseaudio, copy the following into /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. On some systems the appropriate file may be /home/user/.asoundrc
Code: Select all
pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
pcm.!default {
type pulse
}
ctl.!default {
type pulse
}
Code: Select all
pulseaudio -D
Pasuspender
I never actually use this feature anymore because all my applications use pulseaudio beautifully. I use audacity as an example but audacity now works with pulseaudio out of the box. I'm just leaving this an example for other applications that may have trouble that I may not be aware of.
I would like to mention one of the newest and most useful developments in the Pulseaudio sound server and that is the pasuspend or pasuspender feature. This new feature enables Pulseaudio to automatically suspend it's lock of the audio device in order to allow other application to control the audio device. Whenever Pulseaudio is idle, meaning any application using sound is not running, it automatically suspends it's lock of the audio device, which will allow the user to open an application such as Audacity which does not natively use Pulseaudio, and Audacity will work through the ALSA sound system.
It is also possible for the user to force Pulseaudio to relinquish it's lock of the audio device. Just precede the command of the program you wish to start with the pasuspender command. For instance:
Code: Select all
pasuspender audacity
Because Pulseaudio automatically relinquishes control of the sound device and allows applications to use ALSA, this could cause a situation where you think the sound is going through Pulseaudio when it is actually going directly through ALSA. (Does that make sense?).
Well, the best idea is to check to make sure that Pulseaudio is running and that the sound is running through Pulseaudio, and there are many ways to do this.
1. If your notice that your system sounds stopped running, then the Pulseaudio daemon must not be running.
2. If you open up two application using sound simultaneously, the second one will not be able to access the sound card.
3. Open up the Pulseaudio Manager, in Applications>Sound and Video>Pulseaudio Manager, it will say if it is connected or not.
4. Run the command
Code: Select all
ps_ax | grep pulseaudio
Code: Select all
3319 ? Sl 1:31 /usr/bin/pulseaudio --log-target=syslog
3322 ? S 0:00 /usr/lib/pulseaudio/pulse/gconf-helper
26493 pts/1 R+ 0:00 grep pulseaudio
Network Audio
Playing Sounds on other computers
Mac has airport which allows you to stream Itunes to speakers that are connected to airport. Well, rather than spend some insane amount of money for airport, we can do better with Pulseaudio. Lennart Pottering the developer of Pulseaudio, is also a developer of Avahi, the network discovery daemon. So as long as the other computer is shared on the home network, Pulseaudio should be able to play sounds on it.
The catch is, first make sure you can view the network shares of both computers from the other computer. This way you can be sure that the computers can see each other. My home network works fine, so I didn't have to worry about this, so I don't know what will happen, but make sure the computers can atleast ping each other before trying anything.
Both computers must both be running Pulseaudio. I have only tried it on Linux computers, but it should work with any computer that runs Pulseaudio including Mac and Windows, but you may run into problems unique to those systems. Also you must make sure Pulseaudio is configured to share its server.
To configure Pulseaudio to share its server, you need to go into Pulseaudio Preferences which is located in System>Preferences>Pulseaudio Preferences. Then you need to enable all the options for network discovery. Here is what mine looks like.
Then you must do the same process on the networked computer you wish to share audio on. When you are done the process the Pulseaudio Preferences tray icon should appear.
The final step is to click on the Pulseaudio Preferences tray icon, and from there you can change the default Pulseaudio Server on the computer you are sitting at, to the Pulseaudio server on your networked computer, and all sounds played on the computer you are sitting at will play through the speakers on your networked computer. It is that easy!!
You will need the paprefs package to set this up. Even if you do not have gnome, I would recommend installing the gnome-system-tools in order to do this. If you absolutely against doing that you can change the default server by editing the file /etc/pulse/client.conf
Uncomment "default server" and change it to
tcp:REMOTEIP:4713
Where REMOTEIP is the IP address of the computer you want your sounds to be sent to.
Bluetooth
I will not get into using bluetooth because it works flawlessly without any setup. Basically all I had to do was pair the bluetooth headset and it appeared as a device in pulseaudio-volume-control, and you can then select which streams you want to send to the headset. Pulseaudio-volume-control is an amazing application, it's like a compiz for sound as Lennart puts it.
ProjectM
I just wanted to take a second and mention this awesome application. It is called projectm-pulseaudio. It is in the repositories. It displays awesome visualizations for pulseaudio streams, independent of the application that the sound originates from. Exaile my favorite music player removed support for visualizations, however projectm-pulseaudio will show visualizations for the music and use fewer resources while doing it. I absolutely love this application. Absolutely no setup required and it will visualize any stream, it doesn't care, it is only visualizing what is coming out of pulseaudio. Awesome!
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.
OpenAl
This is no longer necessary because OpenAl supports Pulseaudio now.
I used to need to edit my asound.conf and add dmix devices to get applications that used OpenAl to work, however mednafen now supports pulseaudio out of the box, so this is no longer needed for me atleast, but I will keep the information up for legacy applications.
Much of this is from the Dmix Wiki and it is my current personal setup. This enables me to get pulseaudio to work with some applications it wouldn't normally work with, specifically applications using OpenAl.
Code: Select all
# 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
}
![Smile :)](./../images/smilies/icon_smile.gif)
Then, try to force whatever program you are using to make use of the pcm.dsp1 device I created earlier in my asound.conf. In Mednafen I simply specify -sounddevice pcm.dsp1 and mednafen will then output through pulseaudio. However, sometime the audio can stutter and be poor, so what I do is increase the sound buffer size slightly. (The default buffersize in Mednafen is 32). This may not be needed in other applications that use OpenAl but I thought I would mention that here.
This is the command I use in Mednafen to use OpenAl through Pulseaudio
Code: Select all
mednafen -sounddriver alsa -sounddevice pcm.dsp1 -soundbufsize 64 -vdriver 0 -nes.stretch 1 -fs 1 -nes.input.port1 gamepad "$rom"
Avidemux
This is no longer necessary.
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 now uses portaudio and runs with pulseaudio out of the box. Yay!
Iceweasel
Getting flash to work used to be a headache. It really isn't anymore even if you use 64bit. When Adobe temporarily removed the 64bit flash plugin I still used an old alpha version so that Pulseaudio would continue to work. I'm not too uptight about security. You'll never get pulseaudio to work with flash using nspluginwrapper.
I recommend using the newest version of flash, the beta of square is incredibly stable, it is fast, and uses less memory than previous incarnations.
To install flash player 10, is a pretty straight forward process, just go to the site, download the archive, extract it, and replace the flash plugin that is currently on your system. WARNING: You may want to back up flash player 9 before begining this upgrade.
Copy the plugin to /usr/lib/mozilla/plugins/libflashplayer.so, there is plenty of information on how to do this so I will not go into more detail. Just know that there should be no problems using the right version of flash.
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.Use the pasuspender command
Code: Select all
pasuspender program
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 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 the commands "sudo dpkg-reconfigure pulseaudio" and "sudo dpkg-reconfigure pulseaudio-utils" to set things back to default.
6.Try a different device as stated in the Tinkering section.
7."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 creates fake OSS devices that naturally output to Pulseaudio, which allows old OSS application to run easily through Pulseaudio. This is still alpha software, very much in the testing phase, but worth mentioning.
Pulseaudio and Jack
Pulseaudio and Jack are two seperate sound servers that have two completely different purposes. Pulseaudio is great for consumer audio and jack is great for commercial audio. As a musician I have actually created music using both, which for me is possible, but it is obviously not ideal for professional audio which will need jack. Lennart Pottering the developer of Pulseaudio wrote about this and gave at talk at the 2010 Linux Audio Conference.
http://0pointer.de/blog/projects/when-p ... n-not.html
Pulseaudio has the ability to connect to jack through it's module, however, this has to be done manually and it is not trivial. Pulseaudio will however get out of jack's way when it is started. I have no problems starting jack if I start it when no applications are running which is the norm when I'm doing a music project.
The only reason one would want pulseaudio to connect to jack is if you want the streams from pulseaudio. It requires jack_transport which isn't packaged, and the whole implementation in general is a bit finicky.
However, is an e-mail sent to me by CJ Van Den Berg on the pulseaudio discussing the procedure.
https://tango.0pointer.de/pipermail/pul ... 00330.html
and here is an Ubuntu How-to based upon that e-mail that goes more in depth.
http://ubuntuforums.org/showthread.php?t=548178
Like I said, It's not something I use, but that shouldn't have kept me from posting the information sooner.
System Sounds
libcanberra has a pulseaudio library, which should make it easy to use pulseaudio to play system sounds. However, I an not currently get system sounds to work, partially because I use xfce mostly and don't use gnome often. You can however enable accessible login if you are using gdm and get sounds to play that way. You can also add a command to the autostarted applications that plays a sound on startup. For this I use the play command provided by the sox package.
Code: Select all
play /path/to/sound.ogg
Acknowledgements/Sources
By the way, Pulseaudio is in rapid devleopment. It used to be a difficult task to get sound that originates on one computer, to play on another computer over the internet. Now that process, is really simple, and uses a great GUI. It's called Pulseaudio Device Chooser. It works really well if you have multiple computers using Pulseaudio. I just though I would mention how awesome that is, and acknowledge the great work the Pulseaudio developers are doing.
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 ... omoid=BIOW
http://pulseaudio.org/wiki/PerfectSetup
http://pulseaudio.org/
http://alsa.opensrc.org/index.php?title ... Dmix_Howto
http://gentoo-wiki.com/HOWTO_ALSA_sound_mixer_aka_dmix
http://pulseaudio.vdbonline.net/libflashsupport/
http://ubuntuforums.org/showthread.php?p=4928900
http://labs.adobe.com/downloads/flashplayer10.html
I hope this How-To is helpful. I'm always available for questions, comments, additions, or positive feedback.
And maybe a little constructive criticism.
![Wink :wink:](./../images/smilies/icon_wink.gif)