From: Matthias D. <ml...@mo...> - 2008-11-07 18:39:49
|
# HG changeset patch # User Matthias Dahl <ml...@mo...> # Date 1226066417 0 # Node ID 51f9597d25183373cde3081316b782ea7eeffbcc # Parent 5643c1e9b95a74dbef5c56c721b4e55d3dfe4e3a aac channel ordering for multi-channel audio Date: Sun, 28 Sep 2008 20:17:54 +0200 The channel order of aac 5.1 audio is wrong during playback. IIRC, the internal channels order for this kind of streams is the same as dts: dts output is reordered according to alsa specs (and ac3 5.1 also works), but aac is not and - for instance - front center is send to front left. The audio channels configuration table should be something like this ## --------------------- ## | Config: 5.1 Ch | ## ---- ---------------- -------------- -------------- ## | Ch | AAC/DTS | ALSA | AC3 | ## ---- ---------------- --------------- -------------- ## | 00 | Center front | Left front | Left front | ## | 01 | Left front | Right front | Center | ## | 02 | Right front | Left back | Right front | ## | 03 | Left back | Right back | Left back | ## | 04 | Right back | Center | Right back | ## | 05 | LFE | LFE | LFE | ## ---- ---------------- --------------- -------------- diff -r 51f9597d25183373cde3081316b782ea7eeffbcc -r 5643c1e9b95a74dbef5c56c721b4e55d3dfe4e3a ChangeLog --- a/ChangeLog Fri Nov 07 14:00:17 2008 +0000 +++ b/ChangeLog Fri Nov 07 13:58:41 2008 +0000 @@ -6,6 +6,7 @@ xine-lib (1.1.16) 2008-??-?? * Fix timing issues (broken audio) on mingw. * Add ID3 tag TDRC to replace/complement the deprecated tag TYER. * Add a new meta-tag, "Composer", and use it in the FLAC demuxer. + * Correct aac channel ordering for multi-channel audio xine-lib (1.1.15) 2008-08-14 * Security fixes: diff -r 51f9597d25183373cde3081316b782ea7eeffbcc -r 5643c1e9b95a74dbef5c56c721b4e55d3dfe4e3a src/libfaad/xine_faad_decoder.c --- a/src/libfaad/xine_faad_decoder.c Fri Nov 07 14:00:17 2008 +0000 +++ b/src/libfaad/xine_faad_decoder.c Fri Nov 07 13:58:41 2008 +0000 @@ -275,7 +275,32 @@ static void faad_decode_audio ( faad_dec lprintf("decoded %d/%d output %ld\n", used, this->size, this->faac_finfo.samples ); - + + /* Performing necessary channel reordering because aac uses a different + * layout than alsa: + * + * aac 5.1 channel layout: c l r ls rs lfe + * alsa 5.1 channel layout: l r ls rs c lfe + * + * Reordering is only necessary for 5.0 and above. Currently only 5.0 + * and 5.1 is being taken care of, the rest will stay in the wrong order + * for now. + * + * WARNING: the following needs a output format of 16 bits per sample. + * TODO: - reorder while copying (in the while() loop) and optimizing + */ + if(this->num_channels == 5 || this->num_channels == 6) + { + int i = 0; + uint16_t* buf = (uint16_t*)(sample_buffer); + + for(; i < this->faac_finfo.samples; i += this->num_channels) { + uint16_t center = buf[i]; + *((uint64_t*)(buf + i)) = *((uint64_t*)(buf + i + 1)); + buf[i + 4] = center; + } + } + while( decoded ) { audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); |