[FFmpeg-devel] [PATCH] ac3dec: avoid duplicating symbols between fixed and float decoder.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Sep 1 00:00:28 CEST 2014


Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/ac3.h         |   4 +-
 libavcodec/ac3dec.c      | 188 +++++++----------------------------------------
 libavcodec/ac3dec_data.c | 138 ++++++++++++++++++++++++++++++++++
 libavcodec/ac3dec_data.h |  15 ++++
 4 files changed, 182 insertions(+), 163 deletions(-)

diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h
index 871640b..0d01014 100644
--- a/libavcodec/ac3.h
+++ b/libavcodec/ac3.h
@@ -86,8 +86,8 @@
 #define AC3_RENAME(x)           x
 #define AC3_NORM(norm)          (1.0f/(norm))
 #define AC3_MUL(a,b)            ((a) * (b))
-#define AC3_RANGE(x)            (dynamic_range_tab[(x)])
-#define AC3_HEAVY_RANGE(x)      (heavy_dynamic_range_tab[(x)])
+#define AC3_RANGE(x)            (ff_ac3_dynamic_range_tab[(x)])
+#define AC3_HEAVY_RANGE(x)      (ff_ac3_heavy_dynamic_range_tab[(x)])
 #define AC3_DYNAMIC_RANGE(x)    (powf(x,  s->drc_scale))
 #define AC3_SPX_BLEND(x)        (x)* (1.0f/32)
 #define AC3_DYNAMIC_RANGE1      1.0f
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 969e37f..4dbb784 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -42,140 +42,6 @@
 #include "kbdwin.h"
 
 /**
- * table for ungrouping 3 values in 7 bits.
- * used for exponents and bap=2 mantissas
- */
-static uint8_t ungroup_3_in_7_bits_tab[128][3];
-
-/** tables for ungrouping mantissas */
-static int b1_mantissas[32][3];
-static int b2_mantissas[128][3];
-static int b3_mantissas[8];
-static int b4_mantissas[128][2];
-static int b5_mantissas[16];
-
-/**
- * Quantization table: levels for symmetric. bits for asymmetric.
- * reference: Table 7.18 Mapping of bap to Quantizer
- */
-static const uint8_t quantization_tab[16] = {
-    0, 3, 5, 7, 11, 15,
-    5, 6, 7, 8, 9, 10, 11, 12, 14, 16
-};
-
-/** dynamic range table. converts codes to scale factors. */
-static float dynamic_range_tab[256];
-static float heavy_dynamic_range_tab[256];
-
-/** Adjustments in dB gain */
-static const float gain_levels[9] = {
-    LEVEL_PLUS_3DB,
-    LEVEL_PLUS_1POINT5DB,
-    LEVEL_ONE,
-    LEVEL_MINUS_1POINT5DB,
-    LEVEL_MINUS_3DB,
-    LEVEL_MINUS_4POINT5DB,
-    LEVEL_MINUS_6DB,
-    LEVEL_ZERO,
-    LEVEL_MINUS_9DB
-};
-
-/** Adjustments in dB gain (LFE, +10 to -21 dB) */
-static const float gain_levels_lfe[32] = {
-    3.162275, 2.818382, 2.511886, 2.238719, 1.995261, 1.778278, 1.584893,
-    1.412536, 1.258924, 1.122018, 1.000000, 0.891251, 0.794328, 0.707946,
-    0.630957, 0.562341, 0.501187, 0.446683, 0.398107, 0.354813, 0.316227,
-    0.281838, 0.251188, 0.223872, 0.199526, 0.177828, 0.158489, 0.141253,
-    0.125892, 0.112201, 0.100000, 0.089125
-};
-
-/**
- * Table for default stereo downmixing coefficients
- * reference: Section 7.8.2 Downmixing Into Two Channels
- */
-static const uint8_t ac3_default_coeffs[8][5][2] = {
-    { { 2, 7 }, { 7, 2 },                               },
-    { { 4, 4 },                                         },
-    { { 2, 7 }, { 7, 2 },                               },
-    { { 2, 7 }, { 5, 5 }, { 7, 2 },                     },
-    { { 2, 7 }, { 7, 2 }, { 6, 6 },                     },
-    { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 },           },
-    { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 },           },
-    { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
-};
-
-/**
- * Symmetrical Dequantization
- * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization
- *            Tables 7.19 to 7.23
- */
-static inline int
-symmetric_dequant(int code, int levels)
-{
-    return ((code - (levels >> 1)) << 24) / levels;
-}
-
-/*
- * Initialize tables at runtime.
- */
-static av_cold void ac3_tables_init(void)
-{
-    int i;
-
-    /* generate table for ungrouping 3 values in 7 bits
-       reference: Section 7.1.3 Exponent Decoding */
-    for (i = 0; i < 128; i++) {
-        ungroup_3_in_7_bits_tab[i][0] =  i / 25;
-        ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5;
-        ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5;
-    }
-
-    /* generate grouped mantissa tables
-       reference: Section 7.3.5 Ungrouping of Mantissas */
-    for (i = 0; i < 32; i++) {
-        /* bap=1 mantissas */
-        b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3);
-        b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3);
-        b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3);
-    }
-    for (i = 0; i < 128; i++) {
-        /* bap=2 mantissas */
-        b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5);
-        b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5);
-        b2_mantissas[i][2] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][2], 5);
-
-        /* bap=4 mantissas */
-        b4_mantissas[i][0] = symmetric_dequant(i / 11, 11);
-        b4_mantissas[i][1] = symmetric_dequant(i % 11, 11);
-    }
-    /* generate ungrouped mantissa tables
-       reference: Tables 7.21 and 7.23 */
-    for (i = 0; i < 7; i++) {
-        /* bap=3 mantissas */
-        b3_mantissas[i] = symmetric_dequant(i, 7);
-    }
-    for (i = 0; i < 15; i++) {
-        /* bap=5 mantissas */
-        b5_mantissas[i] = symmetric_dequant(i, 15);
-    }
-
-    /* generate dynamic range table
-       reference: Section 7.7.1 Dynamic Range Control */
-    for (i = 0; i < 256; i++) {
-        int v = (i >> 5) - ((i >> 7) << 3) - 5;
-        dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
-    }
-
-    /* generate compr dynamic range table
-       reference: Section 7.7.2 Heavy Compression */
-    for (i = 0; i < 256; i++) {
-        int v = (i >> 4) - ((i >> 7) << 4) - 4;
-        heavy_dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0xF) | 0x10);
-    }
-
-}
-
-/**
  * AVCodec initialization
  */
 static av_cold int ac3_decode_init(AVCodecContext *avctx)
@@ -186,7 +52,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
     s->avctx = avctx;
 
     ff_ac3_common_init();
-    ac3_tables_init();
+    ff_ac3_tables_init();
     ff_mdct_init(&s->imdct_256, 8, 1, 1.0);
     ff_mdct_init(&s->imdct_512, 9, 1, 1.0);
     AC3_RENAME(ff_kbd_window_init)(s->window, 5.0, 256);
@@ -371,14 +237,14 @@ static int parse_frame_header(AC3DecodeContext *s)
 static void set_downmix_coeffs(AC3DecodeContext *s)
 {
     int i;
-    float cmix = gain_levels[s->  center_mix_level];
-    float smix = gain_levels[s->surround_mix_level];
+    float cmix = ff_ac3_gain_levels[s->  center_mix_level];
+    float smix = ff_ac3_gain_levels[s->surround_mix_level];
     float norm0, norm1;
     float downmix_coeffs[AC3_MAX_CHANNELS][2];
 
     for (i = 0; i < s->fbw_channels; i++) {
-        downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]];
-        downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]];
+        downmix_coeffs[i][0] = ff_ac3_gain_levels[ff_ac3_default_coeffs[s->channel_mode][i][0]];
+        downmix_coeffs[i][1] = ff_ac3_gain_levels[ff_ac3_default_coeffs[s->channel_mode][i][1]];
     }
     if (s->channel_mode > 1 && s->channel_mode & 1) {
         downmix_coeffs[1][0] = downmix_coeffs[1][1] = cmix;
@@ -431,9 +297,9 @@ static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps,
     group_size = exp_strategy + (exp_strategy == EXP_D45);
     for (grp = 0, i = 0; grp < ngrps; grp++) {
         expacc = get_bits(gbc, 7);
-        dexp[i++] = ungroup_3_in_7_bits_tab[expacc][0];
-        dexp[i++] = ungroup_3_in_7_bits_tab[expacc][1];
-        dexp[i++] = ungroup_3_in_7_bits_tab[expacc][2];
+        dexp[i++] = ff_ac3_ungroup_3_in_7_bits_tab[expacc][0];
+        dexp[i++] = ff_ac3_ungroup_3_in_7_bits_tab[expacc][1];
+        dexp[i++] = ff_ac3_ungroup_3_in_7_bits_tab[expacc][2];
     }
 
     /* convert to absolute exps and expand groups */
@@ -526,9 +392,9 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
                 mantissa = m->b1_mant[m->b1];
             } else {
                 int bits      = get_bits(gbc, 5);
-                mantissa      = b1_mantissas[bits][0];
-                m->b1_mant[1] = b1_mantissas[bits][1];
-                m->b1_mant[0] = b1_mantissas[bits][2];
+                mantissa      = ff_ac3_b1_mantissas[bits][0];
+                m->b1_mant[1] = ff_ac3_b1_mantissas[bits][1];
+                m->b1_mant[0] = ff_ac3_b1_mantissas[bits][2];
                 m->b1         = 2;
             }
             break;
@@ -538,14 +404,14 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
                 mantissa = m->b2_mant[m->b2];
             } else {
                 int bits      = get_bits(gbc, 7);
-                mantissa      = b2_mantissas[bits][0];
-                m->b2_mant[1] = b2_mantissas[bits][1];
-                m->b2_mant[0] = b2_mantissas[bits][2];
+                mantissa      = ff_ac3_b2_mantissas[bits][0];
+                m->b2_mant[1] = ff_ac3_b2_mantissas[bits][1];
+                m->b2_mant[0] = ff_ac3_b2_mantissas[bits][2];
                 m->b2         = 2;
             }
             break;
         case 3:
-            mantissa = b3_mantissas[get_bits(gbc, 3)];
+            mantissa = ff_ac3_b3_mantissas[get_bits(gbc, 3)];
             break;
         case 4:
             if (m->b4) {
@@ -553,13 +419,13 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
                 mantissa = m->b4_mant;
             } else {
                 int bits   = get_bits(gbc, 7);
-                mantissa   = b4_mantissas[bits][0];
-                m->b4_mant = b4_mantissas[bits][1];
+                mantissa   = ff_ac3_b4_mantissas[bits][0];
+                m->b4_mant = ff_ac3_b4_mantissas[bits][1];
                 m->b4      = 1;
             }
             break;
         case 5:
-            mantissa = b5_mantissas[get_bits(gbc, 4)];
+            mantissa = ff_ac3_b5_mantissas[get_bits(gbc, 4)];
             break;
         default: /* 6 to 15 */
             /* Shift mantissa and sign-extend it. */
@@ -567,8 +433,8 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
                 av_log(s->avctx, AV_LOG_ERROR, "bap %d is invalid in plain AC-3\n", bap);
                 bap = 15;
             }
-            mantissa = get_sbits(gbc, quantization_tab[bap]);
-            mantissa <<= 24 - quantization_tab[bap];
+            mantissa = get_sbits(gbc, ff_ac3_quantization_tab[bap]);
+            mantissa <<= 24 - ff_ac3_quantization_tab[bap];
             break;
         }
         coeffs[freq] = mantissa >> exps[freq];
@@ -1506,8 +1372,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
             s->output_mode  = AC3_CHMODE_STEREO;
         }
 
-        s->loro_center_mix_level   = gain_levels[s->  center_mix_level];
-        s->loro_surround_mix_level = gain_levels[s->surround_mix_level];
+        s->loro_center_mix_level   = ff_ac3_gain_levels[s->  center_mix_level];
+        s->loro_surround_mix_level = ff_ac3_gain_levels[s->surround_mix_level];
         s->ltrt_center_mix_level   = LEVEL_MINUS_3DB;
         s->ltrt_surround_mix_level = LEVEL_MINUS_3DB;
         /* set downmixing coefficients if needed */
@@ -1611,12 +1477,12 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
             downmix_info->preferred_downmix_type = AV_DOWNMIX_TYPE_UNKNOWN;
             break;
         }
-        downmix_info->center_mix_level        = gain_levels[s->       center_mix_level];
-        downmix_info->center_mix_level_ltrt   = gain_levels[s->  center_mix_level_ltrt];
-        downmix_info->surround_mix_level      = gain_levels[s->     surround_mix_level];
-        downmix_info->surround_mix_level_ltrt = gain_levels[s->surround_mix_level_ltrt];
+        downmix_info->center_mix_level        = ff_ac3_gain_levels[s->       center_mix_level];
+        downmix_info->center_mix_level_ltrt   = ff_ac3_gain_levels[s->  center_mix_level_ltrt];
+        downmix_info->surround_mix_level      = ff_ac3_gain_levels[s->     surround_mix_level];
+        downmix_info->surround_mix_level_ltrt = ff_ac3_gain_levels[s->surround_mix_level_ltrt];
         if (s->lfe_mix_level_exists)
-            downmix_info->lfe_mix_level       = gain_levels_lfe[s->lfe_mix_level];
+            downmix_info->lfe_mix_level       = ff_ac3_gain_levels_lfe[s->lfe_mix_level];
         else
             downmix_info->lfe_mix_level       = 0.0; // -inf dB
     } else
diff --git a/libavcodec/ac3dec_data.c b/libavcodec/ac3dec_data.c
index d0a9b1e..1c9fbdd 100644
--- a/libavcodec/ac3dec_data.c
+++ b/libavcodec/ac3dec_data.c
@@ -24,6 +24,7 @@
  * Tables taken directly from the AC-3 spec.
  */
 
+#include "config.h"
 #include "ac3dec_data.h"
 #include "ac3.h"
 
@@ -58,3 +59,140 @@ const uint8_t ff_eac3_hebap_tab[64] = {
  */
 const uint8_t ff_eac3_default_spx_band_struct[17] =
 { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
+
+/**
+ * table for ungrouping 3 values in 7 bits.
+ * used for exponents and bap=2 mantissas
+ */
+uint8_t ff_ac3_ungroup_3_in_7_bits_tab[128][3];
+
+/** tables for ungrouping mantissas */
+int ff_ac3_b1_mantissas[32][3];
+int ff_ac3_b2_mantissas[128][3];
+int ff_ac3_b3_mantissas[8];
+int ff_ac3_b4_mantissas[128][2];
+int ff_ac3_b5_mantissas[16];
+
+/**
+ * Quantization table: levels for symmetric. bits for asymmetric.
+ * reference: Table 7.18 Mapping of bap to Quantizer
+ */
+const uint8_t ff_ac3_quantization_tab[16] = {
+    0, 3, 5, 7, 11, 15,
+    5, 6, 7, 8, 9, 10, 11, 12, 14, 16
+};
+
+#if CONFIG_AC3_DECODER
+/** dynamic range table. converts codes to scale factors. */
+float ff_ac3_dynamic_range_tab[256];
+float ff_ac3_heavy_dynamic_range_tab[256];
+#endif
+
+/** Adjustments in dB gain */
+const float ff_ac3_gain_levels[9] = {
+    LEVEL_PLUS_3DB,
+    LEVEL_PLUS_1POINT5DB,
+    LEVEL_ONE,
+    LEVEL_MINUS_1POINT5DB,
+    LEVEL_MINUS_3DB,
+    LEVEL_MINUS_4POINT5DB,
+    LEVEL_MINUS_6DB,
+    LEVEL_ZERO,
+    LEVEL_MINUS_9DB
+};
+
+/** Adjustments in dB gain (LFE, +10 to -21 dB) */
+const float ff_ac3_gain_levels_lfe[32] = {
+    3.162275, 2.818382, 2.511886, 2.238719, 1.995261, 1.778278, 1.584893,
+    1.412536, 1.258924, 1.122018, 1.000000, 0.891251, 0.794328, 0.707946,
+    0.630957, 0.562341, 0.501187, 0.446683, 0.398107, 0.354813, 0.316227,
+    0.281838, 0.251188, 0.223872, 0.199526, 0.177828, 0.158489, 0.141253,
+    0.125892, 0.112201, 0.100000, 0.089125
+};
+
+/**
+ * Table for default stereo downmixing coefficients
+ * reference: Section 7.8.2 Downmixing Into Two Channels
+ */
+const uint8_t ff_ac3_default_coeffs[8][5][2] = {
+    { { 2, 7 }, { 7, 2 },                               },
+    { { 4, 4 },                                         },
+    { { 2, 7 }, { 7, 2 },                               },
+    { { 2, 7 }, { 5, 5 }, { 7, 2 },                     },
+    { { 2, 7 }, { 7, 2 }, { 6, 6 },                     },
+    { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 },           },
+    { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 },           },
+    { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
+};
+
+/**
+ * Symmetrical Dequantization
+ * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization
+ *            Tables 7.19 to 7.23
+ */
+static inline int
+symmetric_dequant(int code, int levels)
+{
+    return ((code - (levels >> 1)) << 24) / levels;
+}
+
+/*
+ * Initialize tables at runtime.
+ */
+av_cold void ff_ac3_tables_init(void)
+{
+    int i;
+
+    /* generate table for ungrouping 3 values in 7 bits
+       reference: Section 7.1.3 Exponent Decoding */
+    for (i = 0; i < 128; i++) {
+        ff_ac3_ungroup_3_in_7_bits_tab[i][0] =  i / 25;
+        ff_ac3_ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5;
+        ff_ac3_ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5;
+    }
+
+    /* generate grouped mantissa tables
+       reference: Section 7.3.5 Ungrouping of Mantissas */
+    for (i = 0; i < 32; i++) {
+        /* bap=1 mantissas */
+        ff_ac3_b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3);
+        ff_ac3_b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3);
+        ff_ac3_b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3);
+    }
+    for (i = 0; i < 128; i++) {
+        /* bap=2 mantissas */
+        ff_ac3_b2_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_7_bits_tab[i][0], 5);
+        ff_ac3_b2_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_7_bits_tab[i][1], 5);
+        ff_ac3_b2_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_7_bits_tab[i][2], 5);
+
+        /* bap=4 mantissas */
+        ff_ac3_b4_mantissas[i][0] = symmetric_dequant(i / 11, 11);
+        ff_ac3_b4_mantissas[i][1] = symmetric_dequant(i % 11, 11);
+    }
+    /* generate ungrouped mantissa tables
+       reference: Tables 7.21 and 7.23 */
+    for (i = 0; i < 7; i++) {
+        /* bap=3 mantissas */
+        ff_ac3_b3_mantissas[i] = symmetric_dequant(i, 7);
+    }
+    for (i = 0; i < 15; i++) {
+        /* bap=5 mantissas */
+        ff_ac3_b5_mantissas[i] = symmetric_dequant(i, 15);
+    }
+
+#if CONFIG_AC3_DECODER
+    /* generate dynamic range table
+       reference: Section 7.7.1 Dynamic Range Control */
+    for (i = 0; i < 256; i++) {
+        int v = (i >> 5) - ((i >> 7) << 3) - 5;
+        ff_ac3_dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20);
+    }
+
+    /* generate compr dynamic range table
+       reference: Section 7.7.2 Heavy Compression */
+    for (i = 0; i < 256; i++) {
+        int v = (i >> 4) - ((i >> 7) << 4) - 4;
+        ff_ac3_heavy_dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0xF) | 0x10);
+    }
+#endif
+}
diff --git a/libavcodec/ac3dec_data.h b/libavcodec/ac3dec_data.h
index 975b52e..934ccf3 100644
--- a/libavcodec/ac3dec_data.h
+++ b/libavcodec/ac3dec_data.h
@@ -29,4 +29,19 @@ extern const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3];
 extern const uint8_t ff_eac3_hebap_tab[64];
 extern const uint8_t ff_eac3_default_spx_band_struct[17];
 
+extern uint8_t ff_ac3_ungroup_3_in_7_bits_tab[128][3];
+extern int ff_ac3_b1_mantissas[32][3];
+extern int ff_ac3_b2_mantissas[128][3];
+extern int ff_ac3_b3_mantissas[8];
+extern int ff_ac3_b4_mantissas[128][2];
+extern int ff_ac3_b5_mantissas[16];
+extern const uint8_t ff_ac3_quantization_tab[16];
+extern float ff_ac3_dynamic_range_tab[256];
+extern float ff_ac3_heavy_dynamic_range_tab[256];
+extern const float ff_ac3_gain_levels[9];
+extern const float ff_ac3_gain_levels_lfe[32];
+extern const uint8_t ff_ac3_default_coeffs[8][5][2];
+
+void ff_ac3_tables_init(void);
+
 #endif /* AVCODEC_AC3DEC_DATA_H */
-- 
2.1.0



More information about the ffmpeg-devel mailing list