OSS4 on Ubuntu (Lucid Lynx)

by levien on vr 07 mei 2010 // Posted in misc // under

After upgrading to Ubuntu 10.4 LTS, I was happy to notice that audio in all applications (including Skype) was finally working perfectly! However, I was less happy to notice that Pulseaudio was using quite a lot of CPU-time, and that the sound quality was absolutely awful... So I decided to give OSS4 a try. After some googling, installing a few packages and some minor configuration, OSS4 was up and running, and I must admit the improvement in sound quality is rather significant!

To minimise the hassle, I decided to set up ALSA emulation, and initially I kept Pulseaudio as well. I configured applications with native OSS support (e.g. Audacious) to output to OSS4 directly. With the settings below, Gnome applications that use Gstreamer should output directly to OSS4 as well. Everything else will probably either use the ALSA libraries or Pulseaudio, both of which now output to OSS4. However, in the end I removed Pulseaudio altogether as the applications I used did not really require it...

Here's how I did it:

  • In a terminal, run sudo dpkg-reconfigure linux-sound-base
    Choose OSS. This should, among other things, prevent the ALSA modules from loading. Reboot.
  • There are (at least) four ways to install OSS4:
    • Install from the Ubuntu repositories (not recommended):
      sudo apt-get install oss4-base oss4-dkms oss4-source oss4-gtk
      This will automatically rebuild the OSS modules when your kernel is updated, and is the preferred way of installing third-party kernel modules. However, the oss4-dkms package is currently broken for Ubuntu ([bug #519577][https://bugs.launchpad.net/ubuntu/+source/oss4/+bug/519577]). There is a workaround, but for the time being it's best to use the package from the Opensound website.
    • Install the packages from Jason Scurtu's PPA repository. Add the package-source ppa:solard3ity/oss4 to your system (under System->Administration->Software Sources), and refresh the package lists. Then install the following packages: oss4-base oss4-dkms oss4-source oss4-gtk libflashsupport-oss4
    • Download the OSS4 binaries as a DEB package from http://www.opensound.com/download.cgi and install it. This is currently recommended, because the two methods above will break sound in the Flash plugin. The downside is that you'll manually need to reinstall the package every time your kernel is updated. Also, this package is not GPL but has a commercial one-year license.
    • Fetch the source from the Mercurial repository and compile the package yourself, as described in https://help.ubuntu.com/community/OpenSound
      This will give you the latest GPL-version of the drivers, and should work on all architectures.
  • If you get errors about snd_pcm being in use, try rebooting and running sudo soundon. If the problem persists, use lsmod to check if any ALSA modules are still loaded. If so, blacklist them manually. For instance, I had to blacklist the saa7134_alsa module by creating a configuration file /etc/modprobe.d/blacklist-saa7134_alsa.conf with the line blacklist saa7134_alsa
  • Either configure Pulseaudio to use OSS4 or remove it altogether.
    • To configure Pulseaudio with OSS4:
      Edit the default configuration file: gksu gedit /etc/pulse/default.pa
      Comment out the modules for automatic hardware detection.
      Add the following line:
      load-module module-oss device="/dev/dsp" sink_name=output source_name=input mmap=0
    • To remove Pulseaudio:
      sudo apt-get remove pulseaudio
      You will have to manually restore the volume manager icon to your panel later.
  • Configure Gstreamer for OSS4 output:
    Install gstreamer0.10-plugins-bad
    Run gstreamer-properties and set input and output to OSS.
  • Set up ALSA (or rather libasound) to output through OSS4 instead of the native ALSA drivers. Create a configuration file:
    gedit ~/.asoundrc
    Insert the following:
   type oss    
   device /dev/dsp    
   type oss    
   device /dev/dsp    
  • Add the following PPA to your Software Sources and run update-manager: https://launchpad.net/~dtl131/+archive/ppa
    This will enable Gnome audio output and volume management to use Gstreamer instead of Pulseaudio.
  • Right-click over your panel, select "Add to panel" and add the volume control applet. Alternatively, you can add a button to your panel or menu to start the OSS4 mixer (/usr/bin/ossxmix) instead of the normal Gnome volume manager.
  • Configure applications that natively support it (e.g. Audacious, Audacity, Kdenlive, SMPlayer, VLC, Wine, etc.) to use OSS output. Many applications don't (or no longer) have native support for OSS. This is no problem, these should continue to work fine through Gstreamer or ALSA emulation (or Pulseaudio if you decide to keep it).
  • After removing Pulseaudio, it could be that Rhythmbox or Movie Player start to complain about missing audiosink plugins. In that case you'll need to manually change some Gconf-keys. Start gconf-editor. Open system/gstreamer/0.10/default. Check if any keys (e.g. musicaudiosink and chataudiosink) are still set to "pulsesink". If so, change them to "osssink".

Ahem, "that's all!". Sit back and enjoy your much improved audio quality. :-)

If (for whatever reason) you decide that you want to switch back to the old situation with ALSA and Pulseaudio, here's how to do it:

  • In a terminal, run sudo dpkg-reconfigure linux-sound-base
    Choose ALSA. Reboot.
  • Remove the libasound configuration file: rm ~/.asoundrc
  • Reinstall Pulseaudio and associated packages: sudo apt-get install pulseaudio indicator-sound libcanberra-pulse pulseaudio pulseaudio-esound-compat pulseaudio-module-bluetooth pulseaudio-module-gconf pulseaudio-module-x11 ubuntu-desktop ppa-purge
  • Restore the original Pulse-based Gnome volume manager: sudo ppa-purge ppa:dtl131/ppa
  • Configure Gstreamer for Puseaudio output by running gstreamer-properties and setting input and output to PulseAudio.
  • If you manually configured applications (e.g. Audacious, Audacity, Kdenlive, SMPlayer, VLC, Wine, etc.) to use OSS4, switch them back to Pulseaudio or ALSA-output.
  • Start gconf-editor. Open system/gstreamer/0.10/audio/default. Check if any keys (e.g. musicaudiosink and chataudiosink) are set to "osssink". If so, change them to "pulsesink".
  • Remove the OSS4 package using Synaptic or with sudo apt-get remove oss-linux. Optionally you can also remove gstreamer0.10-plugins-bad and ppa-purge now.

For instance, I had to revert back to ALSA on one of my machines, because the OSS4-driver for my Nvidia HDA audio chipset failed to recognise its microphone-input... It may also be smart to (partially) revert back to the original situation before upgrading your distribution (I haven't tried that yet).