From patchwork Sat Oct 15 23:10:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 1016 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp364550vsd; Sat, 15 Oct 2016 16:12:51 -0700 (PDT) X-Received: by 10.28.125.150 with SMTP id y144mr3500174wmc.77.1476573171400; Sat, 15 Oct 2016 16:12:51 -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 i187si4836373wma.127.2016.10.15.16.12.51; Sat, 15 Oct 2016 16:12:51 -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 9FB4F680CFF; Sun, 16 Oct 2016 02:12:47 +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 53BD4687ECE for ; Sun, 16 Oct 2016 02:12:40 +0300 (EEST) Received: by mail-pf0-f196.google.com with SMTP id r16so9895094pfg.3 for ; Sat, 15 Oct 2016 16:12:41 -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=sZ9bCtjFW9q6HBXjbAQiSL+vcyAvympmC/R8vUcvnWo=; b=PCuojTBZWboCpoXdu7tPMWzHyOajEEJTQY55B4zKK/hulbvguZOXguq59ClDbW3FMI HGHdSlZg6iqh/3wa9vPjbx1mBE/yz5XbtVYRjobBQaDKadcmtsAgGGtis1e07HV53J8b 9HpZOwjlFIGWTsflx10gKAklLTUBHiBLj9WvAcg5sJAWwopqIdf25J+phIHZ74JBbGmB 5vzWAHh3eH+PCemd53p/r9H+BBctqDYJ64fWaMWPMQPHywkabPyT6wqZjT1Bge8hTtQT TZfbyMJfkrZb9dLF2z1MVUSZ/zlQewmsqUM+bI9rip+unkuUmrpn79QCRVZ/GG2kTPnP fIHQ== 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=sZ9bCtjFW9q6HBXjbAQiSL+vcyAvympmC/R8vUcvnWo=; b=fgqUETeIPo8PhvTxYTuSHIDnASG6Cgt2JnyfqjsAG5WBfH+VggAv4jplyfgOkVfyue Wr0uA9NyrZSg7+w/OtpX7nl4mwvftu6FcIe2jbg6LSrMeajpGGeDgFEEA9zOh//MDvCC 41w/puosAfR4pBRx4EBaQlAQoZ/dbi8XUJTdmttBlQmzHBubgE2UzNrVPF8lmbcKMWLl 9l6yVe268Pp//KCvkXInikFcWRQWnKziEOShut12WElzC78IUamjciJ8SK8HjpjAYvT6 t4gm6Ye1XiU3YF4agPWKeob1QXoieDRIMrPe3Wg7DgC/v1i8LQLe+6RXO82cN9e6M/uA g37g== X-Gm-Message-State: AA6/9RkxMaDa39yAf5IbA3h+HROCYzFh0T7eMhOiQkItWUzh7LdYSpLn+iOYubOYmuofbg== X-Received: by 10.98.204.67 with SMTP id a64mr27882873pfg.120.1476573160373; Sat, 15 Oct 2016 16:12:40 -0700 (PDT) Received: from localhost.localdomain.localdomain ([45.121.217.36]) by smtp.gmail.com with ESMTPSA id qd12sm37398923pab.22.2016.10.15.16.12.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Oct 2016 16:12:39 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Sun, 16 Oct 2016 06:10:41 +0700 Message-Id: <1476573041-10119-1-git-send-email-mfcc64@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH] avfilter/firequalizer: add scale 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 Cc: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Muhammad Faiz --- doc/filters.texi | 13 +++++++++++++ libavfilter/af_firequalizer.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index f5cc9b7..d4eec70 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2565,6 +2565,19 @@ Enable zero phase mode by subtracting timestamp to compensate delay. Default is disabled. @end table +@item scale +Set scale used by gain. Acceptable values are: +@table @option +@item linlin +linear frequency, linear gain +@item linlog +linear frequency, logarithmic (in dB) gain (default) +@item loglin +logarithmic (in octave scale where 20 Hz is 0) frequency, linear gain +@item loglog +logarithmic frequency, logarithmic gain +@end table + @subsection Examples @itemize @item diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c index c7569bb..78d7767 100644 --- a/libavfilter/af_firequalizer.c +++ b/libavfilter/af_firequalizer.c @@ -43,6 +43,14 @@ enum WindowFunc { NB_WFUNC }; +enum Scale { + SCALE_LINLIN, + SCALE_LINLOG, + SCALE_LOGLIN, + SCALE_LOGLOG, + NB_SCALE +}; + #define NB_GAIN_ENTRY_MAX 4096 typedef struct { double freq; @@ -84,6 +92,7 @@ typedef struct { int fixed; int multi; int zero_phase; + int scale; int nb_gain_entry; int gain_entry_err; @@ -112,6 +121,11 @@ static const AVOption firequalizer_options[] = { { "fixed", "set fixed frame samples", OFFSET(fixed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { "multi", "set multi channels mode", OFFSET(multi), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { "zero_phase", "set zero phase mode", OFFSET(zero_phase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, + { "scale", "set gain scale", OFFSET(scale), AV_OPT_TYPE_INT, { .i64 = SCALE_LINLOG }, 0, NB_SCALE-1, FLAGS, "scale" }, + { "linlin", "linear-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLIN }, 0, 0, FLAGS, "scale" }, + { "linlog", "linear-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLOG }, 0, 0, FLAGS, "scale" }, + { "loglin", "logarithmic-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLIN }, 0, 0, FLAGS, "scale" }, + { "loglog", "logarithmic-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLOG }, 0, 0, FLAGS, "scale" }, { NULL } }; @@ -316,6 +330,8 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g double vars[VAR_NB]; AVExpr *gain_expr; int ret, k, center, ch; + int xlog = s->scale == SCALE_LOGLIN || s->scale == SCALE_LOGLOG; + int ylog = s->scale == SCALE_LINLOG || s->scale == SCALE_LOGLOG; s->nb_gain_entry = 0; s->gain_entry_err = 0; @@ -340,16 +356,27 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g vars[VAR_CHLAYOUT] = inlink->channel_layout; vars[VAR_SR] = inlink->sample_rate; for (ch = 0; ch < inlink->channels; ch++) { + double result; vars[VAR_CH] = ch; vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch); vars[VAR_F] = 0.0; - s->analysis_buf[0] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx)); + if (xlog) + vars[VAR_F] = log2(0.05 * vars[VAR_F]); + result = av_expr_eval(gain_expr, vars, ctx); + s->analysis_buf[0] = ylog ? pow(10.0, 0.05 * result) : result; + vars[VAR_F] = 0.5 * inlink->sample_rate; - s->analysis_buf[1] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx)); + if (xlog) + vars[VAR_F] = log2(0.05 * vars[VAR_F]); + result = av_expr_eval(gain_expr, vars, ctx); + s->analysis_buf[1] = ylog ? pow(10.0, 0.05 * result) : result; for (k = 1; k < s->analysis_rdft_len/2; k++) { vars[VAR_F] = k * ((double)inlink->sample_rate /(double)s->analysis_rdft_len); - s->analysis_buf[2*k] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx)); + if (xlog) + vars[VAR_F] = log2(0.05 * vars[VAR_F]); + result = av_expr_eval(gain_expr, vars, ctx); + s->analysis_buf[2*k] = ylog ? pow(10.0, 0.05 * result) : result; s->analysis_buf[2*k+1] = 0.0; }