Ticket #404 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

DTS 5.1 audio wrong channels.

Reported by: Ritsuka Owned by:
Priority: normal Milestone:
Component: Perian-Main Version: 1.1.3
Severity: normal Keywords:
Cc:

Description

I noticed that with dts audio the left, center and right channels are swapped. The center channel is played as the right one and the right one as the left one.

I attacched a small audio sample with a voice speaking the name of every channels.

Attachments

test.mka Download (979.7 KB) - added by Ritsuka 6 years ago.
dts audio test

Change History

Changed 6 years ago by Ritsuka

dts audio test

comment:1 Changed 5 years ago by Ryan

The issue lies in MatroskaCodecIDs.cpp.

// 5.1 is tested, the others are just guesses
static const AudioChannelLayout dtsChannelLayouts[6] = {
	{ kAudioChannelLayoutTag_MPEG_3_0_B },			// C L R
	{ kAudioChannelLayoutTag_MPEG_4_0_B },			// C L R Cs
	{ kAudioChannelLayoutTag_MPEG_5_0_D },			// C L R Ls Rs
	{ kAudioChannelLayoutTag_MPEG_5_1_D },			// C L R Ls Rs Lfe
};

can be changed to

// 5.1 is tested, the others are just guesses
static const AudioChannelLayout dtsChannelLayouts[6] = {
	{ kAudioChannelLayoutTag_MPEG_3_0_A },			// L R C
	{ kAudioChannelLayoutTag_MPEG_4_0_A },			// L R C Cs
	{ kAudioChannelLayoutTag_MPEG_5_0_A },			// L R C Ls Rs
	{ kAudioChannelLayoutTag_MPEG_5_1_A },			// L R C LFE Ls Rs
};

This makes your test file (as well as one of my own) function as expected.

The one thing that worries me is the comment that claims this was tested.

comment:2 Changed 5 years ago by gbooker

I think that FFMpeg changed it's channel layout when they did channel layout support. The problem with changing the channel layouts as they are set by MatroskaCodecID is that it leaves current reference movies permanently broken. In addition, several other channel layouts are different, so they may fall into the same boat.

The best solution is an interleaver, like the one in A52Codec, but correct function there requires QuickTime/Core Audio to not be broken:  http://openradar.appspot.com/6921431

comment:3 Changed 5 years ago by Ryan

I checked, you have the right of it. It appears that FFMpeg internally shifts its bits around using "L R C Lfe Ls Rs" (seen in the audio channel mask defines in avcodec.h).

I looked up the DTS specification, and it checks out with MatroskaCodecIDs.cpp. Those are the best default values for 3,4,5, and 5.1 channels. It also shows other potential channel layouts like for 6 and 7 channels, however the allegedly proper defaults for those have no AudioChannelLayoutTag?.
Specification found at  http://multimedia.cx/mirror/dts1.pdf, "Audio channel arrangement" on page 13.

comment:4 follow-up: ↓ 6 Changed 5 years ago by gbooker

There are two different kinds of channel layouts here. The first is describing which channels are present, which is what's defined in that pdf. We can write a parser for DTS, like AC3 in bitstream_info.c, to get this information.

The second channel layout is the one which is a problem in this bug. That defines the order of the channels when decoded. This is not defined in the DTS spec, because it shouldn't be in there. This should be agreed upon between the player and the decoder, but that bug is demonstrating that Apple failed in this regard.

QuickTime has a bit of a design flaw with channel layouts. They defined the layout with the channels present and their order in the mov file. This works great for codecs which encode channels separately, or if the order is explicitly defined, such as L and R (This order is actually defined in the Core Audio documentation, though Apple seems to have ignored it when using Core Audio in QuickTime). This is a problem (flaw) for codecs which encode several channels together, such as AC3 and DTS. What order are the channels supposed to be in if the codec is never told?

BTW, there are some audio channel layouts for 6 and 7 (and 8) channels that we can use for DTS, but the channel order becomes an issue again.

comment:5 Changed 5 years ago by gbooker

  • Status changed from new to closed
  • Resolution set to fixed

(In [1076]) Create channel interleaver for DTS (We need to add layouts for other codecs). Fixes #404

comment:6 in reply to: ↑ 4 ; follow-up: ↓ 7 Changed 5 years ago by Madd_the_Sane

Replying to gbooker:

QuickTime has a bit of a design flaw with channel layouts. They defined the layout with the channels present and their order in the mov file. This works great for codecs which encode channels separately, or if the order is explicitly defined, such as L and R (This order is actually defined in the Core Audio documentation, though Apple seems to have ignored it when using Core Audio in QuickTime). This is a problem (flaw) for codecs which encode several channels together, such as AC3 and DTS. What order are the channels supposed to be in if the codec is never told?

BTW, there are some audio channel layouts for 6 and 7 (and 8) channels that we can use for DTS, but the channel order becomes an issue again.

Has someone filed a bug report with Apple about this?

comment:7 in reply to: ↑ 6 Changed 5 years ago by gbooker

Replying to Madd_the_Sane:

Has someone filed a bug report with Apple about this?

The openradar link corresponds to a rdar (with the same number), which is a bug report with Apple.

Note: See TracTickets for help on using tickets.