Commit 96cd6f67 authored by Nikolas Bowe's avatar Nikolas Bowe Committed by Michael Niedermayer

avcodec/(e)ac3: Fix target_level for EAC3.

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: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 6f062eb8
......@@ -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
......
......@@ -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
}
/**
......
......@@ -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 */
......@@ -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));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment