]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/(e)ac3: Fix target_level for EAC3.
authorNikolas Bowe <nbowe-at-google.com@ffmpeg.org>
Fri, 9 Sep 2016 19:48:52 +0000 (12:48 -0700)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 15 Sep 2016 10:18:55 +0000 (12:18 +0200)
Currently when using target_level with EAC3 it produces silence. This small patch fixes target_level for decoding EAC3.

Example:
ffmpeg -y -i /tmp/test.wav -acodec eac3 -dialnorm -14 -ac 6 -b:a 384000 /tmp/test.m2ts
ffmpeg -y -target_level -24 -i /tmp/test.m2ts -acodec pcm_s16le -f matroska /tmp/out.mkv
ffplay /tmp/out.mkv

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/ac3.h
libavcodec/ac3dec.c
libavcodec/ac3dec.h
libavcodec/eac3dec.c

index 747f2f561dc73a11ad5413f42d9c63dc0b2a805b..5c9c37727e7df960def1b128a1099288c469975e 100644 (file)
@@ -87,7 +87,7 @@ typedef int16_t                 SHORTFLOAT;
 #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_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
index fac189b6b64f8e7cd81007166ca48d174874542b..a95c2049b52cde1f130aa21646598d0b1710c467 100644 (file)
@@ -63,9 +63,11 @@ static const uint8_t quantization_tab[16] = {
     5, 6, 7, 8, 9, 10, 11, 12, 14, 16
 };
 
+#if (!USE_FIXED)
 /** dynamic range table. converts codes to scale factors. */
 static float dynamic_range_tab[256];
-static float heavy_dynamic_range_tab[256];
+float ff_ac3_heavy_dynamic_range_tab[256];
+#endif
 
 /** Adjustments in dB gain */
 static const float gain_levels[9] = {
@@ -159,6 +161,7 @@ static av_cold void ac3_tables_init(void)
         b5_mantissas[i] = symmetric_dequant(i, 15);
     }
 
+#if (!USE_FIXED)
     /* generate dynamic range table
        reference: Section 7.7.1 Dynamic Range Control */
     for (i = 0; i < 256; i++) {
@@ -170,9 +173,9 @@ static av_cold void ac3_tables_init(void)
        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);
+        ff_ac3_heavy_dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0xF) | 0x10);
     }
-
+#endif
 }
 
 /**
index c2b867e32c95916ab2b82d4e5086718bda7765bd..6cd67c0f21059891128d670d556a9572eeff87b5 100644 (file)
@@ -260,4 +260,8 @@ static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
  */
 static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s);
 
+#if (!USE_FIXED)
+extern float ff_ac3_heavy_dynamic_range_tab[256];
+#endif
+
 #endif /* AVCODEC_AC3DEC_H */
index 47e5aa65879a43c570e67c8b69afebd17f1a021f..83a54bcfab99025e642b52d14faadfba0ef3306a 100644 (file)
@@ -339,9 +339,17 @@ static int ff_eac3_parse_header(AC3DecodeContext *s)
 
     /* volume control params */
     for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
-        skip_bits(gbc, 5); // skip dialog normalization
-        if (get_bits1(gbc)) {
-            skip_bits(gbc, 8); // skip compression gain word
+        s->dialog_normalization[i] = -get_bits(gbc, 5);
+        if (s->dialog_normalization[i] == 0) {
+            s->dialog_normalization[i] = -31;
+        }
+        if (s->target_level != 0) {
+            s->level_gain[i] = powf(2.0f,
+                (float)(s->target_level - s->dialog_normalization[i])/6.0f);
+        }
+        s->compression_exists[i] = get_bits1(gbc);
+        if (s->compression_exists[i]) {
+            s->heavy_dynamic_range[i] = AC3_HEAVY_RANGE(get_bits(gbc, 8));
         }
     }