Skip to main content
Topic: AAC and 7.1ch audio - fdkaac and qaac. (Read 3128 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

AAC and 7.1ch audio - fdkaac and qaac.

I've created a couple of 7.1ch wave files. When I load the first one into foobar2000 it looks like this:
FL FR FC LFE RL RR SL SR
Foobar2000 seems to use "Rear" rather than "Back" so in WAVE-EX terms that'd be:
FL FR FC LFE BL BR SL SR

If I convert that file to AAC with FDKAAC and load it into foobar2000, what displays is this:
FL FR FC LFE RL RR FCL FCR

Now if I do it the other way around and start with a wave file that looks like this:
FL FR FC LFE RL RR FCL FCR

After conversion with FDKAAC foobar2000 displays this:
FL FR FC LFE RL RR SL SR

According to the info here FDKAAC accepts two 7.1ch layouts.
http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Channel_Layouts
The only problem is, unless I'm missing something, it's getting them the wrong way round.

Maybe it's a mapping issue but when I start off with the first wave file I mentioned above
FL FR FC LFE RL RR SL SR
all the encoders I've tested seem to behave themselves in respect to encoding properly, even if they remap the channels.

For the second example though, I think fdkaac is also messing with the channel levels as well as the mapping. The test wave file I made started out as a mono channel duplicated to make things visually easier to see. The stereo channels should always be the same volume (back L/R is different to FC L/R though). The LFE channel contains the same full range audio, so if FDKAAC is applying a low pass filter to it, a volume drop might be understandable, but the difference in volume for the other channels seems like it might be a cause for concern.

I thought I'd try testing a different encoder just to make sure it's not foobar2000's fault, and the result from QAAC seems even more of a worry.

Original wave file:


After encoding FDKAAC:


QAAC:


NeroAACenc:


QAAC & Apple Lossless:


As far as I know the only other 7.1ch combination that's likely to work is this one, but FDKAAC rejects it:
FL FR FC LFE FCL FCR SL SR

Anyone know what might be going on here?
Thanks.

Re: AAC and 7.1ch audio - fdkaac and qaac.

Reply #1
Well after much experimenting, googling and banging my head against the desk, the answer was ffmpeg (foobar2000 uses it for decoding). A combination of two problems.

It turns out that FDKAAC wasn't doing anything bad, aside from creating files in such a way it caused ffmpeg to decode them incorrectly, so a 7.1ch (rear) wave file:
FL FR FC LFE BL BR SL SR
would be encoded by FDKAAC and then incorrectly decoded by foobar2000 as 7.1ch (front):
FL FR FC LFE BL BR FCL FCR
When it should decoded using the original layout:
FL FR FC LFE BL BR SL SR

It seems that problem only effects the FDKAAC encoder.
https://sites.google.com/site/qaacpage/news/fdkaac053
http://ffmpeg.org/pipermail/ffmpeg-cvslog/2015-June/090556.html
For foobar2000 the solution was to upgrade to version 1.3.10 beta 2. The current stable version (1.3.9) uses an older ffmpeg.
1.3.10 upgrades foobar2000 to the latest ffmpeg and FDKAAC encoded 7.1ch (rear) AAC is decoded correctly.

Problem number two also seems to be caused by ffmpeg decoding files incorrectly, but for a different reason. From QAAC:
https://sites.google.com/site/qaacpage/news/qaacrelease235refalac135
If you are a ffmpeg user, note that standard 7.1ch front AAC requires "-strict 1" to decode in the correct channel layout. It is due to historical reason that AAC encoders (including Nero and qaac) has been wildly mapping 7.1ch rear to 7.1ch front.

I tested the above by taking a 7.1ch (front) wave file:
FL FR FC LFE BL BR FCL FCR
and encoding it with FDKAAC, then decoding to a wave file with ffmpeg.
When I used -strict 1 in the command line I got a 7.1ch (front) wave file with the channels in the correct places:
FL FR FC LFE BL BR FCL FCR
Without -strict 1 the output was 7.1ch (rear) with the front stereo and surround channels swapped.
It seems that's the reason for the channel volume oddness I was experiencing, and why it was happening with FDKAAC and QAAC but not Nero. Unfortunately I don't think there's a fix for foobar2000. You can encode a 7.1ch (front) wave file to AAC correctly with foobar2000/FDKAAC/QAAC but you can't decode it correctly.

From an ffmpeg log file:
[aac @ 03210940] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide) layout, use -strict 1 to decode according to the specification instead.

If I understand it correctly an AAC 7.1ch (rear) file is exactly the same in layout as AAC 7.1ch (front), except with the addition of a PCE (program config element) to specify the speaker location. Without the PCE, the default layout of 7.1ch (front) is used, however some AAC encoders (such as Nero and old versions of QAAC) take the 7.1ch (rear) layout, put the side channels in the front surround channels and encode it as 7.1ch (front). In order to decode it correctly the process is reversed and it's decoded as 71.ch (rear), but that's not spec compliant.
For 7.1ch (rear) the channels can be encoded in the correct order but as that's not a standard AAC layout, a PCE must be used to set the channel order correctly.
There's no way to know if 7.1ch without a PCE is 7.1ch (front) as it supposed to be, or 7.1ch (rear) encoded incorrectly, and ffmpeg seems to assume latter and by default decodes 7.1ch (front) as 7.1ch (rear), with a messed up channel order. The "-strict 1" switch gets it to decode correctly as 7.1ch (front).

So until decoding 7.1ch AAC according to spec becomes the default, which I think it really should be, I don't think there'll be a way to decode 7.1ch (front) AAC correctly using foobar2000, unless you use the Matrix Mixer DSP and manually correct the channel layout yourself.

For the record, MPC-HC 1.7.10 (or rather it's flavour of LAV Filters) and ffdshow both decode 7.1ch (front) incorrectly.

If I've got any of the above wrong for some reason, please feel free to correct me.

Re: AAC and 7.1ch audio - fdkaac and qaac.

Reply #2
Something else I just realised, and I guess it's another reason to stop using Nero for any kind of 7.1ch encoding.....

Originally I thought Nero was the only encoder handling 7.1ch (front) audio correctly. If you look at the screenshots from my opening post, at first glance it certainly appears that way, but if you look at the channel layouts the input was 7.1ch (front), but it's being decoded as 7.1ch (rear).

Therefore, Nero must also remap 7.1ch (front) audio..... which effectively means.... because it remaps 7.1ch (rear) audio, encoding it as 7.1ch (front), and that results in 7.1ch (front) having to be decoded incorrectly, it remaps 7.1ch (front) too in order to compensate, however as a result 7.1ch (front) audio encoded by Nero can never be decoded correctly, and 7.1ch (front) audio encoded by other encoders is likely to be decoded very incorrectly.

I'm not saying all that makes Nero bad..... back in the day there may have been no other option..... but maybe it's time to put an end to producing non-compliant encodes so eventually non-compliant decoding can go away.

Also, if anyone's interested, FhGAAC seems incapable of encoding 7.1ch (rear) audio correctly, which is a shame, as it's probably the most common type. Best as I can tell it encodes it as 7.1ch (front) as Nero does, but it doesn't remap it accordingly, so if it's decoded by ffmpeg without the "-strict 1" option, it ends up decoded as 7.1ch (rear) with the front stereo and side surround channels swapped. If it's decoded with "-strict 1" it ends up as 7.1ch (front) with the original side surround channels in the FLC and FLR speakers.
FhGAAC encodes 7.1ch (front) correctly though, even if ffmpeg needs "-strict 1" to decode it properly.

The whole 7.1ch AAC situation seems to be quite a mess, although at least now I think I know what to expect and what's complaint and what isn't.

Re: AAC and 7.1ch audio - fdkaac and qaac.

Reply #3
I'm adding FFmpeg -strict option to foobar2000 so these files can be decoded correctly.
However using non default -strict mode is apparently not recommended by FFmpeg developers, so I can't make -strict 1 enabled by default.

Re: AAC and 7.1ch audio - fdkaac and qaac.

Reply #4
Awesome. Thanks Peter.
I was new to the 7.1ch AAC situation and it confused the hell out of me until I worked out what was happening.

It's nice to have an option to decode it properly, although given LAV Filters and ffdshow etc decode 7.1ch (front) as 7.1ch (rear) and given the native ffmpeg AAC encoder does it the same way Nero does. I guess that won't be changing in a hurry.

I've attached some files to a post here that I don't think foobar2000 is decoding correctly, channel layout-wise, in case you missed it. https://hydrogenaud.io/index.php/topic,111502.0.html

Thank you, and thanks for foobar2000!

 
SimplePortal 1.0.0 RC1 © 2008-2019