Pulseaudio Fixes for Hardy Heron

   Posted by: Kaobear   in How-To, Linux, Ubuntu

This guide is specially designed to fix certain issues present with Ubuntu Hardy’s current implementation of PulseAudio and to enable equalized output. I have divided this guide into different sections, based on your needs:

Part A: Required Fixes (bug #198453)
Part B: Adobe Flash & PulseAudio Fix - i386 only(bug #192888)
Part C: Stuttering Audio Fix (bug #188226 and bug #190754)
Part D: Equalizer Support (adapted from my original research here and using updated values from the ArchLinux wiki)
Appendix A: General Tips
Appendix B: Troubleshooting Audio Playback/Mixing
Appendix C: Removal Instructions

Before you start: The purpose of this guide is to make PulseAudio work smoothly with all applications, not to fix a system that does not play sound at all.

  • If you are running Kubuntu/Xubuntu/Edubuntu, this guide is not for you (as PulseAudio is not included by default).
  • If you cannot get sound working under any circumstances, then you are probably suffering from a kernel or ALSA bug - this guide is not for you.
  • If you have a brand-new sound card that is not supported in ALSA, and you are using OSS v4 - this guide is not for you.
  • If you can get sound working in some applications but not others, or you find that audio mixing is broken - this guide is for you.

Which part(s) should I follow?
Part A is a required step you must follow, as it will enable proper PulseAudio support in most ALSA-aware applications.

Part B (i386 only) will install version 10 (beta) of Adobe’s Flash plugin, as it has better compatibility with PulseAudio.

Part C is highly recommended if you notice a lot of stuttering audio in some applications. The settings proposed in this guide work well for my system, but you may need to do some manual tweaking to get the best results for your hardware.

Part D is an optional step that enables a system-wide audio equalizer (which can be customized using any LADSPA audio processing plugin). The settings provided in this guide are ideal for laptop users who notice poor quality audio playback using their built-in laptop speakers.

Appendix A gives information on specific applications including Skype, WINE as well as SDL and OSS applications. Appendix B helps troubleshoot audio playback/mixing issues using the PulseAudio Volume Control application. Appendix C will revert all changes made by this guide (if for some reason you can’t get PulseAudio working properly).

Note 1: Changes to PulseAudio will not take effect immediately! Please remember to log out and back in after you have completed all desired steps in this guide, or reboot if you performed a kernel upgrade.

Note 2: If you still experience problems after using this guide, please follow the steps of Appendix B and report the requested information in your post.

Part A: Core Fixes (bug #198453)
This section will adjust your PulseAudio setup to allow almost every ALSA-aware application to work properly with PulseAudio. If you don’t complete this step, any ALSA applications without native PulseAudio support will block access to the sound card, preventing PulseAudio from using it simultaneously.

1. Backup important configuration files (don’t worry if you see “no such file or directory” warnings):

$ mkdir ~/pulse-backup; sudo mv ~/.asoundrc* /etc/asound.conf ~/pulse-backup/

2. Copy the base PulseAudio configuration files to the local user directory:

$ cp /etc/pulse/daemon.conf /etc/pulse/default.pa -t ~/.pulse/

3. Install the following packages to ensure proper PulseAudio functionality:

$ sudo apt-get install libasound2 libasound2-plugins libasound2-dev padevchooser swh-plugins libao-pulse libsdl1.2debian-pulseaudio ladspa-sdk

4. Create a new “~/.libao” file and set the default driver to “pulse” for libao applications:

$ echo "default_driver=pulse" >~/.libao

5. Create a new “~/.asoundrc” file:

$ gedit ~/.asoundrc

Paste the following text into the file and save:

pcm.!default {
  type pulse

ctl.!default {
  type pulse

pcm.pulse {
  type pulse

ctl.pulse {
  type pulse

pcm.equalized {
  type plug
  slave.pcm "equalizer";

pcm.equalizer {
  type ladspa

  # The output from the EQ can either go direct to a hardware device
  # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
  # to the software mixer shown here.
  slave.pcm "plughw"
  #slave.pcm "plug:dmix"

  # Sometimes you may need to specify the path to the plugins,
  # especially if you've just installed them.  Once you've logged
  # out/restarted this shouldn't be necessary, but if you get errors
  # about being unable to find plugins, try uncommenting this.
  path "/usr/lib/ladspa"

  plugins [
      label mbeq
      id 1197
      input {
       #this setting is here by example, edit to your own taste
       #bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz,
       #       1250hz, 1750hz, 25000hz, 50000hz, 10000hz, 20000hz
       #range: -70 to 30
        controls [ -1 -1 -1 -1 -5 -10 -20 -17 -12 -7 -6 -5 -5 0 0 ]

Note: Although an equalizer is defined in this configuration, it will not be used unless you follow Part D, so don’t worry.

Part B: Adobe Flash & PulseAudio Fix - i386 only (bug #192888)
The latest stable version of Adobe Flash does not work very well in conjunction with PulseAudio. Although there are workarounds available (installing the packages “libflashsupport” and “nspluginwrapper”), Flash still has stability problems when configured to use PulseAudio. The latest Flash v10 beta release works correctly, however.
WARNING: Part B is for i386 users only. 64bit users shouldn’t notice as many crashes anyway.

1. Make sure you don’t have “libflashsupport” installed, as it can cause instability:

$ sudo apt-get remove libflashsupport

2. Download and install the following packages from Intrepid’s repository:

$ wget http://archive.ubuntu.com/ubuntu/pool/multiverse/f/flashplugin-nonfree/flashplugin-nonfree_10.0.1.218+ http://archive.ubuntu.com/ubuntu/pool/main/a/alsa-lib/libasound2_1.0.16-2ubuntu1_i386.deb http://archive.ubuntu.com/ubuntu/pool/main/a/alsa-lib/libasound2-dev_1.0.16-2ubuntu1_i386.deb http://archive.ubuntu.com/ubuntu/pool/main/a/alsa-plugins/libasound2-plugins_1.0.16-1ubuntu1_i386.deb
$ sudo dpkg -i flashplugin-nonfree_10.0.1.218+ libasound2_1.0.16-2ubuntu1_i386.deb libasound2-dev_1.0.16-2ubuntu1_i386.deb libasound2-plugins_1.0.16-1ubuntu1_i386.deb

Part C: Stuttering Audio Fix (bug #188226 and bug #190754)
PulseAudio appears to create stuttering audio issues on many systems, perhaps due to the default CPU scheduler in Hardy’s shipping kernel 2.6.24-16-generic (bug #188226), buffering problems (bug #190754), or both combined. This information should hopefully solve or at least reduce these problems.

These settings are ideal for my audio card, an “Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC’97 Audio Controller (rev 01)”. They may not work as well for you, so try adjusting the fragment values if you have problems.

1. Make sure your system is up-to-date and you are using at least kernel 2.6.24-18-generic, as it provides important scheduler fixes to prevent PulseAudio skipping.

2. Add your user to the groups “pulse-access” and “pulse-rt”:

$ sudo adduser $USER pulse-access
$ sudo adduser $USER pulse-rt

3. Edit “~/.pulse/daemon.conf”:

$ gedit ~/.pulse/daemon.conf

Add the following lines to the end of the file, and save:

high-priority = yes
nice-level = -11
realtime-scheduling = yes
realtime-priority = 5
default-fragments = 8
default-fragment-size-msec = 5
resample-method = speex-float-0

Note 1: If you still notice stuttering, try modifying the fragment sizes marked in red.
Note 2: The resample method listed in blue will reduce CPU usage, potentially at the cost of some audio quality. Change back to “speex-float-3″ if you don’t care about higher CPU usage.

Part D: Equalizer Support (adapted from my original research here and using updated values from the ArchLinux wiki)
In this section we will configure a LADSPA audio processing plugin (http://www.ladspa.org/) to equalize PulseAudio output.

Here’s a quick explanation of how it works: the configuration in “~/.asoundrc” from Part A uses the LADSPA plugin named “mbeq_1197″, otherwise known as “Multiband EQ”. The integers in the section “controls” set the gain for fifteen different bands, starting at 50Hz and ending at 20Khz. You can use the “listplugins” command to get a full listing of all LADSPA plugins installed on your system, and to see the options of a particular plugin, use the “analyseplugin” command (from the package “ladspa-sdk”). To see the settings for the plugin used in this guide, therefore:

$ analyseplugin /usr/lib/ladspa/mbeq_1197.so

The settings provided in this guide are intended to help laptop users; if you notice that your sound seems “tinny” and your built-in speakers seem to “rattle” at a high volume, these settings will improve the quality of your sound immensely. The following section will configure PulseAudio to use this equalized output.

1. Edit the file “~/.pulse/default.pa”:

$ gedit ~/.pulse/default.pa

Navigate to line 32 (marked here in red):

### Load audio drivers statically (it's 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

Change the line marked in red to the following, making sure the hash symbol (this: “#”) is removed, and save changes:

load-module module-alsa-sink device=equalized

Appendix A: General Tips
Certain applications will not work correctly even with these fixes, but there are workarounds available:

  1. Skype (available in the Medibuntu repository): some special configuration is required. Open Skype’s Options, then go to Sound Devices. You need to set “Sound Out” and “Ringing” to the “pulse” device, and set “Sound In” to the hardware definition of your microphone. For example, my laptop’s microphone is defined as “plughw:I82801DBICH4,0″. Due to a bug in Skype’s ALSA support, you must also follow Part C of this guide to prevent stuttering.
  2. ZSNES: due to bug #188567 you need to change the default audio driver in this application. Run zsnes with the following parameters (note that you only need to do this once, as the default sound driver will be saved):
    $ zsnes -ad sdl
  3. WINE: please ensure you are always using the latest version of WINE, available here. The ALSA driver in WINE has been improved and should work with PulseAudio in some cases. If it doesn’t work, set the audio driver to OSS in the “Configure WINE” (winecfg) application, and use padsp as shown below.
  4. OSS applications: You must use the “padsp” wrapper (part of the “pulseaudio-utils” package) to allow OSS-compatible applications to work properly with PulseAudio. Simply invoke the application prefixed with “padsp”, e.g.:
    $ padsp quake3
  5. For everything else, please see: http://www.pulseaudio.org/wiki/PerfectSetup (though keep in mind that many steps outlined on that page are already covered in this guide)

Appendix B: Troubleshooting Audio Playback/Mixing
If you cannot get an application to play audio, or share audio with other applications simultaneously, try the following:

  1. Open the “PulseAudio Device Chooser” from Applications/Sound & Video. Click on the applet icon, and click “Volume Control…”. Click on the “Playback” tab.
  2. Run an application and allow it to play sound.
  3. Check PulseAudio Volume Control’s Playback tab and see if the application displays an entry while the application is (or should be) playing audio.

There are three possible results:

  1. The application plays audio and lists an entry in PulseAudio Volume Control.
  2. The application plays audio and does not list an entry in PulseAudio Volume Control.
  3. The application fails to play audio and does not list an entry in PulseAudio Volume Control.

Result A means the application is configured correctly and working properly with PulseAudio.
Result B means the application is not using PulseAudio, but it managed to play audio because the PulseAudio server was in a suspended state (and not accessing the sound card).
Result C is the same as result B, except that the PulseAudio server was not in a suspended state, and so the application could not access the sound card directly.

If you experience result B or C for just a few applications, those particular applications are probably buggy or using OSS output (see Appendix A). If you experience result B or C for most applications, however, your system is configured incorrectly. Ensure you have followed this guide to the letter.

If you have trouble, please reply to this thread giving the following information, and I’ll do my best to help:
1. The result of the troubleshooting steps listed above, using at least two applications if possible. Give the application names and results (A, B or C) for each.
2. The verbose output of PulseAudio, i.e.:

$ pulseaudio -k; sleep 4; pulseaudio -vv

Appendix C: Removal Instructions
If you cannot get PulseAudio to behave on your system with this guide, the following steps will restore PulseAudio to its original state.

$ sudo apt-get install flashplugin-nonfree/hardy libsdl1.2debian-alsa
$ sudo rm ~/.asoundrc* /etc/asound.conf ~/.libao ~/.pulse/daemon.conf ~/.pulse/default.pa
$ sudo cp ~/pulse-backup/asound.conf /etc/
$ cp ~/pulse-backup/.asoundrc* ~/

I hope this HOWTO can assist users that have been frustrated by certain shortcomings of PulseAudio. I do hope these fixes make it into Hardy (or at least Intrepid) in an official form, but in the meantime I have outlined the steps necessary to fix the most common problems. Additionally, the Equalizer (LADSPA) setup for PulseAudio (Part D) will most likely remain unique and apart from any “official” changes to Ubuntu, so be sure to check it out if you’re interested. Feedback is welcome!

This entry was posted on Saturday, August 9th, 2008 at 9:28:19 AM and is filed under How-To, Linux, Ubuntu. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
467 pages viewed, 78 today
354 visits, 62 today
FireStats icon Powered by FireStats knack