Win [Workaround] Boost center channel for stereo, fix downmixing issues
#1
Hi there,

I really like XBMC but for a long time I was seriously disappointed by the way XBMC handled mixing down 5.1 Sound to stereo. While my research showed, that I'm not the only one with this problem I wasn't able to find a proper solution for this.
Some suggested, that this was because of a bad down-mixing matrix, which would disregard the center channel. As an effect the center channel would not be loud enough compared to back left/right and front left/right.
Today I managed to solve this for me, it's messy, it's hardcoded but it's working.

A few words on the principle:
Downmix matrix in EDEN is handled very basic. When you look at the Eden source code provided on the main site you will find a file called "PCMRemap.cpp".
In this file the downmixing is realised. The following structure allows for different channels to be mapped to other channels, while the following number indicates a gain or loss in volume:
Code:
static struct PCMMapInfo PCMDownmixTable[PCM_MAX_CH][PCM_MAX_MIX] =
{
  /* PCM_FRONT_LEFT */
  {
    {PCM_INVALID}
  },
  /* PCM_FRONT_RIGHT */
  {
    {PCM_INVALID}
  },
  /* PCM_FRONT_CENTER */
  {
    {PCM_FRONT_LEFT_OF_CENTER , 1.0},
    {PCM_FRONT_RIGHT_OF_CENTER, 1.0},
    {PCM_INVALID}
  },
  /* PCM_LOW_FREQUENCY */
  {
    /*
      A/52B 7.8 paragraph 2 recomends +10db
      but due to horrible clipping when normalize
      is disabled we set this to 1.0
    */
    {PCM_FRONT_LEFT           , 1.0},//3.5},
    {PCM_FRONT_RIGHT          , 1.0},//3.5},
    {PCM_INVALID}
  },
  /* PCM_BACK_LEFT */
  {
    {PCM_FRONT_LEFT           , 1.0},
    {PCM_INVALID}
  },
  /* PCM_BACK_RIGHT */
  {
    {PCM_FRONT_RIGHT          , 1.0},
    {PCM_INVALID}
  },
  /* PCM_FRONT_LEFT_OF_CENTER */
  {
    {PCM_FRONT_LEFT           , 1.0},
    {PCM_FRONT_CENTER         , 1.0, true},
    {PCM_INVALID}
  },
  /* PCM_FRONT_RIGHT_OF_CENTER */
  {
    {PCM_FRONT_RIGHT          , 1.0},
    {PCM_FRONT_CENTER         , 1.0, true},
    {PCM_INVALID}
  },
  /* PCM_BACK_CENTER */
  {
    {PCM_BACK_LEFT            , 1.0},
    {PCM_BACK_RIGHT           , 1.0},
    {PCM_INVALID}
  },
  /* PCM_SIDE_LEFT */
  {
    {PCM_FRONT_LEFT           , 1.0},
    {PCM_BACK_LEFT            , 1.0},
    {PCM_INVALID}
  },
  /* PCM_SIDE_RIGHT */
  {
    {PCM_FRONT_RIGHT          , 1.0},
    {PCM_BACK_RIGHT           , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_FRONT_LEFT */
  {
    {PCM_FRONT_LEFT           , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_FRONT_RIGHT */
  {
    {PCM_FRONT_RIGHT          , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_FRONT_CENTER */
  {
    {PCM_TOP_FRONT_LEFT       , 1.0},
    {PCM_TOP_FRONT_RIGHT      , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_CENTER */
  {
    {PCM_TOP_FRONT_LEFT       , 1.0},
    {PCM_TOP_FRONT_RIGHT      , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_BACK_LEFT */
  {
    {PCM_BACK_LEFT            , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_BACK_RIGHT */
  {
    {PCM_BACK_RIGHT           , 1.0},
    {PCM_INVALID}
  },
  /* PCM_TOP_BACK_CENTER */
  {
    {PCM_TOP_BACK_LEFT        , 1.0},
    {PCM_TOP_BACK_RIGHT       , 1.0},
    {PCM_INVALID}
  }
};

So PCM_FRONT_CENTER(FC) maps to PCM_FRONT_LEFT_OF_CENTER(FLC), PCM_FRONT_RIGHT_OF_CENTER(FRC) and itself, in a stereo setting the three of them are not existing. FLC and FRC now map (besides others) on PCM_FRONT_LEFT and PCM_FRONT_RIGHT, so if one likes center to be increased the values for this adjustment should be changed, increased in this case, so for a value of "2.0" it should look like:
Code:
[...]
  /* PCM_FRONT_LEFT_OF_CENTER */
  {
    {PCM_FRONT_LEFT           , 2.0},
    {PCM_FRONT_CENTER         , 1.0, true},
    {PCM_INVALID}
  },
  /* PCM_FRONT_RIGHT_OF_CENTER */
  {  
    {PCM_FRONT_RIGHT          , 2.0},
    {PCM_FRONT_CENTER         , 1.0, true},
    {PCM_INVALID}
  },
[...]
Thats no big deal and nearly anybody should be able to do so by changing the "PCMRemap.cpp" and compile XBMC using the HOW-TO in the Wiki, if you manage to get an "XBMC.exe" with your "PCMRemap.cpp" just copy it over to your XBMC-Directory and you should be fine (do a backup of the original "XBMC.exe", just in case...).

For comparison:
with original values (out of the box EDEN):
Code:
17:08:13 T:2660   DEBUG: CPCMRemap: FL = FL(0.292893) CE(0.207107) LFE(0.207107) BL(0.292893)
17:08:13 T:2660   DEBUG: CPCMRemap: FR = FR(0.292893) CE(0.207107) LFE(0.207107) BR(0.292893)
with values of "2.5"
Code:
17:09:48 T:2212   DEBUG: CPCMRemap: FL = FL(0.223470) CE(0.395043) LFE(0.158017) BL(0.223470)
17:09:48 T:2212   DEBUG: CPCMRemap: FR = FR(0.223470) CE(0.395043) LFE(0.158017) BR(0.223470)

Well the drawback:
- you may need to enable normalization (remember, in the stable Eden-release ON and OFF are switched, so ON=OFF and vice versa, at least for me!) (depending on the gaining-factor)
- this works just for Eden as with Audio Engine being new in v12 the remapping also changed and at a quick look i haven't been able to easily change this in v12, maybe it won't need changing after all but for the moment I want to stick with EDEN and thus needed this problem fixed in there...

As the process is simple I compiled the XBMC.exe for Values of 1.5, 2.0, 2.5, 3.0 and 3.5, I personally prefer a value of 2.5 but you may decide this on your own
Download here: http://uploaded.net/file/7xmczobv (ca. 21MB) and just replace your "XBMC.exe" with your preferred from the archive
(consider making a backup of your own before!)


Enjoy!

Edit: I'm not that much into GPL and publishing Software, but I hope as I explained the changes and as they are very very minor I'm allowed to offer the compiled executables, if not please contact me and i will remove them asap.
Reply
#2
@kikakeule - well done, and the minor patch like that is officially blessed - you have published the source code for the patch above Wink
System: XBMC HTPC with HDMI WASAPI & AudioEngine - Denon  AVR-3808CI  - Denon DVD-5900 Universal Player  - Denon DCM-27 CD-Changer
- Sony BDP-S580 Blu-Ray  - X-Box 360  - Android tablet wireless remote - 7.1 Streem/Axiom/Velodyne Surround System
If I have been able to help feel free to add to my reputation +/- below - thanks!
Reply
#3
Thanks!!! I'll give it a shot tomorrow! Look forward to seeing how it works.
Reply
#4
Thank you so much for this effort. I'm surprised this is not a bigger issue with users of Xbmc. I know a few & they don't hear anything wrong with the sound.

Before I do it I have one small question.

Will this solution effect bitstreaming?

My HTPC feeds two rooms. Sometimes at the same time. My tv with stereo hifi back room & My cinema projection screen front room which has a DTS/Dolby capable receiver & 5.1.
Xbmc is able to bitstream over hdmi and keep the analog output going at the same time. A feature I never thought I would have.
I'm hopeful that your work around will not effect things. I guessing just replacing the original .exe will revert any changes made by the modified .exe?

Downmixing & a WMC quality Pvr are the only two obstacles standing in the way of my perfect media centre life.

Reply
#5
glad you like it!

I'm not using bitstream but as far as I can tell it should not be affected, as its just passed through without being modified in any way...
and like you said: changing exe back again should revert anything to normal.
Reply
#6
Nice 1.
Now if only I could fecken download it.
Reply
#7
Nice 1. It worked perfectly but it highlighted another problem I had not spotted.
The multiple audio options I had were gone when I went to the cinema to compare your exe stereo sound to the bitstreaming sound.
For some reason the official Xbmc exe does not have multiple audio options on my pc.
I had initially installed a prebuild of Xbmc with pvr support by Margro found here.
http://www.scintilla.utwente.nl/~marcelg...build.html

I reinstalled the Margro version and up came the extra options.
Any ideas why this might be?
Do you have one or three audio options in your settings

Standard Xbmc exe audio options.
http://images55.fotki.com/v268/photos/5/...ons-vi.png

Margro Xbmc exe audio options.
http://images15.fotki.com/v588/photos/5/...ons-vi.png
Reply
#8
Sorry for the delayed answer, had some issues with my network...
i think you got the following patch enabled in the Margro-Build:
http://forum.xbmc.org/showthread.php?tid=86038

using the provided source in the link and my changes from above you should easily be able to build a binary with boost and two audio outputs.
I would've tried to do this for you but unfortunately I'm not able to download the provided source code in the link due to issues with skydrive (where the author stored the source...)
Reply
#9
You the man, man!
I went off and ordered another graphics card anyway. Hopefully having two Hdmi audio outs will simplify things a little for me.
Since moving form Wmc to Xbmc I'm counting the days to Frodo and Pvr goodness. Hopefully your fix will then be redundant & we will all be in Media Centre heaven.

Thanks again for your help.
Cheers.
Reply
#10
kikakeule, I would really like to try out your builds of XBMC that have the center channel properly boosted after the stereo downmix, but unfortunately every time I attempt to download your file the hosting site tells me that all their download slots are taken and that I should retry in a few minutes. I have done that many times now, and I get the same message every time. Registering for a free account didn't help, either.

Is there any chance that you could post the file on a different file sharing service? I realize that I could figure out how to compile XBMC myself, but I would be very grateful if you could save me a lot of time by posting your already compiled files on another download service.
Reply
#11
(2012-10-28, 21:08)gharkay Wrote: Is there any chance that you could post the file on a different file sharing service? I realize that I could figure out how to compile XBMC myself, but I would be very grateful if you could save me a lot of time by posting your already compiled files on another download service.


Credit to kikakeule. Just uploaded to different host for you:

http://rapidgator.net/file/52968436/XBMC...N.rar.html
Reply
#12
(2012-10-28, 21:08)gharkay Wrote: kikakeule, I would really like to try out your builds of XBMC that have the center channel properly boosted after the stereo downmix, but unfortunately every time I attempt to download your file the hosting site tells me that all their download slots are taken and that I should retry in a few minutes. I have done that many times now, and I get the same message every time. Registering for a free account didn't help, either.

Is there any chance that you could post the file on a different file sharing service? I realize that I could figure out how to compile XBMC myself, but I would be very grateful if you could save me a lot of time by posting your already compiled files on another download service.
i had the same problem. Chrome was my issue. Internet explorer worked straight away.
Reply
#13
(2012-10-28, 21:47)john.doe Wrote:
(2012-10-28, 21:08)gharkay Wrote: Is there any chance that you could post the file on a different file sharing service? I realize that I could figure out how to compile XBMC myself, but I would be very grateful if you could save me a lot of time by posting your already compiled files on another download service.


Credit to kikakeule. Just uploaded to different host for you:

http://rapidgator.net/file/52968436/XBMC...N.rar.html

Thanks so much for trying, john.doe, but unfortunately I am getting a File Not Found error from Rapid Gator regardless of the browser I use.
(2012-10-29, 01:26)Macrezz Wrote:
(2012-10-28, 21:08)gharkay Wrote: kikakeule, I would really like to try out your builds of XBMC that have the center channel properly boosted after the stereo downmix, but unfortunately every time I attempt to download your file the hosting site tells me that all their download slots are taken and that I should retry in a few minutes. I have done that many times now, and I get the same message every time. Registering for a free account didn't help, either.

Is there any chance that you could post the file on a different file sharing service? I realize that I could figure out how to compile XBMC myself, but I would be very grateful if you could save me a lot of time by posting your already compiled files on another download service.
i had the same problem. Chrome was my issue. Internet explorer worked straight away.

Interesting. I just tried Internet Explorer (I usually use Chrome) and still had the same issue. Maybe you just have to get really lucky with snagging an open download slot.
Edit: And now that I just finished writing those two posts, I tried again in Chrome and was able to get the original download to work. I must have clicked the download button at just the right time when there was an open slot!
Reply

Logout Mark Read Team Forum Stats Members Help
[Workaround] Boost center channel for stereo, fix downmixing issues0