[AE] Fix standard layouts #1490

Closed
wants to merge 2 commits into
from

Projects

None yet

10 participants

@Karlson2k
Member

This fix strange 5.1 mapping like that:

INFO: ==[Downmix Matrix]==
INFO: FL = FL(1) SL(0.707107)
INFO: FR = FR(1) SR(0.707107)
INFO: FC = FC(1)
INFO: LFE = LFE(1)
INFO: BL = SL(0.707107)
INFO: BR = SR(0.707107)
INFO: ====================

After that patch mapping is right:

INFO: ==[Downmix Matrix]==
INFO: FL = FL(1)
INFO: FR = FR(1)
INFO: FC = FC(1)
INFO: LFE = LFE(1)
INFO: SL = SL(1)
INFO: SR = SR(1)
INFO: ====================
@elupus
Member
elupus commented Sep 27, 2012

I'm pretty sure there was some reason for that.

@Memphiz
Member
Memphiz commented Sep 27, 2012

I would say to loud special effects - to low speech ;)

@Memphiz
Member
Memphiz commented Sep 27, 2012

Ohh nvm ... missread the outputs. Better wait for the AE guys.

Karlson2k added some commits Sep 27, 2012
@Karlson2k Karlson2k [AE] Fix standard layouts
Replace outdated 5.1 layout (Back Left and Back Right) with current standard 5.1 layout  (Side Left and Side Right).
This fix strange 5.1 mapping like that:
INFO: ==[Downmix Matrix]==
INFO: FL = FL(1) SL(0.707107)
INFO: FR = FR(1) SR(0.707107)
INFO: FC = FC(1)
INFO: LFE = LFE(1)
INFO: BL = SL(0.707107)
INFO: BR = SR(0.707107)
INFO: ====================
f61e2bf
@Karlson2k Karlson2k [AE] Cosmetics and comments 53e201e
@Karlson2k
Member

Separated code change and cosmetics.

@elupus Reason is old standard. Right now Side Left & Side Right used everywhere (DVD, BD, TV) instead of Back Left & Back Right in 5.1. That's current standard.

@gnif
Member
gnif commented Sep 27, 2012

@Karlson2k - I avoid this if I was you, this is NOT the standard behaviour, expect to get flamed in the forums for this change.

@elupus
Member
elupus commented Sep 27, 2012

As far as I can see it has not been pushed to master yet. But it does
indeed seem lika a wrong change.

@Karlson2k
Member

Some info: see AC3 standard http://www.atsc.org/cms/standards/a_52-2010.pdf , section 5.4.2.3, table 5.8
http://msdn.microsoft.com/en-us/library/windows/hardware/ff537573(v=vs.85).aspx
http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/SpkrConfig5.docx
Or just look at defs of KSAUDIO_SPEAKER_5POINT1_SURROUND in KsMedia.h

You can also check http://www.dolby.com/us/en/consumer/setup/connection-guide/home-theater-speaker-guide/index.html
As you can see for 5.1 there are no back left and back right, but side left and side right.

@gnif
Member
gnif commented Sep 28, 2012

@Karlson2k - Please note that those diagrams support the current layout...

SBR or as we call it, BR, is not the same as SR
SBL or as we call it BL, is not the same as SL

Please look at those diagrams more closely.

@gnif
Member
gnif commented Sep 28, 2012

Either way, the code was as you are suggesting here is how it used to be, we were flamed by audiophiles for it being incorrect and sounding terrible on their 5.1 setup, there are a few very lengthy trac tickets that describe that the behaviour you are suggesting is wrong, and the correct behaviour is what is currently implemented.

@gnif
Member
gnif commented Sep 28, 2012

Just did some digging, @alanwww1 is the one that would be able to comment on this one and set matters straight.

@alanwww1
Member

Not sure I am the right one for this task :-) , but what I think we could do is do a couple of tests with the channel identification tests files I collected together and see how they are downmixed in major commercial or opensource players.
Here are my test files (hope the links work)
https://rapidshare.com/files/28912283/Audio_channel_ID_files.zip?bin=1
https://rapidshare.com/files/3894124765/Video_channelID_files.zip?bin=1

I'll only have time in the weekend to make some tests.
@Karlson2k could you please make tests with these files, how are they downmixed in major players ?

@Karlson2k
Member

@gnif The difference between 5.1 and 7.1 is back speakers; side speakers (no matter how we call them) are on same positions in 5.1 and in 7.1. In current XBMC code difference between 5.1 and 7.1 is side speakers, that's wrong for sure.

Side speakers is explicitly defined in AC3 standard. And when playing any DVD, BD or mkv with 5.1 AC3 on 5.1 speakers, we must get one-to-one matching. Right now 5.1 AC3 is remixed in channels.

@Karlson2k
Member

@alanwww1 OK, I'll do some tests.

@da-anda
Member
da-anda commented Sep 28, 2012

my receiver also shows 5.1 "rear speakers" as "rear side speakers" and only uses the real rear speakers for 7.1. That's at least what I noticed if this helps.

@Karlson2k
Member

Done tests with MPC-HC, AC3Filter, FFDShow, Windows Media Player 11, PowerDVD 12, WinDVD 11.
Results are very inconsistent, especially with opensource products.
Looks like noone know how to implement it right so in one part of project something implemented in one way, in other part - in other way.
If throw away most inconsistent results, than AC3 5.1 and DTS 5.1 in 7.1 systems mostly routed to side speakers, AAC 5.1 in 7.1 is mostly routed to back.
In case of 5.1 speakers setup, even 5.1 streams are remixed. In most cases 7.1 side speakers is routed to front and surround, and back speakers is routed only to surround. (for 5.1 speakers setup)
More results tomorrow. It's 1am here. :)

@DDDamian
Contributor

I think this is why custom channel maps was on the list lol, along with level adjustments (mostly for boosting center channels).

It really should be a user preference for those that have 7.1 systems (I do). I want/expect 5.1 to play to my fronts and sides, and the receiver does its PLIIx processing for the backs.

@jmarshallnz
Member

Surely that is what one always wants. 7.1 == 5.1 + 2 rears. 6.1 == 5.1 +
1 rear. This is all quite well defined, so no matter what we get there
should be an explicit map available, right?

On Sat, Sep 29, 2012 at 10:16 AM, Damian Huckle notifications@github.comwrote:

I think this is why custom channel maps was on the list lol, along with
level adjustments (mostly for boosting center channels).

It really should be a user preference for those that have 7.1 systems (I
do). I want/expect 5.1 to play to my fronts and sides, and the receiver
does its PLIIx processing for the backs.


Reply to this email directly or view it on GitHubhttps://github.com/xbmc/xbmc/pull/1490#issuecomment-8997016.

@DDDamian
Contributor

@jmarshallnz - my thoughts exactly. If you take a 7.1 speaker test file (DTS-MA) it's all very clear. If there's any doubt it should be esotoric 7.1 wide or 9.1/2 setups, for which there is precious little hardware support let alone recordings.

The definitions are out there and defined, and we should allow for them in enums just cause. The writers of the FLAC standard intentionally avoided clear channel definitions for a reason: there was no prior accepted definition nor much chance of an agreed standard beyond 5.1. M$ took it a step further and defined them with the option to remap them at will, because it was all out in the fringe. Not many people in the foreseeable future will have >7.1/2 nor will recordings. What one does with >7.1 hardware is a crapshoot because you have to extrapolate existing recording channels.

In win they use the speaker mask parameter to direct tracks to whichever channel you want, and mappable software channels just mirrors that. The levels of actual audio data mapped to a given channel are more the issue here.

5.1 audio doesn't care whether they're "sides" or "backs" - that's more of a physical speaker positioning argument. For 7.1 the standard is defined by the only true 7.1 mixes which are DTS-HD/TrueHD - no FLAC definition exists for that speaker layout.

@Karlson2k
Member

Agree with @jmarshallnz and @DDDamian.
Some conclusions:

  • AC3 standard defines surround speakers as side speakers (not back) (here, section 5.4.2.3, table 5.8).
  • Commercial players, that pretend to strictly follow standards, play AC3 and DTS 5.1 tracks on side speakers.
  • 6.1 = 5.1 + back center, 7.1 = 5.1 + back speakers. (here and here)
  • Microsoft screwed things up by ambiguous definitions. FL + FR + FC + LFE + BL + BR should be interpreted by MS decision as FL + FR + FC + LFE + SL + SR (More info here). Moreover, MS require sound driver to play 5.1 streams on 7.1 side channels even if driver is requested to use 7.1 back channels (More info here). In the same time Windows Control Panel show 5.1 config as back speakers and internally interpret it as side speakers. (More info).
  • Most of the users will be happy if 5.1 streams will be played on their 5.1 systems without remixing of channels.
  • XBMC already correctly detects channels in AC3 and DTS streams.

Final conclusion:
To get code working right we need to define correct 5.1 speakers setup as suggested in this PR. Than 5.1 context (that already correctly detected) will be played correctly. If we leave speakers setup as is, than we need some kind of hacks to remap properly detected side channels to back channels.
It's also a good idea to implement an option in settings to use side speakers as back speakers for users who willing to place speakers really behind the listener. If I'll have time, I'll implement it.

To fully understand Windows situation with back and side speakers, I suggest following reading:

  • http://msdn.microsoft.com/en-us/library/windows/hardware/gg463023.aspx
  • http://msdn.microsoft.com/en-us/library/windows/hardware/ff537573.aspx (quotes: "Windows ... do not define a new 5.1 format descriptor to distinguish the 5.1 side-speaker configuration from the 5.1 back-speaker configuration", "vendor should ensure that the two side-speaker channels in the 5.1-channel stream play through the side speakers rather than the back speakers", "when playing content authored for the "7.1 home theater speakers" configuration through a 5.1 speaker configuration with side speakers, the channels for the 7.1 side speakers most naturally map to the side speakers in the 5.1 configuration")
  • http://msdn.microsoft.com/en-us/library/windows/hardware/ff537511.aspx (quotes: "Although having only a single 5.1-channel format descriptor avoids confusing users, it does require hardware vendors to remember to interpret the 0x3F channel mask to mean that channels 5 and 6 are assigned to the SL and SR speaker positions instead of the BL and BR positions.", " if the system mixer produces a 5.1-channel output stream, the mixer always sets the stream's channel mask to 0x3F. The system mixer behaves this way even if it receives a 5.1-channel input stream with a channel mask of 0x60F. With this behavior, an audio driver never receives a 5.1-channel stream with a channel mask of 0x60F from the mixer.")
  • http://msdn.microsoft.com/en-us/library/windows/hardware/gg463015.aspx
@Karlson2k
Member

It's also a good idea to implement an option in GUI to get 5 channels content always played on 5 speakers setup without remuxing, not matter now content defines speakers placement.

@DDDamian
Contributor

@Karlson2k - agree with all but your last comment - no GUI setting for this one. It's just unnecessary and confusing.

@DDDamian
Contributor

FYI a concise article summarizing the standards can be found here: http://www.jensign.com/bdp95/7dot1voiced/index.html

Interestingly for the 7.1 wav file linked on that page MediaInfo shows an incorrect channel mapping. Audacity maps it correctly.

Using the 7,1 FLAC from @alanwww1's zip XBMC is mapping correctly:
11:54:14 T:4076 INFO: Sample Rate : 48000
11:54:14 T:4076 INFO: Sample Format : AE_FMT_S24NE4
11:54:14 T:4076 INFO: Channel Count : 8
11:54:14 T:4076 INFO: Channel Layout: FL,FR,FC,BL,BR,SL,SR,LFE
11:54:14 T:4076 INFO: Frames : 2400
11:54:14 T:4076 INFO: Frame Samples : 19200
11:54:14 T:4076 INFO: Frame Size : 32
11:54:15 T:4076 INFO: CSoftAE::InternalOpenSink - keeping old sink with : AE_FMT_FLOAT, FL,FR,FC,BL,BR,SL,SR,LFE, 48000hz
11:54:15 T:4076 DEBUG: CSoftAE::InternalOpenSink - Using speaker layout: 7.1

although it exposes us hitting this several hundred times:
11:54:16 T:248 WARNING: CAEUtil::GuessChLayout - This method should really never be used, please fix the code that called this

because FLAC does not define the channel layout - although at least we "guess" it right.

Ditto with the .wav file from my link where dwChannelMask is defined.

@DDDamian
Contributor

Downmixed to 2.0 the center channel is completely arsed....

@anssih
Member
anssih commented Sep 30, 2012

I think before AE we used to simply consider SL+SR without BL+BR input as BL+BR if the output device has only BL+BR without SL+SR (and/or vice versa). In my opinion this would be the best approach, since IMO generally it is a good idea to match 5.1 input directly to 5.1 output no matter if input is side/back and output sink is side/back

(and I think whether a 5.1 audio has back or side depends also on the sink library, e.g. ALSA always has 5.1 with back speakers while I guess other systems may consider them as side speakers - also, I guess most audio codecs would use the side speakers instead).

To clarify, I mean:

Input: FL FR C LFE BL BR
Ouput: FL FR C LFE BL BR
=> 1-to-1 mapping

Input: FL FR C LFE SL SR
Ouput: FL FR C LFE SL SR
=> 1-to-1 mapping

Input: FL FR C LFE SL SR
Ouput: FL FR C LFE BL BR
=> 1-to-1 mapping

Input: FL FR C LFE BL BR
Ouput: FL FR C LFE SL SR
=> 1-to-1 mapping

Input: FL FR C LFE SL SR BL BR
Output: FL FR C LFE BL BR
=> mixing

Input: FL FR C LFE SL SR BL BR
Output: FL FR C LFE SL SR
=> mixing

This can be achieved by e.g.

a) Always considering output with SL SR without BL BR as BL BR instead, and then direct any input with SL+SR without BL+BR to BL+BR if output has not SL+SR, or

b) Always considering output with BL BR without SL SR as SL SR instead, and then direct any input with BL+BR without SL+SR to SL+SR if output has not BL+BR, or

c) Direct any input with SL+SR without BL+BR to BL+BR if output has not SL+SR, and any input with BL+BR without SL+SR to SL+SR if output has not BL+BR.

@DDDamian
Contributor

Formats like FLAC do not encode any position info, e.g. it does not describe whether 5.1 audio contains BR/BL info or SR/SL info. Most of this conversation will apply only to PCM data and FLAC will be the most common of those for input streams.

We really just need to follow the standards:
5.1 in -> 5.1 out = 1:1 with a map of FL FR C LFE BL BR
7.1 in -> 7.1 out = 1:1 with a map of FL FR C LFE BL BR SL SR
5.1 in -> 6.1 out = 1:1 let avr mix BC
5.1 in -> 7.1 out = 1:1 let avr mix BL BR <- most avr's will send the surround channels to SL SR and matrix BL BR

All of the above are just 1:1 or upmixes - downmixes are a different animal and where I see an issue with C

IMHO the issue is more with quad (4.0), 5.0 (crashes), AAC and Vorbis (only AAC really matters) and USB or other audio cards with 8ch analog outputs. These really need custom channel maps as they won't auto-interpret PCM data the way most avr's will....

@Karlson2k
Member

@DDDamian Small addition.
Proper mapping for AC3 5.1 and DTS 5.1 is FL FR C LFE SL SR.
There are some files with explicitly defined FL FR C LFE BL BR.
In any case we should play both types on 5.1 setup (no matter how system report it) as 1:1.
But in case of 6.1 and 7.1 system we should set output to configuration, specified in file.

@Karlson2k
Member

And again back to this PR.
See my coments here: #1490 (comment)

@DDDamian
Contributor

"But in case of 6.1 and 7.1 system we should set output to configuration, specified in file."

Yep - that's kinda where I was going with the channel mapping thing. A good example (albeit done in GUI) would be AC3Filter, although there's many others. It solves everything including quad and 5.0, we would need to provide a default mapping file as part of the build to make it invisible/seamless upon install.

Check back to the original list I had sent you ;)

@Karlson2k
Member

@DDDamian It's in my to-do list. :)
But while it isn't implemented yet, will we push this PR to master?

@DDDamian
Contributor

Not until:

  • we check the downmix code (it's amiss in the matrix you quote and in center-channel mixing, and
  • we hear from other platform devs as it's a core change and I'm unsure of the affect on ALSA
@DDDamian
Contributor

I also note LFE position is moved for 5.1 and not 7.1? Regardless, I'm not comfortable with some other ramifications yet (e.g. ALSA).

@LongChair LongChair added a commit to plexinc/plex-home-theater-public that referenced this pull request Apr 30, 2015
@LongChair LongChair Disable Automatic Login setting if not applicable, fixes #1490 ec38f83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment