From patchwork Fri Sep 9 19:48:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niki Bowe X-Patchwork-Id: 497 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp486732vsd; Fri, 9 Sep 2016 12:57:29 -0700 (PDT) X-Received: by 10.194.141.203 with SMTP id rq11mr5337618wjb.112.1473451049161; Fri, 09 Sep 2016 12:57:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id xw6si2065102wjb.135.2016.09.09.12.57.24; Fri, 09 Sep 2016 12:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36B0A689BE9; Fri, 9 Sep 2016 22:57:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA9A5680220 for ; Fri, 9 Sep 2016 22:57:04 +0300 (EEST) Received: by mail-pf0-f175.google.com with SMTP id 128so32326460pfb.3 for ; Fri, 09 Sep 2016 12:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=xIuiSafAW7ru96skehbGgHkhBa1poAm9rjjzGzUTg9Y=; b=Y/n56tQOJGkJLxxnvRwFP3UwEzbZ8aU/wvVdFwXxnbncCDOA0WUlXkdmMb/YPwOgwS 3T2dyla/wZOl6pnlqAC/IjeGq0XNfCJubO7Fjpj8OgMlvEeC2xwoqPbIpGndcM34OFsr 6cNr//wl5zhwKyFX/+EXbGw/ttfKtDo2UIgjqHGupCFECqSkhiwG47eQ7gwdL9T6SnVM SCQGv4OunyxpV2L5Cd+tTIpATH2QB71DB5aRHrxTpxu9y5ZjmZCDxVVKbd2b7vlgz2Ru vlO2tjC25aT9bb54YaLA4fzrnQk3c5tBbKHel1zItCUpAJou/jSeYJx3mXsv/gBV+LuL srqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xIuiSafAW7ru96skehbGgHkhBa1poAm9rjjzGzUTg9Y=; b=eeocl1GZ9rEEGwwii7FaqLY6LcgZimdDaLuRHmyLTALcSgzfTYSLfNvPvoxPGi82u9 eon4Uv3KxUtWeKmiEhJMI0AQ+r1WOb0BpPDS3WzvhteYQncotc+vHXsqQgqLUR1N5P4w 2nx3Y737Q4RnaLJZaXGmomXs0BzKmHea7li84uV5QfdflNm9a3BOZMIq5ZqH1H8RAmO9 zZMZl8RjdCzjYrXM755zF8Oep0pdWFLyJDVKS2qZsIEZEzUwi+WjpMwozkh0MT1BAByA Etv+FTBuRoaJxeDGy27G/MVi8xaDPzg/BDkTL44xU+vyXvi5i7UKiCdt5IrU6d28aTrm HUaw== X-Gm-Message-State: AE9vXwOg4dJIonoFRpSCAoYvffXFNX2N0oi0K/Jq2TEV/70/xRsI339Dd3BIBbsonm8i0uV+ X-Received: by 10.98.47.132 with SMTP id v126mr9781177pfv.152.1473450540679; Fri, 09 Sep 2016 12:49:00 -0700 (PDT) Received: from nbowe.mtv.corp.google.com ([100.99.4.71]) by smtp.gmail.com with ESMTPSA id u64sm7170763pfi.0.2016.09.09.12.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 12:48:58 -0700 (PDT) From: Nikolas Bowe To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Sep 2016 12:48:52 -0700 Message-Id: <1473450532-45376-1-git-send-email-nbowe@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [FFmpeg-devel] [PATCH] Fix target_level for EAC3. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nikolas Bowe MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavcodec/ac3.h | 2 +- libavcodec/ac3dec.c | 9 ++++++--- libavcodec/ac3dec.h | 4 ++++ libavcodec/eac3dec.c | 14 +++++++++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h index 747f2f5..5c9c377 100644 --- a/libavcodec/ac3.h +++ b/libavcodec/ac3.h @@ -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 diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index fac189b..a95c204 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -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 } /** diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index c2b867e..6cd67c0 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -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 */ diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c index 47e5aa6..83a54bc 100644 --- a/libavcodec/eac3dec.c +++ b/libavcodec/eac3dec.c @@ -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)); } }