]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ac3tab.c
add support for files that do not allow more than 4 subframes
[ffmpeg] / libavcodec / ac3tab.c
index 36a7449a72fd4e4f82d9cd9bb13eb479d9c8abb3..79f628fbd9f6df4dbadc1aa884cbd3c9271fddb2 100644 (file)
  */
 
 /**
- * @file libavcodec/ac3tab.c
+ * @file
  * tables taken directly from the AC-3 spec.
  */
 
+#include "libavcore/audioconvert.h"
+#include "avcodec.h"
 #include "ac3tab.h"
 
 /**
@@ -72,28 +74,55 @@ const uint16_t ff_ac3_frame_size_tab[38][3] = {
 };
 
 /**
- * Maps audio coding mode (acmod) to number of full-bandwidth channels.
+ * Map audio coding mode (acmod) to number of full-bandwidth channels.
  * from ATSC A/52 Table 5.8 Audio Coding Mode
  */
 const uint8_t ff_ac3_channels_tab[8] = {
     2, 1, 2, 3, 3, 4, 4, 5
 };
 
+/**
+ * Map audio coding mode (acmod) to channel layout mask.
+ */
+const uint16_t ff_ac3_channel_layout_tab[8] = {
+    AV_CH_LAYOUT_STEREO,
+    AV_CH_LAYOUT_MONO,
+    AV_CH_LAYOUT_STEREO,
+    AV_CH_LAYOUT_SURROUND,
+    AV_CH_LAYOUT_2_1,
+    AV_CH_LAYOUT_4POINT0,
+    AV_CH_LAYOUT_2_2,
+    AV_CH_LAYOUT_5POINT0
+};
+
+#define COMMON_CHANNEL_MAP \
+    { { 0, 1,          }, { 0, 1, 2,         } },\
+    { { 0,             }, { 0, 1,            } },\
+    { { 0, 1,          }, { 0, 1, 2,         } },\
+    { { 0, 2, 1,       }, { 0, 2, 1, 3,      } },\
+    { { 0, 1, 2,       }, { 0, 1, 3, 2,      } },\
+    { { 0, 2, 1, 3,    }, { 0, 2, 1, 4, 3,   } },
+
 /**
  * Table to remap channels from SMPTE order to AC-3 order.
  * [channel_mode][lfe][ch]
  */
 const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
-    { { 0, 1,          }, { 0, 1, 2,         } },
-    { { 0,             }, { 0, 1,            } },
-    { { 0, 1,          }, { 0, 1, 2,         } },
-    { { 0, 2, 1,       }, { 0, 2, 1, 3,      } },
-    { { 0, 1, 2,       }, { 0, 1, 3, 2,      } },
-    { { 0, 2, 1, 3,    }, { 0, 2, 1, 4, 3,   } },
-    { { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2,   } },
+    COMMON_CHANNEL_MAP
+    { { 0, 1, 2, 3,    }, { 0, 1, 3, 4, 2,   } },
     { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
 };
 
+/**
+ * Table to remap channels from from AC-3 order to SMPTE order.
+ * [channel_mode][lfe][ch]
+ */
+const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
+    COMMON_CHANNEL_MAP
+    { { 0, 1, 2, 3,    }, { 0, 1, 4, 2, 3,   } },
+    { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
+};
+
 /* possible frequencies */
 const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
 
@@ -106,7 +135,7 @@ const uint16_t ff_ac3_bitrate_tab[19] = {
 /* AC-3 MDCT window */
 
 /* MDCT window */
-const int16_t ff_ac3_window[256] = {
+const int16_t ff_ac3_window[AC3_WINDOW_SIZE/2] = {
     4,    7,   12,   16,   21,   28,   34,   42,
    51,   61,   72,   84,   97,  111,  127,  145,
   164,  184,  207,  231,  257,  285,  315,  347,
@@ -170,7 +199,7 @@ const uint8_t ff_ac3_log_add_tab[260]= {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 };
 
-const uint16_t ff_ac3_hearing_threshold_tab[50][3]= {
+const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]= {
 { 0x04d0,0x04f0,0x0580 },
 { 0x04d0,0x04f0,0x0580 },
 { 0x0440,0x0460,0x04b0 },
@@ -257,7 +286,7 @@ const uint16_t ff_ac3_fast_gain_tab[8]= {
     0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
 };
 
-const uint8_t ff_ac3_critical_band_size_tab[50]={
+const uint8_t ff_ac3_critical_band_size_tab[AC3_CRITICAL_BANDS]={
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
     3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24