From patchwork Fri Jul 29 17:36:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Burt P X-Patchwork-Id: 30 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp1467529vsd; Fri, 29 Jul 2016 10:53:48 -0700 (PDT) X-Received: by 10.28.14.68 with SMTP id 65mr43954441wmo.68.1469814828053; Fri, 29 Jul 2016 10:53:48 -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 i9si19957782wjg.122.2016.07.29.10.53.47; Fri, 29 Jul 2016 10:53:48 -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=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B3F5689E1F; Fri, 29 Jul 2016 20:53:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A882B689E17 for ; Fri, 29 Jul 2016 20:53:34 +0300 (EEST) Received: by mail-it0-f68.google.com with SMTP id u186so7524203ita.1 for ; Fri, 29 Jul 2016 10:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=HZk/kFO94FwQoLeTHyZb1AT4k++Q1Z4aGQ/zrONY5AI=; b=H/VYp3/mj6/P+mY3HKl9uiR1TVF5M+Rlh2t4GyZjZGFlcXtcZuBQmUu9Rx3JqYNkyc DJTZYPpcbv+X8KkFddHPW2o1l4urZLBRfJRU1qYTOcUFdws/SsQ18B+x4MwOM1GZbhWa z5xsJJyxHFvAUGzD8jdLPQCllvw5qq6ww3izImzqKQu2GTUUKcZcDg+NoyWtO/vbE4E+ M0O7Fr/sAqWbao0iiNMmilZvBO1EHvHjUQBXFl5f+fqQNAuSQEn77yIvfO+QU1N2efPt 7QQjUydNforEcQZI6AApgJvB8vn51QnlfOdUoq1EqIbjwfJJ2B4moswO0uPEG0VYQDGL Um3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=HZk/kFO94FwQoLeTHyZb1AT4k++Q1Z4aGQ/zrONY5AI=; b=ZA9V6ZIqQt2I0VeE9reqgcjjCTLG0VcSOBN20NA7adtxS5J4yayHy6duqKqm/2nCsl euI0ct58XDPuL8hdbXGoMmVKajKCdhCZrG2kK8EBlaoilOP7GRJx94auKMp4g15wgUkE 5XGZ5kkQAoU/BZnhMkHcPTEXJg9N6wGDvhUPONGQ83Pc1IX/Avrl5wjOnk6v101xQpEm dinLG8WpdtseD/Ge7to8vC55qrQwjsRanscvOwZkhkxGr5iNOdGjcsQeHYFtzMFu2C1u MNqamCAqs/ASOm7Bf6eevs1VfCURgwhSWV+OH+A2WCePzxczG6956mWZ6iVmxYjwyce6 lx8w== X-Gm-Message-State: AEkoouu9POb1WQDqLa+WwaP1l5ySdwU5npNVKHI6jPC4+9aQgEcs/FTHlBNrhxyLq8SMAw== X-Received: by 10.36.239.197 with SMTP id i188mr2291790ith.71.1469813798010; Fri, 29 Jul 2016 10:36:38 -0700 (PDT) Received: from localhost.localdomain ([216.16.66.181]) by smtp.gmail.com with ESMTPSA id u7sm1720954ita.21.2016.07.29.10.36.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jul 2016 10:36:37 -0700 (PDT) From: Burt P To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Jul 2016 12:36:19 -0500 Message-Id: <1469813782-13305-5-git-send-email-pburt0@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469813782-13305-1-git-send-email-pburt0@gmail.com> References: <1469472876-7262-1-git-send-email-pburt0@gmail.com> <1469813782-13305-1-git-send-email-pburt0@gmail.com> Subject: [FFmpeg-devel] [PATCH 4/7] af_hdcd: add force_pe filter option 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Used to attempt replication of some results from http://www.audiomisc.co.uk/HFN/HDCD/Examined.html May not be generally useful, defaults to off. Signed-off-by: Burt P --- libavfilter/af_hdcd.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c index 6040400..aeb65eb 100644 --- a/libavfilter/af_hdcd.c +++ b/libavfilter/af_hdcd.c @@ -867,6 +867,12 @@ typedef struct HDCDContext { const AVClass *class; hdcd_state_t state[2]; + /* always extend peaks above -3dBFS even if PE isn't signaled + * -af hdcd=force_pe=0 for off + * -af hdcd=force_pe=1 for on + * default is off */ + int force_pe; + AVFilterContext *fctx; /* filter context for logging errors */ int sample_count; /* used in error logging */ @@ -878,7 +884,10 @@ typedef struct HDCDContext { float max_gain_adjustment; /* in dB, expected in the range -6.0 to 0.0 */ } HDCDContext; +#define OFFSET(x) offsetof(HDCDContext, x) static const AVOption hdcd_options[] = { + { "force_pe", "Always extend peaks above -3dBFS even when PE is not signaled.", + OFFSET(force_pe), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, 0 }, {NULL} }; @@ -1093,14 +1102,21 @@ static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int return gain; } +/* extract fields from control code */ +static void hdcd_control(HDCDContext *ctx, hdcd_state_t *state, int *peak_extend, int *target_gain) +{ + *peak_extend = (ctx->force_pe || state->control & 16); + *target_gain = (state->control & 15) << 7; +} + static void hdcd_process(HDCDContext *ctx, hdcd_state_t *state, int32_t *samples, int count, int stride) { int32_t *samples_end = samples + count * stride; int gain = state->running_gain; - int peak_extend = (state->control & 16); - int target_gain = (state->control & 15) << 7; + int peak_extend, target_gain; int lead = 0; + hdcd_control(ctx, state, &peak_extend, &target_gain); while (count > lead) { int envelope_run; int run; @@ -1115,8 +1131,7 @@ static void hdcd_process(HDCDContext *ctx, hdcd_state_t *state, int32_t *samples samples += envelope_run * stride; count -= envelope_run; lead = run - envelope_run; - peak_extend = (state->control & 16); - target_gain = (state->control & 15) << 7; + hdcd_control(ctx, state, &peak_extend, &target_gain); } if (lead > 0) { av_assert0(samples + lead * stride <= samples_end); @@ -1283,6 +1298,9 @@ static av_cold int init(AVFilterContext *ctx) hdcd_reset(&s->state[c], 44100); } + av_log(ctx, AV_LOG_VERBOSE, "Force PE: %s\n", + (s->force_pe) ? "on" : "off"); + return 0; }