# Crossfeed ALSA plugin (for headphones)

## octoploid

What is crossfeed?

From wikipedia:

 *Quote:*   

> Crossfeeding, blends the left and right stereo channels slightly, reducing the extreme channel separation characteristic of headphone listening that is known to cause headaches in a small fraction of listeners (and compensating for extreme separation in older stereo releases). Crossfeed also improves the soundstage characteristics and makes the music sound more natural as if one was listening to a pair of speakers.

 

First we will install the bs2b crossfeed plugin.

This ladspa plugin is part of  the tap-plugins and is only available in CVS. (no ebuild)

```
# emerge ladspa-sdk

cd /tmp

rsync -av "rsync://PROJECTNAME.cvs.sourceforge.net/cvsroot/tap-plugins/*" .

export CVSROOT=/tmp 

cd ~

cvs -z3 co tap-plugins

cd tap-plugins

make

# make install

# env-update
```

Now we must tell alsa to use this new plugin.

We edit /etc/asound.conf:

```
pcm.!default {

  type hw

  card 0

}

ctl.!default {

  type hw

  card 0

}

pcm.crossfeed {

  type plug

  slave.pcm "ladspa"

}

pcm.ladspa {

  type ladspa

  slave.pcm "plughw:0,0";

  path "/usr/local/lib/ladspa";

  plugins [

    {

      label tap_bs2b

      input {

        controls [ 2 1 ]

      }

    }

 ]

}
```

This should be adjusted to reflect your hardware configuration. I use an external USB DAC

with no software mixing (bit-perfect sound) .  You can set different sound characteristics 

with the "controls" values. (First integer 1..3, second 0 or 1). See:

http://www.hydrogenaudio.org/forums/index.php?showtopic=38291

or the source code for further information.

Now we must tell our music player to use the alsa-crossfeed plugin.

I will give two examples: cmus and mpd.

cmus:

Just type ":set dsp.alsa.device=crossfeed" to enable the plugin and

":set dsp.alsa.device=default" to switch it off again.

mpd:

Edit /etc/mpd.conf

```
audio_output {

        type                    "alsa"

        name                    "ALSA default"

        device                  "default"

#        format                  "44100:16:2" # optional

}

#

audio_output {

        type                    "alsa"

        name                    "ALSA crossfeed"

        device                  "crossfeed"

#        format                  "44100:16:2" # optional

}
```

Restart mpd and run  "mpc disable 1"

"mpc outputs" now shows:

```
Output 1 (ALSA default) is disabled

Output 2 (ALSA crossfeed) is enabled
```

If you want to switch the crossfeed plugin off again, you 

just enable output 1 and disable output 2.

----------

## a.b.

I tried that but it doesn't work. The most meaningful error messages comes from mplayer:

 *Quote:*   

> 
> 
> [AO_ALSA] alsa-lib: pcm.c:2202:(snd_pcm_open_noupdate) Unknown PCM ladspa
> 
> [AO_ALSA] Playback open error: File exists
> ...

 

----------

## octoploid

 *a.b. wrote:*   

> I tried that but it doesn't work. The most meaningful error messages comes from mplayer:
> 
>  *Quote:*   
> 
> [AO_ALSA] alsa-lib: pcm.c:2202:(snd_pcm_open_noupdate) Unknown PCM ladspa
> ...

 

You should make sure that ALSA_PCM_PLUGINS="ladspa" is set, when you emerge alsa-lib.

Also check if both "pcm.crossfeed" and "pcm.ladspa" are defined in your asound.conf as 

described above.

----------

## a.b.

 *octoploid wrote:*   

>  *a.b. wrote:*   I tried that but it doesn't work. The most meaningful error messages comes from mplayer:
> 
>  *Quote:*   
> 
> [AO_ALSA] alsa-lib: pcm.c:2202:(snd_pcm_open_noupdate) Unknown PCM ladspa
> ...

 

In fact I have set ALSA_PCM_PLUGINS="*" in my make.conf. I'll try remergeing with ladspa

explicitly set.

 *Quote:*   

> 
> 
> Also check if both "pcm.crossfeed" and "pcm.ladspa" are defined in your asound.conf as 
> 
> described above.

 

I copy&pasted yours.

----------

## octoploid

 *a.b. wrote:*   

>  *octoploid wrote:*    *a.b. wrote:*   I tried that but it doesn't work. The most meaningful error messages comes from mplayer:
> 
>  *Quote:*   
> 
> [AO_ALSA] alsa-lib: pcm.c:2202:(snd_pcm_open_noupdate) Unknown PCM ladspa
> ...

 

Just delete ALSA_PCM_PLUGINS="*" in your make.conf and re-emerge. This should also build all

alsa pcm plugins. (Check by running: emerge -pv alsa-lib)

----------

## a.b.

 *octoploid wrote:*   

>  *a.b. wrote:*    *octoploid wrote:*    *a.b. wrote:*   I tried that but it doesn't work. The most meaningful error messages comes from mplayer:
> 
>  *Quote:*   
> 
> [AO_ALSA] alsa-lib: pcm.c:2202:(snd_pcm_open_noupdate) Unknown PCM ladspa
> ...

 

No, it doesn't. That's probably because I have set USE="-*"

----------

## ciaranhearne

Just in case anyone wants to know how to get this plugin working with Dmix (so you can play multiple sounds at once) here is my working .asoundrc:

```

pcm.!default {

  type plug

  slave.pcm "ladspa"

}

pcm.crossfeed {

  type plug

  slave.pcm "ladspa"

}

pcm.ladspa {

  type ladspa

  slave.pcm "dmixplug"

  path "/usr/lib/ladspa";

  plugins [

    {

      label tap_bs2b

      input {

        controls [ 2 1 ]

      }

    }

 ]

}

pcm.dmixplug {

  type plug

  slave.pcm "dmixer"

}

pcm.dmixer {

    type dmix

    ipc_key 1234

    slave {

        pcm "hw:0,0"

        period_size 1024

        buffer_size 4096

        rate 44100

    }

} 

```

Ciaran

----------

## darklegion

I'm just wondering: How do you set configuration options with the bs2b plugin? There is an "easy" crossfeed mode in bs2b that supposedly causes much less treble roll off.I looked in tap_bs2b.c and it is probably CONTROL_HIGH_BOOST that enables this with the ladspa plugin, but I have no idea how to enable it.

I'll have a more thorough look in the morning (I'm badly lacking sleep) but if you already know the answer, I'd love to hear it.The plugin has unacceptable quality at the moment, for me.

----------

## octoploid

 *darklegion wrote:*   

> I'm just wondering: How do you set configuration options with the bs2b plugin? There is an "easy" crossfeed mode in bs2b that supposedly causes much less treble roll off.I looked in tap_bs2b.c and it is probably CONTROL_HIGH_BOOST that enables this with the ladspa plugin, but I have no idea how to enable it.
> 
> I'll have a more thorough look in the morning (I'm badly lacking sleep) but if you already know the answer, I'd love to hear it.The plugin has unacceptable quality at the moment, for me.

 

You should check the hydrogenaudio.org link that I've posted above.

Basically :

input {

        controls [ 2 1 ]

      } 

controls the plugin. The second integer sets the "easy" crossfeed mode (1=on, 0=off).

The first integer specifies the crossfeed level:

 *Quote:*   

> Crossfeed level
> 
> 1 : Virtual speakers placed almost directly left and right of you (60 degrees azimuth).
> 
> 2: Virtual speakers at 10 and 2 'o clock.
> ...

 

----------

## Hypnos

Thank you octoploid for the how-to, and ciaranhearne for the tip about dmix.

With my Klipsch Custom 2 in-ear monitors I have found I need the aggressive "3" setting to get a minimally comfortable soundstage depth on old/low-quality recordings.  With newer recordings that come with more depth, either "2" or "3" give a nice, mild enhancement.

I have created an ebuild "tap-plugins-99999999.ebuild" for the CVS head:

```

# Copyright 1999-2009 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $

inherit cvs

DESCRIPTION="Tom's Audio Processing LADSPA plugins"

HOMEPAGE="http://tap-plugins.sourceforge.net/"

LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~amd64"

IUSE=""

DEPEND="media-libs/ladspa-sdk"

RDEPEND="${DEPEND}"

ECVS_SERVER="${PN}.cvs.sourceforge.net:/cvsroot/${PN}"

ECVS_MODULE="${PN}"

S="${WORKDIR}/${ECVS_MODULE}"

src_unpack() {

   cvs_src_unpack

   cd "${S}"

   epatch "${FILESDIR}/${P}-makefile.patch"

}

src_install() {

   emake DESTDIR="${D}" install || die "emake install failed"

   dodoc CREDITS README 

}
```

which requires the following patch in "files/tap-plugins-99999999-makefile.patch" :

```
diff -urN tap-plugins-99999999.old/Makefile tap-plugins-99999999/Makefile

--- tap-plugins-99999999.old/Makefile   2009-07-29 11:43:31.000000000 +0900

+++ tap-plugins-99999999/Makefile   2009-07-29 11:46:15.000000000 +0900

@@ -23,8 +23,8 @@

 # Change this if you want to install somewhere else. In particular

 # you may wish to remove the middle "local/" part of the path.

 

-INSTALL_PLUGINS_DIR   =   /usr/local/lib/ladspa/

-INSTALL_LRDF_DIR   =   /usr/local/share/ladspa/rdf/

+INSTALL_PLUGINS_DIR   =   ${D}/usr/lib/ladspa/

+INSTALL_LRDF_DIR   =   ${D}/usr//share/ladspa/rdf/

 

 # NO EDITING below this line is required

 # if all you want to do is install and use the plugins.

```

Put these in your local overlay.

----------

## octoploid

BTW there is new ladspa-bs2b plugin available:

http://sourceforge.net/projects/bs2b/files/LADSPA%20plugin/0.9.1/ladspa-bs2b-0.9.1.tar.bz2/download

If you want to check it out, first emerge libbs2b and then compile and install it by hand (or write 

an ebuild).

This new plugin is controlled by two numbers:

```
Lowpass-filter-cut-frequency: Lowpass-filter-cut-frequency

                        flags: readable, writable, controllable

                        Float. Range:             300 -            2000 Default:             725 Current:             725

  Feeding-level       : Feeding-level

                        flags: readable, writable, controllable

                        Float. Range:               1 -              15 Default:             4.5 Current:             4.5

```

See http://bs2b.sourceforge.net/ for more info.

----------

## Hypnos

octoploid,

Thank you again!  The mix is much stronger with this plugin, and I find the default settings more than adequate for my IEMs.  Here is the ebuild, "ladspa-bs2b-0.9.1.ebuild" :

```
# Copyright 1999-2009 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $

DESCRIPTION="LADSPA plugin for bs2b"

HOMEPAGE="http://bs2b.sourceforge.net"

SRC_URI="mirror://sourceforge/bs2b/LADSPA%20splugin/${PV}/${P}.tar.bz2"

LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~amd64"

IUSE=""

      

DEPEND="media-libs/ladspa-sdk

      >=media-libs/libbs2b-3.1.0"

RDEPEND="${DEPEND}"

src_install() {

   emake DESTDIR="${D}" install || die "emake install failed"

   dodoc AUTHORS THANKS

}
```

EDIT: I opened a bug to add this to the Portage tree.

----------

## sping

 *Hypnos wrote:*   

> Here is the ebuild, "ladspa-bs2b-0.9.1.ebuild"

 

Added to the sping overlay next to media-plugins/audacious-bs2b.

----------

## Hypnos

Sorry for necromancing, but it seems silly to open a new thread for such a small update.

My Klipsch Custom 2 headphones conked out, so I got an Image S4 set.  I find I need much less crossfeed, but have to reverse the channels as the headphones fit much better switching left/right.  Here is my updated ~/.asoundrc:

```
ctl.!default {

   type hw

   card Intel

}

pcm.!default {

   type route

   slave.pcm "plug:ladspa"

   slave.channels 2

   ttable.1.0 1

   ttable.0.1 1

}

pcm.ladspa {

   type ladspa

   slave.pcm "dmixplug"

   path "/usr/lib/ladspa"

   plugins [

      {

         label bs2b

#            input {

#               controls [ 700 5 ]

#            }

      }

   ]

}

pcm.dmixplug {

   type plug

   slave.pcm "dmixer"

}

pcm.dmixer {

   type dmix

   ipc_key 1234

   slave {

      pcm "hw:0"

      period_size 1024

      buffer_size 4096

      rate 48000

   }

}

```

Hopefully this will be useful to someone.

EDIT:  This setup seems to screw up mono audio output ... no sound.

EDIT2: PaulBredbury's correction below, plus with "slave.channels 2" mono at least comes out of the front left channel.

----------

## PaulBredbury

 *Hypnos wrote:*   

> controls [ 1 1 ]

 

That's not quite right - I assume that first 1 gets changed to either 300 or 725.

analyseplugin bs2b

 *Quote:*   

> Ports:	"Lowpass filter cut frequency (Hz)" input, control, 300 to 2000, default 725
> 
> 	"Feeding level (dB)" input, control, 1 to 15, default 4.5

 

I've been using in my ~/.asoundrc:

```
controls [ 700 6 ]
```

----------

## Hypnos

Paul,

Thanks for the correction -- the ladspa-bs2b code does seem to clip parameter values to the ranges given in the info output, instead of using the presets described in the bs2b headers which were used in the old tap_bs2b plugin.

This also explains why the second parameter always affected the output much more than the first parameter in my experimentation with these new headphones.

----------

## West201

I can only hear the headset when I use phonon's "test" sound, but when playing music or VLC it's not functioning. Any suggestions ? I did use cmus method.

----------

