lists.zerezo.com



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MPlayer-dev-eng] [patch] Correct channel assignment for FLAC > 2 channels



Hi, I was playing about with converting some multi channel audio files to FLAC, and playing them with mplayer. I found the channels were played back through the wrong speakers.

If you look at libmpcodecs/ad_ffmpeg.c, you'll see there is no specific support for FLAC, so (for 6 channels), it'll default to AF_CHANNEL_LAYOUT_5_1_B (L R Ls Rs C LFE)

However, looking at the FLAC specification at http://flac.sourceforge.net/format.html#frame_header (channel assignment section) shows that FLAC actually uses an arrangement of (L R C LFE Ls Rs).

The attached patch fixes this, and now my FLACs play correctly.

Index: libmpcodecs/ad_ffmpeg.c
===================================================================
--- libmpcodecs/ad_ffmpeg.c	(revision 27727)
+++ libmpcodecs/ad_ffmpeg.c	(working copy)
@@ -177,6 +177,8 @@
               src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_LIBA52_DEFAULT;
             else if (!strcasecmp(codec, "vorbis"))
               src_ch_layout = AF_CHANNEL_LAYOUT_VORBIS_DEFAULT;
+            else if (!strcasecmp(codec, "flac"))
+              src_ch_layout = AF_CHANNEL_LAYOUT_FLAC_DEFAULT;
             else
               src_ch_layout = AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT;
             reorder_channel_nch(buf, src_ch_layout,
Index: libaf/reorder_ch.c
===================================================================
--- libaf/reorder_ch.c	(revision 27727)
+++ libaf/reorder_ch.c	(working copy)
@@ -1109,6 +1109,7 @@
     AF_CHANNEL_LAYOUT_LAVC_LIBA52_5CH_DEFAULT,
     AF_CHANNEL_LAYOUT_LAVC_DCA_5CH_DEFAULT,
     AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT,
+    AF_CHANNEL_LAYOUT_FLAC_5CH_DEFAULT,
 };
 
 static int channel_layout_mapping_6ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = {
@@ -1119,6 +1120,7 @@
     AF_CHANNEL_LAYOUT_LAVC_LIBA52_6CH_DEFAULT,
     AF_CHANNEL_LAYOUT_LAVC_DCA_6CH_DEFAULT,
     AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT,
+    AF_CHANNEL_LAYOUT_FLAC_6CH_DEFAULT,
 };
 
 void reorder_channel_copy_nch(void *src,
Index: libaf/reorder_ch.h
===================================================================
--- libaf/reorder_ch.h	(revision 27727)
+++ libaf/reorder_ch.h	(working copy)
@@ -73,6 +73,8 @@
 #define AF_CHANNEL_LAYOUT_LAVC_DCA_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_D
 #define AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_C
 #define AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_C
+#define AF_CHANNEL_LAYOUT_FLAC_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_A
+#define AF_CHANNEL_LAYOUT_FLAC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_A
 
 #define AF_CHANNEL_MASK  0xFF
 #define AF_GET_CH_NUM(A) ((A)&0x7F)
@@ -105,7 +107,8 @@
 #define AF_CHANNEL_LAYOUT_LAVC_LIBA52_DEFAULT 4
 #define AF_CHANNEL_LAYOUT_LAVC_DCA_DEFAULT    5
 #define AF_CHANNEL_LAYOUT_VORBIS_DEFAULT      6
-#define AF_CHANNEL_LAYOUT_SOURCE_NUM          7
+#define AF_CHANNEL_LAYOUT_FLAC_DEFAULT        7
+#define AF_CHANNEL_LAYOUT_SOURCE_NUM          8
 #define AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT AF_CHANNEL_LAYOUT_ALSA_DEFAULT
 
 /// Optimized channel reorder between different audio sources and targets.
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng