View Full Version : The continued search for crossfeed in Linux


Daravon
05-23-08, 02:23 PM
Since switching from the dark side there's only one thing that I have given up, and that is effective DSP for headphones. For those of us that listen exclusively to headphones and have picky tastes, some kind of stereo-collapsing signal processing is almost mandatory for a satisfactory listening experience.

In windows I used foobar2000 which had several different plugins, for 'crossfeed' as it's called. There is also the Baur Stereo-to-binaural DSP on sourceforge and the 4Front plugin. There is also Dolby headphone, which is very effective.

I usually use Amarok, or rhythmbox; I have yet to find any way to implement any of these very available DSPs in linux. Please help. It's almost worth booting back into windows in order to listen to music, but I don't want to.

Imagine my joy upon reading in the mplayer man page that mplayer has a 'hrtf' option that supposedly 'Converts multichannel audio to 2 channel output for headphones, preserving the spatiality of the sound'. At first I tried it, but it error'd saying it wasn't 48kHz, so I resampled it and tried it, but it didn't work. It sounded bad and crackled and other bad stuff.

Now there is also a 'pan' filter for mplayer, that lets you custom-mix channels together. It might work ok for a 'better than nothing' crossfeed option but I don't understand the syntax yet.

chaz@brutus:~/Music/Lossless albums/Hot Water Music/Forever and Counting$ mplayer -af resample=48000:0:2,hrtf=s 10\ Western\ Grace.flac
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 5400+ (Family: 15, Model: 107, Stepping: 2)
CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing 10 Western Grace.flac.
Audio file file format detected.
============================================================ ==============
Forced audio codec: mad
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 2 ch, s16le, 979.8 kbit/69.43% (ratio: 122477->176400)
Selected audio codec: [ffflac] afm: ffmpeg (FFmpeg FLAC audio decoder)
============================================================ ==============
AO: [pulse] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
[hrtf] Using active matrix to decode 2 channel input, HRTF to mix 3/2 matrix surround into L, R channels
A: 20.7 (20.6) of 257.0 (04:17.0) 18.7%
Exiting... (Quit)
chaz@brutus:~/Music/Lossless albums/Hot Water Music/Forever and Counting$

Troubleshooter
05-23-08, 06:47 PM
Wow, now this is beyond me. Do you have a bunch of multi-channel music that you listen to regularly? Obviously we see people wanting their 2 channel music spread out to 5/7.1 but I really think I'm not following what you're looking for here. I own a grand total of 1 music title that is more than 2 channel, a dts 'cd' (?) that honestly was a freebie. Maybe I'm just not with it?
-Trouble

Daravon
05-23-08, 07:10 PM
No, not multichannel, what I want is headphone DSP. For listening to stereo music with headphones. If you don't understand, try this
http://en.wikipedia.org/wiki/Head-related_transfer_function

DSPs like this are popular and include the ones mentioned above. However they are simply not implemented in linux because I guess linux users don't listen to headphones or else don't care. I haven't even found a wrapper for Dolby Headphone, which I would assume would be the easiest thing ever to implement, yet beyond my nonexistent coding capabilities.

bac522
05-23-08, 08:39 PM
Not sure if XMMS will help you. Check out http://www.xmms.org/effect.php

Troubleshooter
05-24-08, 08:02 AM
Ahhhh gotcha.

Rgb
05-24-08, 08:39 AM
I fully agree that the lack of Dolby headphone or similar head-related-transfer-function DSP algorithms in any of the Linux audio players/music managers is a big gap in the Linux audio scene.

The Linux version of WinDVD, LinDVD, might have something like tis
http://www.intervideo.com/jsp/Product_Profile.jsp?p=LinDVD

but I haven't been able to find a comprehensive feature set list of LinDVD.

I think the best hope is for one of the Linux media players to support the Dolby Headphone .dll like Foobar does on window. This .dll is usually ripped from a PowerDVD load, but the .dll is easily found all over the net, so Linux developers have easy access to it like Win users.

Another option would be to buy an external Dolby headphone encoder
http://www.amazon.com/JVC-SUDH1-Surround-Headphone-Adaptor/dp/B000ETBZ5G

I was thinking of getting the JVC unit to set up a "silent" surround sound home theater in a vacation home- route the SPDIF AC3 out from a Linux media PC into the JVC unit, feed the Dolby Headphone encoded 2 channel output in to a wireless headphone transmitter, then give anyone who wants to watch a wireless headphone, or set up a multi-output wired headphone distribution system. Add some shakers to the seats, and everyone gets "5.1" surround plus the bass feel without anyone else in the house hearing it :D.

Rgb
05-24-08, 09:05 AM
I forgot I asked the question a while ago
http://www.avsforum.com/avs-vb/archive/index.php/t-850396.html

Perhaps the mplayer or Audacious/Banshee/Rythmbox/Exaile devs could make the Dolby Headphone .dll work as a plugin?

mythmaster
05-24-08, 09:20 AM
I don't use headphones, but I'm curious: when you tell amarok to use 5.1, is the headphone output still basic 2 ch stereo?

EDIT: to answer my own stupid question, I guess you'd lose the surround part.

mythmaster
05-24-08, 10:24 AM
Tell you what, why don't we disassemble that dll? If we can find out how it handles input and output, then we can write a jack or alsa plugin that uses it through wine, or if we can pluck out the algorithm, we can write a native plugin.

Copyright notice: reverse engineering is *NOT* illegal.

Rgb
05-24-08, 10:49 AM
Filename reference
http://www.softwaretipsandtricks.com/dll/6235-Dolbyhphdll.html

Info links- scroll down to "DSP" section
http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Components_0.9

Again, if you have any old copy of PowerDVD, probably at least back to XP/4.0/5.0/6.0, you can grab the .dll from the install directory.

Rgb
05-24-08, 10:52 AM
It might be simpler to reverse engineer/port the Dolby Headphone wrapper. Might be useful to ask the developer himself if he would share his wrapper source
http://pelit.koillismaa.fi/plugins/show.php?id=132

Daravon
05-24-08, 04:58 PM
I'm not sure how Dolby Headphone is with non-Prologic, plain old stereo music; does anyone know?

BTW, is mplayer capable of gapless playback of .flac?

mythmaster
05-24-08, 10:18 PM
BTW, is mplayer capable of gapless playback of .flac?

Nearly all of my music is in .flac. Most certainly.

Might be useful to ask the developer himself if he would share his wrapper source

Since he uses the brand name Dolby and his product is shipped with commercial software, the developer is probably bound by licensing terms that explicitly prohibit him from releasing the source or even porting to another OS.

Rgb
05-24-08, 10:22 PM
Since he uses the brand name Dolby and his product is shipped with commercial software, the developer is probably bound by licensing terms that explicitly prohibit him from releasing the source or even porting to another OS.

I don't think this wrapper is "commercial"
http://pelit.koillismaa.fi/plugins/show.php?id=132

mythmaster
05-24-08, 10:32 PM
I don't think this wrapper is "commercial"
http://pelit.koillismaa.fi/plugins/show.php?id=132
You're right. I didn't follow the link & thought we were still talking about DOLBYHPH.DLL (which is still required by the wrapper).

That's a good idea since he's already figured out how to "talk" to the dll. I'm guessing wine would still be needed though which seems like unnecessary baggage.

What we really want is the algorithm.

greeniguana00
05-25-08, 01:26 PM
I haven't been on Linux in a while (or AVS for that matter), but I think I can help. There is a program called Jack Rack which makes it very easy to apply filters to audio. If you look here: http://quitte.de/dsp/caps.html you'll see that there are pan and hrtf filters. I suggest you get JACK (JACK Audio Connection Kit) working, get used to how it works, then start fooling around with Jack Rack. JACK allows you to send audio from program to program easily, so you just route the output of a player (XMMS is one player that has a JACK output plugin) to the input of Jack Rack and go from there.

Daravon
05-27-08, 12:10 AM
Nearly all of my music is in .flac. Most certainly.

OK then what's your secret? Mplayer plays back quite gappily, which I just confirmed now by trying to play an album back.

mythmaster
05-27-08, 07:24 AM
OK then what's your secret? Mplayer plays back quite gappily, which I just confirmed now by trying to play an album back.

No secret. Plays fine on a Celeron 2.4 GHz 512 MB RAM system.

What's your cpu?

Daravon
05-27-08, 09:26 AM
AMD 5400+ and 4 gigs of ram.

chaz@brutus:~/Music/Lossless albums/Neutral Milk Hotel/In the Aeroplane over the Sea$ mplayer -ao alsa:device=spdif *
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 5400+ (Family: 15, Model: 107, Stepping: 2)
CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing 01 the king of carrot flowers pt. one.flac.
Audio file file format detected.
============================================================ ==============
Forced audio codec: mad
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 2 ch, s16le, 935.8 kbit/66.32% (ratio: 116981->176400)
Selected audio codec: [ffflac] afm: ffmpeg (FFmpeg FLAC audio decoder)
============================================================ ==============
AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 120.2 (02:00.1) of 120.0 (02:00.0) 0.6%

*INSERT MASSIVE GIANT HALF SECOND GAP*

Playing 02 the king of carrot flowers pts. two & three.flac.
Audio file file format detected.
...

Daravon
05-27-08, 11:48 AM
I was reading the hydrogenaudio wiki about gapless playback and it says that all lossless file formats are inherently gapless. But mplayer clearly inserts gaps when it plays back an album. Does this have something to do with how I tell mplayer to play? I usually cd into an album directory, which has all the album's songs in it in flac format, and then just

mplayer -ao alsa:device=spdif -af pan:2:1:.1:.1:1 *

maybe there's some way to tell it to play all the tracks as one file?

Mac The Knife
05-27-08, 03:40 PM
When I really had to have gapless playback, I used to use XMMS (version 1x - NOT XMMS-2 where they f-ed up the UI).

Unfortunately, Hardy uses some newer libraries so XMMS (v1x) won't install from a prepackaged deb. If I ever get around to it, I intend to recompile it with the Hardy libraries (now I just have to get motivated enough to do it).

mythmaster
05-27-08, 06:14 PM
I was reading the hydrogenaudio wiki about gapless playback and it says that all lossless file formats are inherently gapless. But mplayer clearly inserts gaps when it plays back an album. Does this have something to do with how I tell mplayer to play? I usually cd into an album directory, which has all the album's songs in it in flac format, and then just

mplayer -ao alsa:device=spdif -af pan:2:1:.1:.1:1 *

maybe there's some way to tell it to play all the tracks as one file?

Mine doesn't do that (just tested with a couple of grateful dead tracks...no transition whatsoever), but I just give it -ao alsa and it plays through spdif and I set my speakers to Dolby PLII Music, so no need for the audio filter. Does it do the same without the audio filter?

EDIT: Sorry, replied to the wrong post...talking about the half-second gap. Also, AFAIK, you can't tell it to play all as one file.

Daravon
05-27-08, 06:41 PM
I don't know; I'll try it tonight.

The 'pan' audio filter is being used as a primitive crossfeed. That's the whole reason for using mplayer in the first place. If gapless playback doesn't work with the audio filter, then i'm in a total catch-22 .

mythmaster
05-27-08, 07:06 PM
I don't know; I'll try it tonight.

The 'pan' audio filter is being used as a primitive crossfeed. That's the whole reason for using mplayer in the first place. If gapless playback doesn't work with the audio filter, then i'm in a total catch-22 .

Not really. You can set it up in .asoundrc with the a52 plugin. I had mine set up like that before I figured out my speakers did it for me (and better). The HOWTO is here --> http://gentoo-wiki.com/HOWTO_Dolby_Digital_Out_(AC3,_SPDIF)#On-the-fly_Dolby_Digital_Encoding

If you use the a52 plugin, you'll have to compile it since it's disabled by default in the *buntu asound-plugins package. This HOWTO worked for me --> http://ubuntuforums.org/showthread.php?t=714712 although I didn't have to set up pulseaudio since I upmixed in .asoundrc.

Here it is:
$ cat asoundrc.bak
pcm.!default "plug:stereoupmix"

pcm.a52encode {
type a52
}

pcm.stereoupmix {
type route
slave.pcm "a52encode"
slave.channels 6
ttable.0.0 1
ttable.1.1 1
ttable.0.2 1
ttable.1.3 1
ttable.0.4 0.5
ttable.1.4 0.5
ttable.0.5 0.5
ttable.1.5 0.5
}

Daravon
05-27-08, 09:53 PM
That a52 on-the-fly Dolby encoding thing looks really cool. But let me ask this...why would I want to do that? Do I have to do that in order to play back music over spdif gaplessly?

That's what I really want, now using the mplayer '-af pan' pseudo-crossfeed, I'm not getting gapless playback with flac files.

I do NOT want to upmix stereo sound to surround. I realize that according to the How-to, leaving the config as

pcm.a52encode {
type a52
}


doesn't do upmixing, but I still don't see why I would want to do this unless it somehow fixes gapless playback with -af options?

mythmaster
05-27-08, 10:13 PM
That a52 on-the-fly Dolby encoding thing looks really cool. But let me ask this...why would I want to do that? Do I have to do that in order to play back music over spdif gaplessly?

That's what I really want, now using the mplayer '-af pan' pseudo-crossfeed, I'm not getting gapless playback with flac files.

I do NOT want to upmix stereo sound to surround. I realize that according to the How-to, leaving the config as

pcm.a52encode {
type a52
}


doesn't do upmixing, but I still don't see why I would want to do this unless it somehow fixes gapless playback with -af options?

Yeah, I misunderstood and thought the audio filter was upmixing to surround which can be done otherwise if that was the problem causing the gaps. Sorry.

mythmaster
05-27-08, 10:36 PM
I found this (http://bs2b.sourceforge.net/) for you. Not sure if it's what you're looking for. EDIT: Also, this (http://amarok.kde.org/wiki/Ladspa_HowTo).

Configuring bs2b as a LADSPA filter in ALSA should allow you to use crossfeed from anything, including MythTV.

Daravon
05-28-08, 01:10 AM
Dude...that apparently rocks. I'll have to give that a go later.

Rgb
05-28-08, 09:07 AM
I found this (http://bs2b.sourceforge.net/) for you. Not sure if it's what you're looking for. EDIT: Also, this (http://amarok.kde.org/wiki/Ladspa_HowTo).

Configuring bs2b as a LADSPA filter in ALSA should allow you to use crossfeed from anything, including MythTV.

That filter in your first link looks like a Dolby Headphone equivalent- Great find! One less excuse for staying with Windows :)

It looks like it handles 2 channel stereo source audio.

One great feature of Dolby Headphone is its ability to accept 5.1 channel Dolby Digital Ac3 streams, decode and downmix to 2 channel, while preserving the spatiality of the rear and front center channels. It's quite effective- it sounds like the rears and center are outside of your head, just like you're in a room with discrete speakers around you.

I don't know how you'd do that with the binaural filter linked above.

Perhaps first applying a DD 2 channel downmix filter intended for speakers, which applies a "surround" effect for rear/center channels, and then piping this into the binaural headphone filter?

mythmaster
05-28-08, 10:54 AM
Perhaps first applying a DD 2 channel downmix filter intended for speakers, which applies a "surround" effect for rear/center channels, and then piping this into the binaural headphone filter?

That sounds feasible and I'm sure someone's done this. That much processing would induce a delay, of course, but video timing can be adjusted. Since ALSA's doing all the dirty work instead of the media player, at least the audio playback would be gapless.

EDIT: I found a LADSPA HRTF plugin over here (http://quitte.de/dsp/caps.html#HRTF). So, you should be able to pipe the surround and center channels through it, position them, and mix them in with the stereo channels before sending them through bs2b.

Daravon
05-28-08, 12:21 PM
That sounds feasible and I'm sure someone's done this. That much processing would induce a delay, of course, but video timing can be adjusted. Since ALSA's doing all the dirty work instead of the media player, at least the audio playback would be gapless.


is that why my mplayer is being nongapless, because I'm having it do audio processing?

mythmaster
05-28-08, 12:39 PM
is that why my mplayer is being nongapless, because I'm having it do audio processing?

Sounds like it. The only way to know for sure would be to try it w/o the processing.

Daravon
05-29-08, 11:55 AM
It's still nongapless without the -af. I'm here at work now different computer, and I downloaded the gapless test sample from the hydrogenaudio wiki, converted it to flac, and played with mplayer. Obvious gaps are introduced simply doing mplayer *.

Who was it that said mplayer was gapless? Does it have to be compiled specially or something? I installed it from the Hardy reps.

mythmaster
05-29-08, 10:34 PM
It's still nongapless without the -af. I'm here at work now different computer, and I downloaded the gapless test sample from the hydrogenaudio wiki, converted it to flac, and played with mplayer. Obvious gaps are introduced simply doing mplayer *.

Who was it that said mplayer was gapless? Does it have to be compiled specially or something? I installed it from the Hardy reps.

To be clear we're talking about the same thing...you're talking about gaps in between songs, aren't you? When I play a Grateful Dead show, it sounds like one long track (which it was originally), no skips, pops, gaps, or anything in between tracks. That's on my Gentoo box, but I didn't use any out-of-the-ordinary configure options. I'll try it later with a gd set on the Mythbuntu box.

EDIT: I STAND CORRECTED!! There *is* a noticeable gap in mplayer. There is *not* one, however, in Amarok, so if you set up your crossfeed in alsa, you'll be good to go (assuming it works as advertised -- I haven't tried it).

Daravon
05-30-08, 09:26 AM
Further development: discovery of aqualung, an unstable but totally gapless player that has a very nice LADSPA plugin interface. Has a lot of cool plugins including tube sound, vinylizer (with options for record warpage, year recorded and wear, which is amusing) and, with a bit of fiddling, the Bauer b2sb plugin. It's a bit unstable though and alsa output sounds bad. OSS output seems to be fine though.

Daravon
05-30-08, 06:57 PM
further development: The b2sb TAP plugin does not actually do anything. So aqualung is pointless, but for the other amusing DSPs.

mythmaster
05-30-08, 09:51 PM
Do you mean that it doesn't work at all or it doesn't sound right?

Daravon
05-31-08, 10:16 AM
It didn't work whatsoever.

mythmaster
05-31-08, 11:40 AM
Did you install TAP from CVS? Just double-checking.

Daravon
05-31-08, 02:11 PM
To be honest my friend with much stronger linux-fu did the installing. He did say that he got the b2sb plugin from cvs, note, I do not know what that means. But in my aqualung I have a ton of very cool DSPs now, most of which work, but the TAP-b2sb plugin does nothing. Some of the stranger dsps also crash aqualung, but the b2sb seems to do nothing at all.

mythmaster
05-31-08, 02:42 PM
Interesting. Is there somewhere for you to adjust the settings for it? There's a reasonably coherent discussion of what the settings do at the forum --> http://www.hydrogenaudio.org/forums/lofiversion/index.php/t38291-50.html

Also, you could try setting the controls in .asoundrc as demonstrated at the link I posted earlier (the one from the amarok wiki).

Daravon
05-31-08, 02:55 PM
Yeah, the aqualung interface allowed you 3 different levels and an optional 'high boost'. We tried them all.

Patching the plugin into alsa as per the amarok how-to is my only open option now, but it doesn't look like it would be easy to turn off and on, that is, if I wanted to watch a stereo movie using speakers it would still be applying the DSP, unless I manually copied the config file. At least I think so.

mythmaster
05-31-08, 03:06 PM
I'm pretty sure there's a way that you can *not* make it the default alsa setting and just have your music player use it, but I've never done it.

The alsa wiki (http://alsa.opensrc.org/index.php/Main_Page) is the place to go for that info.

mythmaster
06-01-08, 11:03 AM
Yeah, just leave out the "pcm.!default" section, and you can rename "pcm.ladspa" to something more convenient, e.g. "pcm.headphones". You will then have a new device called "headphones" (or whatever) that you can tell your music player to use.

Daravon
06-06-08, 12:57 PM
The ladspa/alsa thing doesn't seem to work. This is no surprise since the plugin doesn't work in aqualung either; I don't see any reason why it would work when used by alsa.

mythmaster
06-06-08, 07:04 PM
Bummer. Maybe the xmms plugin? SOMETHING's gotta work...too many people say they like it.

fatso83
06-25-08, 04:37 PM
If you liked foobar2000 so much, why don't you just use that? Then you can continue using your plugins and all the rest you used to like.

Wine will happily install and run foobar for you, but you might have to fiddle around a bit to get the sound running if it doesn't work out of the box.
It's Microsoft Windows you want to get away from, not the great apps :)

Daravon
06-25-08, 05:10 PM
I tried running foobar, but it looked funny and crashed on me a few times.

I still haven't found any working crossfeed DSP in linux, which is a true shame, but I built a RC circuit to implement a crossfeed in hardware. I'd much rather use DSP, but at least this way I have something, and it works with my LPs too.

fatso83
06-25-08, 05:23 PM
Too bad, I use at this moment! I actually downloaded and installed it after tipsing you. Even installed the bs2b plugin, and it's working nicely. Just needed a good sound sample to hear the difference.

But the look and sound of foobar is like in Windows. Wine just released version 1.0 - the first (supposedly) stable version since the conception 15 years ago, so maybe you should give it a new go?

http://folk.ntnu.no/kopseng/bildegalleri/main.php?g2_view=core.DownloadItem&g2_itemId=4386&g2_serialNumber=2 (http://folk.ntnu.no/kopseng/bildegalleri/main.php?g2_itemId=4384&g2_imageViewsIndex=1)

I have to admit I did the step A in this guide (http://ubuntuforums.org/showthread.php?t=789578&highlight=wine+alsa) for getting PulseAudio running, and prepend the "padsp" to the wine command to actually get the sound working.