Search:  
Gentoo Wiki

HOWTO_Set_up_a_system-wide_equaliser_with_ALSA_and_LADSPA


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Note about possible problems

(this note is not by the original author, it's by another user who just mostly fixed the issues below)

A lot of information in this howto is very useful.

But the mbeq-32bit bzipped archive and other changes, seem to break the current Gentoo x86_64 systems.

ladspa-sdk swh-plugins

is fine to emerge,

but only after figuring out how to delete the files from mbeq-32bit which this article shows how to install

and only after removing /etc/asound.conf

was I able to have a working netscape-flash

(of course, not with alsa-libs-1.0.16 and associates but downgraded to 1.0.14)


Introduction

Many people find that the sound produced by their audio hardware isn't quite what they'd hoped, especially with inexpensive devices. An equaliser allows specific frequency groups to be made louder or softer, and goes a long way towards counteracting the imperfections in many audio devices. Whether it be a pair of earbuds that are lacking in bass response, or a pair of speakers that just sound "cold", an equaliser will go a long way to improving the listening experience.

This article will explain how to set up a software equaliser that will affect just about all audio played through the system. There are a few limitations, the most obvious being that AC3 and DTS streams digitally passed to an external amplifier won't be affected, but it is possible to work around this (for example by decoding the AC3/DTS stream in software and using an analogue multi-channel connection to the amplifier instead.)

Required software

This guide assumes the system is using ALSA, and the "default" PCM device should be rerouted through the equaliser. This means that most programs will automatically start using the equaliser, unless they've been manually set to use a different audio device instead.

The equaliser plugin uses the LADSPA audio processing library, so this will need to be installed. The equaliser plugin used here is the "mbeq" plugin, which is part of the "swh-plugins" library.

emerge -av ladspa-sdk swh-plugins

Configuration

Since each audio environment is different, the exact values of the equaliser controls will need to be configured manually. The easiest way to do this is to open an audio program with LADSPA support (such as Audacious, or XMMS with the LADSPA plugin installed) and enable the plugin there, as this will allow the equaliser controls to be adjusted and the result heard in real-time. (The alternative is to edit the ALSA configuration file by hand, and restart playback after each change.)

Testing with Audacious

To work out the equaliser settings using Audacious (v1.4 or newer, v1.3 doesn't work with ALSA or LADSPA properly), go into the Preferences and under Plugins, on the Effects tab, enable LADSPA. Make sure the main Audacious EQ has been switched off of course! Click the Preferences button to configure the LADSPA interface and you should see a long list of possible plugins. Scroll down to the Multiband EQ (ID #1197) and add it. When you configure the EQ plugin, you should see a list of controls (see screenshot on the right.) Adjust these while listening to a song (remembering that there may be a few seconds latency) and when you're happy with the sound of the audio move on to the next step.

(If you're coming back here to tweak your EQ settings once everything is working, don't forget to disable the system-wide EQ while you're fiddling, otherwise you'll have two EQs going and the new values you copy into the system-wide configuration will be incorrect.)

Remember that in a digital system amplifying audio can result in clipping and distortion, so avoid setting the EQ values above zero if at all possible. If there is a need to increase the sound level (for example to improve bass response) far better results will be obtained by reducing the level of all the other controls instead. This will of course make the audio sound quieter, but turning the volume up on an analogue amplifier is far better than hearing loud clicks and pops every time a particularly strong bass note is played.


System-wide setup

Once you have the values for the equaliser, these need to be copied into an ALSA configuration file. Here we will be using the system-wide configuration file /etc/asound.conf but the user-specific ~/.asoundrc should work just as well. If you've never tweaked ALSA before then you won't have these files, so create one of them anew.

File: /etc/asound.conf
pcm.eq {
  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:0,0"
  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 {
        # These are the values copied straight from the EQ plugin in
        # Audacious.  (See screenshot above.)
        controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
      }
    }
  ]
}

# Redirect the default device to go via the EQ - you may want to do
# this last, once you're sure everything is working.  Otherwise all
# your audio programs will break/crash if something has gone wrong.
pcm.!default {
  type plug
  slave.pcm "eq"
}

# Redirect the OSS emulation through the EQ too (when programs are run through "aoss")
pcm.dsp0 {
  type plug
  slave.pcm "eq"
}

Testing and Activation

ALSA plugins can be quite difficult to get functioning properly, so some testing may be required. Once the configuration above has been entered, it should be possible to play a file normally - pick one that is very obvious as to whether it is using the EQ or not.

# Bypass the EQ and play direct to the hardware
aplay -Dplughw:0,0 test.wav

# If the device is in use, try bypassing the EQ and playing to the software mixer
aplay -Dplug:dmix test.wav

# Manually specify the EQ
aplay -Dplug:eq test.wav

# Use the default device, once it has been redirected via the EQ
aplay test.wav

Once the final test above (to the default device) is working, all ALSA programs should direct their audio via the EQ. Most programs will need to be restarted to pick up the new configuration, and if their output device has been changed it may need to be set back to "default". Don't forget to disable any program-specific equalisers that may still be active!

Advanced Configuration

Audio in 32-bit programs under amd64

If you're running a 64-bit system, the plugins installed in this guide will be 64-bit too. This means that when a 32-bit program tries to play audio, it will attempt to load a 32-bit version of each LADSPA plugin, which will of course fail as only 64-bit versions are present. There is one known workaround for this, and that is to install 32-bit versions of all the plugins in use into /usr/lib32/ladspa, and then change the global LADSPA search path to first look in /usr/lib64/ladspa, followed by /usr/lib32/ladspa. This means 64-bit programs will find the plugins in /usr/lib64/ladspa, while 32-bit programs will fail to load anything from /usr/lib64/ladspa, but then they'll move on to /usr/lib32/ladspa where they'll be able to load plugins successfully.

This is done by editing the default LADSPA search path, in /etc/env.d/60ladspa:

File: /etc/env.d/60ladspa
LADSPA_PATH=/usr/lib64/ladspa:/usr/lib32/ladspa

Then run env-update to pick up this change, then either log out and back in, or run . /etc/profile in any shells that need the new config (once this has been done correctly, typing echo $LADSPA_PATH will show the value above.) 32-bit programs can now be loaded from this shell to use the new config. If 32-bit programs are loaded via some other method (e.g. desktop icons) then a restart is probably best, to guarantee the updated settings apply to the whole system.

Make sure you do not have a path statement in your ALSA config, as this will override the new system default.

The 32-bit plugins now need to be installed into /usr/lib32/ladspa. I am not aware of a method to do this on the same Gentoo system (other than perhaps a 32-bit chroot), so if someone works this out please update this section. The method I used was to simply copy the one plugin I use, mbeq_1197.so from /usr/lib/ladspa on a 32-bit PC. This of course won't copy any dependencies, as you can tell by using the ldd program:

$ ldd mbeq_1197.so
       linux-gate.so.1 =>  (0xffffe000)
       libfftw3f.so.3 => not found
       librt.so.1 => /lib32/librt.so.1 (0xf7f5b000)
       libm.so.6 => /lib32/libm.so.6 (0xf7f35000)
       libc.so.6 => /lib32/libc.so.6 (0xf7e05000)
       libpthread.so.0 => /lib32/libpthread.so.0 (0xf7ded000)
       /lib/ld-linux.so.2 (0x56555000)

Here libfftw3f.so was not found, so copy libfftw3* from a 32-bit system's /usr/lib to your own /usr/lib32. This solves the problem:

$ ldd mbeq_1197.so 
       linux-gate.so.1 =>  (0xffffe000)
       libfftw3f.so.3 => /usr/lib32/libfftw3f.so.3 (0xf7dfa000)
       librt.so.1 => /lib32/librt.so.1 (0xf7df1000)
       libm.so.6 => /lib32/libm.so.6 (0xf7dcb000)
       libc.so.6 => /lib32/libc.so.6 (0xf7c9b000)
       libpthread.so.0 => /lib32/libpthread.so.0 (0xf7c83000)
       /lib/ld-linux.so.2 (0x56555000)

If you do not have access to a 32-bit machine to copy the files from, you can download the mbeq plugin including dependencies, and extract it by running cd / ; tar jxvf /path/to/mbeq-32bit.tar.bz2.

From this point, 32-bit programs should be able to play audio through the equaliser, and be mixed in with audio from 64-bit programs thanks to dmix.

The most common use for this will probably be to get audio out of Adobe/Macromedia Flash v9 which uses ALSA natively, and only a 32-bit version of the plugin exists at the time of writing. Even using nspluginwrapper to run the 32-bit plugin under a 64-bit browser like Firefox will still require 32-bit LADSPA plugins, otherwise Flash will be unable to play audio. (An easier alternative would be to define an alternate PCM device that doesn't use the EQ, and then point Flash at that second device instead - but unfortunately you can't change the ALSA device that Flash uses.)

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Set_up_a_system-wide_equaliser_with_ALSA_and_LADSPA"

Last modified: Fri, 05 Sep 2008 06:34:00 +0000 Hits: 5,295