From patchwork Tue Oct 18 15:57:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 1054 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp751546vsd; Tue, 18 Oct 2016 09:12:31 -0700 (PDT) X-Received: by 10.194.238.162 with SMTP id vl2mr755861wjc.39.1476807151268; Tue, 18 Oct 2016 09:12:31 -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 do12si38104824wjb.261.2016.10.18.09.12.28; Tue, 18 Oct 2016 09:12:31 -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 9BCE9689AF5; Tue, 18 Oct 2016 19:12:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2645468980E for ; Tue, 18 Oct 2016 19:12:17 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id r16so15510775pfg.3 for ; Tue, 18 Oct 2016 09:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=9X9aHJKkBqFiaBamCBdxXNC5LU8IM6qbTc4vqqXFkxw=; b=MS2BtSVJBUj1broFnRgIYT5b4wSBSN3iDRVlMl2/E1XQYbuq+ZB0URRP+1iCrznAh+ 3HvewwdJB8daAyLagN+KYOtwqvbI9MvDnBIUqokZire7oBJFKM5gZlCg7/mtxKBMXkqK EskdcF4CcLAt31o+fV/1M4qiNMgiAPEOQKtXgbYCmgFYfwHcG3dPi5+Ln0cAH1L5BHS2 2Ld5dx9PSv5TYi1MfYzSH30TtAE0uZSU59AL+TqVIpXHZ8TosQZ+jpRRrNS3M7F9nlvV wK8mR4su5ae/4svcvzf3oPAQWsQi7nKwyXAlZtaMl9gVx7u9OIYUBF/y0bi6DmXZ08PR 0V+Q== 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=9X9aHJKkBqFiaBamCBdxXNC5LU8IM6qbTc4vqqXFkxw=; b=dJb8/jp2uDna6BrFxa6KjgmVYR9Li23LimvNN7EexCL+jkBccMN3B80pQZu+7TSpIi TzQFg8jduqZtzYUfZ+gZFyr0CJ9dNcvo6yB75fKeXWK6cDuJvUVOpR7U4Zyv+JK2tIUQ VWjsziOe1BRLkd5pTIUGCzNIMQjl+cGgrfSwDt727XtKNNDtFgMTV+n0J6TMKQwar8K5 so/wmT50+qAs9LoEOMjJssViF23cKjQzthtlOmoLhDz+n8Z97kQ0zFTACQ9l7BcgZp5R 9ql/CvgI0OGKtaHYjX/SRcjxrfMKeqGvQyJ1nqgU4FOyo8HIX3xnqAIeSVxahJxeJHEq rCrw== X-Gm-Message-State: AA6/9Rm25M6Jf1zNseJiB7693GczUPsAravcF0s69yCeKtA6BBQ54dNjVlp9zOKlCoVVYg== X-Received: by 10.98.137.206 with SMTP id n75mr1943139pfk.132.1476806351486; Tue, 18 Oct 2016 08:59:11 -0700 (PDT) Received: from localhost.localdomain.localdomain ([114.120.233.247]) by smtp.gmail.com with ESMTPSA id 70sm56966191pfc.50.2016.10.18.08.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 08:59:10 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2016 22:57:01 +0700 Message-Id: <1476806221-31286-1-git-send-email-mfcc64@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH] avfilter/firequalizer: add cubic_interpolate function on gain 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: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" smoother version of gain_interpolate Signed-off-by: Muhammad Faiz --- doc/filters.texi | 2 ++ libavfilter/af_firequalizer.c | 49 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 9fc8c4f..14c9b07 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2508,6 +2508,8 @@ and functions: @table @option @item gain_interpolate(f) interpolate gain on frequency f based on gain_entry +@item cubic_interpolate(f) +same as gain_interpolate, but smoother @end table This option is also available as command. Default is @code{gain_interpolate(f)}. diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c index 6868066..e799e34 100644 --- a/libavfilter/af_firequalizer.c +++ b/libavfilter/af_firequalizer.c @@ -354,6 +354,51 @@ static double gain_interpolate_func(void *p, double freq) return res[0].gain; } +static double cubic_interpolate_func(void *p, double freq) +{ + AVFilterContext *ctx = p; + FIREqualizerContext *s = ctx->priv; + GainEntry *res; + double x, x2, x3; + double a, b, c, d; + double m0, m1, m2, msum, unit; + + if (!s->nb_gain_entry) + return 0; + + if (freq <= s->gain_entry_tbl[0].freq) + return s->gain_entry_tbl[0].gain; + + if (freq >= s->gain_entry_tbl[s->nb_gain_entry-1].freq) + return s->gain_entry_tbl[s->nb_gain_entry-1].gain; + + res = bsearch(&freq, &s->gain_entry_tbl, s->nb_gain_entry - 1, sizeof(*res), gain_entry_compare); + av_assert0(res); + + unit = res[1].freq - res[0].freq; + m0 = res != s->gain_entry_tbl ? + unit * (res[0].gain - res[-1].gain) / (res[0].freq - res[-1].freq) : 0; + m1 = res[1].gain - res[0].gain; + m2 = res != s->gain_entry_tbl + s->nb_gain_entry - 2 ? + unit * (res[2].gain - res[1].gain) / (res[2].freq - res[1].freq) : 0; + + msum = fabs(m0) + fabs(m1); + m0 = msum > 0 ? (fabs(m0) * m1 + fabs(m1) * m0) / msum : 0; + msum = fabs(m1) + fabs(m2); + m1 = msum > 0 ? (fabs(m1) * m2 + fabs(m2) * m1) / msum : 0; + + d = res[0].gain; + c = m0; + b = 3 * res[1].gain - m1 - 2 * c - 3 * d; + a = res[1].gain - b - c - d; + + x = (freq - res[0].freq) / unit; + x2 = x * x; + x3 = x2 * x; + + return a * x3 + b * x2 + c * x + d; +} + static const char *const var_names[] = { "f", "sr", @@ -379,9 +424,9 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g FIREqualizerContext *s = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; const char *gain_entry_func_names[] = { "entry", NULL }; - const char *gain_func_names[] = { "gain_interpolate", NULL }; + const char *gain_func_names[] = { "gain_interpolate", "cubic_interpolate", NULL }; double (*gain_entry_funcs[])(void *, double, double) = { entry_func, NULL }; - double (*gain_funcs[])(void *, double) = { gain_interpolate_func, NULL }; + double (*gain_funcs[])(void *, double) = { gain_interpolate_func, cubic_interpolate_func, NULL }; double vars[VAR_NB]; AVExpr *gain_expr; int ret, k, center, ch;