ALSA Equalizer & Crossfeed on Debian Stable (Squeeze)

This is for ALSA, and is not suitable for systems using pulseaudio.

The aim:
to have a real time, audio equalizer (optionally systemwide if preferred)

to have high quality crossfeed to enhance playback with headphones

to have the option to use the above with all apps (systemwide) and otherwise to be able to choose or toggle the eq and crossfeed on/off when using mpd or mplayer.

What is needed:
ALSA uses plugins via an API called LADSPA. The Debian package swh-plugins contains a good LADSPA equalizer plugin, mbeq. A very nice crossfeed DSP, bs2b-ladspa, is available. The best real time controller for the equalizer is alsaequal, which isn’t in Debian Squeeze but is very easy to build (it’s available in Debian Testing/Wheezy).

Install mbeq, bs2b, and anything necessary to build alsaequal:

# apt-get install build-essential caps libasound2-dev libasound2-plugins bs2b-ladspa swh-plugins

Obtain alsaequal:

$ wget http://www.thedigitalmachine.net/tools/alsaequal-0.6.tar.bz2

Build alsaequal:
This only takes a minute.
Unpack alsaequal-0.6.tar.bz2 and after cd into alsaequal:
$ make
# make install

Create a suitable ~/.asoundrc:
The following ~/.asoundrc assumes use of the default soundcard with dmix as the default mixer because on 99% of systems this is how ALSA is automatically set up. If you have multiple sound cards and want to set one as default this can be done by editing /etc/modprobe.d/alsa-base.conf. For example I have an integrated hda-intel card and a USB card and I want the USB card to be the default sound device. In /etc/modprobe.d/alsa-base.conf I created the lines:

# Make usb audio the default card
options snd slots=snd-usb-audio,snd-hda-intel

So now the USB device driver always loads first on boot and the USB device is always the default. The integrated intel card is still available if I want to use it.

Back to the ~/.asoundrc

# eq controller
ctl.equal {
type equal
library "/usr/lib/ladspa/mbeq_1197.so"
module "mbeq"
}

#eq plug passes output to dmix – no crossfeed
pcm.equal {
type plug
slave.pcm plugequal
}
pcm.plugequal {
type equal
slave.pcm “plug:dmix”
library “/usr/lib/ladspa/mbeq_1197.so”
module “mbeq”
}

#eq plug passes output to crossfeed
pcm.plugequal2 {
type equal
slave.pcm crossfeed
library “/usr/lib/ladspa/mbeq_1197.so”
module “mbeq”
}
pcm.equal2{
type plug
slave.pcm plugequal2
}

#crossfeed outputs to dmix
pcm.crossfeed {
type plug
slave.pcm “bs2b”
}
pcm.bs2b {
type ladspa
slave.pcm “plug:dmix”
path “/usr/lib/ladspa/”
plugins [{
label bs2b
input {
controls [ 650 9.5 ]
}
}]
}

This has created several devices: an equalizer, a means to control the equalizer’s settings in real time, and a crossfeed based on Jan Meier’s famous crossfeed hardware (the dmix device already exists and is defined in /usr/share/alsa/pcm/dmix.conf – there is no need to touch it). There are two ways to access the equalizer: one passes the equalized output directly to dmix, and the other passes it to the crossfeed device, after which the crossfeed passes its output to the dmix mixer device. The mixer in this example is plug:dmix which can accept and mix multiple audio sources and is enabled automatically in any modern ALSA system. If you want every sound from all applications passed through the eq then change

pcm.equal {
to
pcm.!default {

Configure MPD’s outputs:
If you set the eq systemwide then you can remove the third output device from the following mpdconf example.

I run mpd under my own user name and my ~/.mpdconf contains the following audio outputs:

audio_output {
type "alsa"
name "My ALSA Device"
auto_resample "no"
mixer_device "default" # optional
mixer_control "PCM" # optional
}
audio_output {
type "alsa"
name "bs2b"
device "crossfeed"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}
audio_output {
type "alsa"
name "Eq"
device "equal"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}
audio_output {
type "alsa"
name "EQ+bs2b"
device "equal2"
auto_resample "no"
mixer_control "PCM"
mixer_device "default"
}

This allows me to toggle mpd output between the following states:

No Eq, no crossfeed
Crossfeed, no Eq
Eq, no crossfeed
Eq + crossfeed

Restart alsa and mpd so the changes can take effect:

# alsa force-reload && /etc/init.d/mpd restart

Configure the Equalizer:
This is easily done in a terminal using alsamixer, which is already installed as part of ALSA. So play some music using mpd with one of the equalizer outputs (or mplayer-ao alsa:device=equal ) if you’re using pcm.equal { then you can do

$ alsamixer -D equal

and if you’re using Eq systemwide with pcm.!default { then play audio with any app and you need only do

$ alsamixer

and now you can use the Eq sliders and hear the effect. When you’re happy with it and want to save the settings so they always take effect on boot you can run:

# alsactl store

MPlayer:
Now for the best way to use mplayer with both crossfeed and the configured equalizer. MPlayer has its own meier crossfeed so use this and then pass the audio to the ALSA ‘equal’ device just created and configured:

mplayer -af bs2b=profile=jmeier -ao alsa:device=equal

Alias for convenience:
On my playback system I don’t use any Eq with my speakers or my old Sennheiser Hi-Fi headphones but it’s very useful to add a little extra bass for use with my Sony studio monitor headphones, so they sound more like a Hi-Fi headphone and a little less like a slightly lightweight and sterile monitor. I have the above command aliased as mplayer-headphones in ~/.bash_aliases:

#use meier crossfeed emulation for headphones
alias mplayer-headphones='mplayer -af bs2b=profile=jmeier -ao alsa:device=equal'

Of course if you have set up Eq systemwide then you need only do:

mplayer -af bs2b=profile=jmeier

So there it is: high quality Eq and/or Meier-like crossfeed available to mplayer, mpd and clients, and (if you prefer) to any app which produces sound.

Resource useage:
On my system (Athlon64 4050e dual core 2.0Ghz running 32-bit Debian) running mpd and alsa with crossfeed and eq uses about 4% more CPU than without either, which is to say that CPU useage goes from 1% to 5% when no samplerate conversion is required. A similar change, 4 or 5 percentage points difference, is seen when samplerate conversion is required i.e. 48000Hz audio resampled to my system default 44100Hz using libsamplerate “samplerate_medium”.

Advertisements

Tags: , , , , , , , , ,

15 Responses to “ALSA Equalizer & Crossfeed on Debian Stable (Squeeze)”

  1. moa Says:

    very usefull. thank you!

  2. hozza Says:

    I’ve been trying for ages on my crunchbang (Debian based) and all I’ve got is every audio app crashing when audio is played?

    • takla Says:

      I have no experience of crunchbang. Perhaps it uses Pulse Audio by default? If so then my blog post on setting up ALSA crossfeed and equalizer is not suitable for you.

      Chaining alsa devices can be difficult. Alsa is complex and some of the documentation lacks clarity or appears to be/is incomplete or ambiguous, or maybe has suffered in translation. Here is one way to simplify: instead of configuring both equalizer and crossfeed in ~/.asoundrc you can configure only an equalizer and then use audio and video apps which use their own crossfeed plug-in. For example MPlayer can use its own implementation i.e. mplayer -af bs2b=profile=jmeier . VLC also has its own headphone filter. Alternatively you could set up an Alsa crossfeed and use apps which implement their own equalizer. Again VLC comes to mind for video and audio, and DeadBeef or Audacious for audio.

  3. Mau Says:

    hi there, hi followed your guide and when i chose anything other than “My Alsa Device” in mpc outputs i got the following error :

    ALSA lib pcm.c:2190:(snd_pcm_open_noupdate) Unknown PCM equal2
    Feb 15 12:06 : output: Failed to open “EQ+bs2b” [alsa]: Failed to open ALSA device “equal2”: No such file or directory

    i can’t figure out what’s wrong , can you help?

    • takla Says:

      Check your ~/.asoundrc is correctly written, as it seems you have no alsa equal2 device. You can also run ‘alsamixer -D ‘ to see if a device exists. If the device exists but mpd doesn’t see it then is mpd running as a different user? I run mpd under my normal user name so it sees my ~/.asoundrc. I don’t know your system, alsa version, ~/.asoundrc or /etc/asound.conf so can’t say more than that.

  4. Mau Says:

    i did copy your .asoundrc with pcm.!default for systemwide eq, I’m on debian squeeze , Alsa is ver 1.0.21..If I run “alsamixer -D equal” i get the eq controls i guess the problem must be mpd not being able to see alsa configuration file i’m going to check as soon as i’m able to.Thanks for now

    • takla Says:

      I think I should have been clearer about “systemwide”. In this context it meant all yout system’s audio apps that are run by you, the user. A standard Debian install of mpd creates a new mpd user and mpd is run under that user, not your regular user ID. Your regular user just runs a client such as gmpc or mpc or similar, but not the daemon. In my case I change the Debian default by editing ~/.mpdconf and specifying the user is me i.e:

      # General music daemon options ################################################
      #
      # This setting specifies the user that MPD will run as. MPD should never run as
      # root and you may use this setting to make MPD change its user ID after
      # initialization. This setting is disabled by default and MPD is run as the
      # current user.
      #
      user “takla”

      and I edit /etc/default/mpd and add:

      MPDCONF=/home/takla/.mpdconf

      Then when mpd starts it is under my user and it sees and uses my ~/.asoundrc.

      If you use mpd as a home player, i.e. not accessible outside your trusted LAN, then there is no need for it to run as a special mpd user. Your own user account is fine. The Debian default is sensibly cautious but there is no harm in changing it according to circumstances.

  5. Mau Says:

    hi, while was waiting for your response i checked again my .asoundrc and i found few mystypes i did miss first time,everything works now.
    Thanks again for your help and time

  6. Guillem Says:

    Hi! I hope to still receive support from this post :/

    I am using debian squeeze (oldstable) and it seems that package bs2b-ladspa is not available any more. I installed the one available for sid.

    I followed the “how-to” from above and I am not sure if it really worked. Anyway, the problem is that I am spotify premium user, and now, when I try to reproduce any track, the terminal shows the following message:

    11:10:52.694 I [audio_driver_linux.cpp:26 ] Using Alsa
    ALSA lib dlmisc.c:236:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_equal.so
    11:10:52.750 E [audio_streamer_decompressor.cpp:296] playbackError(-6)
    11:11:01.728 I [recommendations.js:17 ] Failed to get top playlists

    Is there any way to restore my system to the stauts previuos to the alsa eualizer installation?

    Thank you in advance!

    • takla Says:

      In current Debian releases (Wheezy and newer) with multi architecture support things have changed since I wrote the article: alsa-lib is not in /usr/lib but in /usr/lib/i386-linux-gnu or /usr/lib/x86_64-linux-gnu or similar, depending on architecture. So you can’t anymore just drop in a package from Sid into Squeeze and expect it to work.

      Anyway just uninstall it: # apt-get purge bs2b-ladspa and # alsa force-reload (or reboot)

      You can then just delete or rename your ~/.asoundrc and sound should work as before.

      • Guillem Says:

        Hello Takla.

        Thank you very much for your advice.
        It worked perfectly.

        Well yes, I was quite brave just installing a package which do not correspond to my release, but… I wanted to try it, that’s how some newbies like me can learn.

        By the way, do you know if there is another possibility to install an equalizer for squeeze?

        Thank you very much again for your attention!

  7. takla Says:

    For Squeeze you could build the equaliser and bs2b from source.

    Unless there is some pressing reason not to change I would upgrade from Debian oldstable to stable. bs2b-ladspa and libasound2-plugin-equal are both in normal Wheezy repos.

  8. Ikem Krueger Says:

    A Puppy Linux user wrote a gui for alsaequal called “pEqualizer”:

    http://murga-linux.com/puppy/viewtopic.php?t=81889

  9. Ibon Says:

    So nice setup!, thanks a lot for sharing 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: