niedziela, 26 lipca 2009

PulseAudio, the beginning

Sound on my Linux

I thought it would be useful to gather all the information that let me configure my system in quite a neat way at one place. This includes Firefox Flash plugin using PulseAudio.

What PulseAudio is

PulseAudio is a sound server. It's not the first such a project. But this the first one I really use and it doesn't grind my gears (too much).
It's an entity consisting of libraries (and optionally a daemon), which allows you to manage sound streams on a higher abstraction level than the physical device level. It enables software mixing, sound card switching during playback, additional software amplification of the volume.
Additionally PulseAudio is network transparent.
It is a standard package in the Ubuntu distribution.

Why I need PulseAudio

In the nearest future I'm going to examine network features of this system, but the real reason of the installation was different. For a couple of years now I've been using two sound cards connected to my notebook. Usually sound comes into my head through headphones connected to the external SB Live!. The first problem with this sound card is that streams mixing has never worked - so I couldn't listen to YouTube and mplayer at the same time. The second problem - I want to hear Stepmania through the integrated sound card, YouTube on both, mplayer on the external one. ALSA by itself isn't so flexible. And we have Flash which is impossible to configure in a sensible way - it uses the default card.
And last but not least: the buggy asoundconf tool, which by the way is going to disappear soon (see the Appendix 1.).

Base configuration

GNU/Linux Debian. Lenny, with a scent of testing and unstable (Squeez and current Sid).
ALSA is the low level sound system here.

Packages You will need

ii libasound2-plugins 1.0.19-2 ALSA library additional plugins
ii pulseaudio 0.9.15-2 PulseAudio sound server

Packages making PulseAudio cool

ii padevchooser 0.9.3-2 PulseAudio Device Chooser
ii pavucontrol 0.9.8-1 PulseAudio Volume Control
ii paprefs 0.9.8-1 PulseAudio Preferences

These tools will give you GUI control over PulseAudio.

To really feel the advantages of PulseAudio

ii flashplugin-nonfree 1:2.6 Adobe Flash Player - browser plugin

This package currently downloads (Firefox about:config):

Shockwave Flash
File name:
Shockwave Flash 10.0 r22


Dependencies are going to be fulfilled by some kind of apt. Personally I use aptitude.

Details on packages selection

You have to omit the installation of flashplugin-nonfree-extrasound and pulseaudio-esound-compat. They are redundant in this configuration. This is because Adobe Flash Player 10 uses ALSA by default, so another emulation layer is not needed.

How it works

As far as I understand this, it works like that...
1) Firefox Flash Plugin sends sounds to ALSA
2) ALSA reads the configuration file (.asoundrc) in my home directory, which orders it to use an ALSA plugin (libasound2-plugins) which sends the sound to PulseAudio
3) PulseAudio gets to physical devices back through an ALSA sink
4) Let there be sound

The configuration file

From Arch Linux wiki a recipe for the .asoundconf file in the home directory:

pcm.pulse {
type pulse
ctl.pulse {
type pulse

pcm.!default {
type pulse
ctl.!default {
type pulse


By default PulseAudio doesn't act as a daemon (as the configuration file states - it's better this way). It's run per (graphical) session.

Let's assure PulseAudio is running (probably this step is redundant as the first use of PulseAudio will launch it):

pgrep pulseaudio


ps axu | grep pulseaudio

If we get a line containing pulseaudio - it's working.

If we didn't get that kind of line, we can force the PulseAudio launch by executing:

padevchooser &

We should see an icon appear in the notification area. PulseAudio has started. You can click on the icon and then on the "Manager..." menu option to see the details.

Before starting to panic because there is no sound, we should check if ALSA understood what it shoud do. Execute:
aplay -v /usr/share/sounds/alsa/Noise.wav
we should see a line like this:
ALSA <-> PulseAudio PCM I/O Plugin

Final cuts

Let's assure that every time our Desktop shows up padevchooser starts as well. You will manage to do the rest using the PulseAudio Volume Control (pavucontrol).

Appendix 1: asoundconf fades out

As the alsa-utils package changelog states:

alsa-utils (1.0.19-1) unstable; urgency=low

This upload removes alsaconf and asoundconf, two scripts which
could be used to modify certain ALSA parametres, as they caused
more problems than provided solutions, were outdated and generally

alsaconf was upstream's way to detect sound cards and generate
system-wide ALSA configurations. However, this should have been
unnecessary for a very long time, with the introduction of udev
support and its automatic hardware detection. If this isn't the
case for you, it's a bug which should be filed and fixed properly.

asoundconf was a tool introduced by Ubuntu which could be used to
generate asoundrc files for systems with special needs. The script
was not being maintained and was getting buggy, and the Debian and
Ubuntu teams have agreed to get rid of it for the next release. Users
can use Pulse or similar technologies to configure their preferred
sound devices and sinks.

-- Jordi Mallach Sat, 28 Mar 2009 12:53:02 +0100

1 komentarz:

  1. No. *Pulseaudio* *sucks* *dick*.

    My fresh Fedora (core dumped) 11 uses PA. It's incredible how sucky it is. Not only it eats like 10% of N270's computing power (which is quite a lot, given it shouldn't be doing anything while playing sounds), but also produces cracks and pauses. Get this, mplayer needs about 5 seconds to "get in sync" with audio. And I don't give a shit about its advanced resampling or whatever. I want it to work, and I'm totally fed up with linux software changing with every Moon phase...

    I'm aware of all those advanced PA feature, multi-sink, multi-source, it's all cool, but not everybody needs such stuff. I liked ALSA, I liked OSS. I'm glad my desktop FC7.92 uses ALSA, it's nice and smooth, and does all I need it to do. Right now, I would be happy to hear from ya an efficient method of pouring PA down the sink, and re-installing good-old ALSA subsystem. :P