From patchwork Wed Feb 3 19:40:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 25374 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E438844A7DA for ; Wed, 3 Feb 2021 21:40:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD4DF689721; Wed, 3 Feb 2021 21:40:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3B5C680911 for ; Wed, 3 Feb 2021 21:40:33 +0200 (EET) Received: by mail-ej1-f41.google.com with SMTP id sa23so1048754ejb.0 for ; Wed, 03 Feb 2021 11:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=BQA5ouIOBeMr16zrcMCirgkxLDHEypH36Y33H8h4ZzM=; b=jztGnI5QaPqIWDqZUcufJA4Vb/442T9rIrLFO5nnOsuYlA6Nl8fWOTG5obY608pX9a TYweDWxSvw5o4ofLeeN8IZ+By6Xl6XZKveHbiIvejkSItKmSjsvWQ+8IVsrRE9NoPbSP O1MJJj09Pr1fxXE7Poyy90HhfJo9RQzfE/ixa/e68ZPvHapVeE9z4y3nrIOF6F1PjW2j nvGN8+mS1vGzPkbHWoN9IS/DEouIJVll/O6BndEy2LobE/LCtMVFvU5PTbGuFUI/nAlh 3U6S73ThZT+BkFKqAiQXRQDAjUhdiDttL9YSd74r6PRGvS6CngLRUblkm/gFG7PSY9OV FXCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=BQA5ouIOBeMr16zrcMCirgkxLDHEypH36Y33H8h4ZzM=; b=rGftF/bgLvRk1vPoSzF+R9xj5SrGMqLfm1f/oM1HhHQPvfoVwCmE0xCUqz7f+28rsV xq3LHt21M0SOsbChvZhHPkisH7WdvuvUHEvOzUHZ6Zyu8LRxTkTstY/0rmhJgDXxU8fw V8nD7CvVRFQVf/fHmkmi5K9P2Ocwtb63XhKCY/fi+/LDPWz4vfLsg/+8mK06oVSmOjPu 2xpyDoCkS1P68iBnDhg7w0nnUK1yGg3J7g5Duqgk9hOA4Vmg0ITaJc5ltnlpFB24xBjF UrJK9/rRm1Z6acap/21bPGlmMxQDrVvLtaK7L6/AWG82h3aQWad/mxuVWn1MYkrZIIlY BqdA== X-Gm-Message-State: AOAM531ypCo6BUP+GPq2Nx7OKF4jwfDk+5fyhJPr9xETLBjvRx5pEc/t Y7ZHWZwpYLSyiZmaKNyjZlLHLPe+DfSC+A== X-Google-Smtp-Source: ABdhPJxplbT1UGwj23Ed/+hubdbC1m8WWM8/HCKKwe/Ohr4Zb9/KqTMccPZT7lGBnDe4N639+JoYZg== X-Received: by 2002:a17:906:c0d7:: with SMTP id bn23mr4782557ejb.94.1612381233409; Wed, 03 Feb 2021 11:40:33 -0800 (PST) Received: from localhost.localdomain ([31.45.254.141]) by smtp.gmail.com with ESMTPSA id n16sm1390706ejy.23.2021.02.03.11.40.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 11:40:32 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Feb 2021 20:40:25 +0100 Message-Id: <20210203194025.3558-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter/af_amix: add sum 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" Signed-off-by: Paul B Mahol --- doc/filters.texi | 6 ++++++ libavfilter/af_amix.c | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 2d85a414ec..b4c4e330f4 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1879,6 +1879,11 @@ stream ends. The default value is 2 seconds. @item weights Specify weight of each input audio stream as sequence. Each weight is separated by space. By default all inputs have same weight. + +@item sum +Do not scale inputs but instead do only summation of samples. +Beware of heavy clipping if inputs are not normalized prior to filtering. +By default is disabled. @end table @subsection Commands @@ -1886,6 +1891,7 @@ Each weight is separated by space. By default all inputs have same weight. This filter supports the following commands: @table @option @item weights +@item sum Syntax is same as option with same name. @end table diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index c4d8916a57..beaf7bcada 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -164,6 +164,7 @@ typedef struct MixContext { int duration_mode; /**< mode for determining duration */ float dropout_transition; /**< transition time when an input drops out */ char *weights_str; /**< string for custom weights for every input */ + int sum; /**< inputs are not scaled, only added */ int nb_channels; /**< number of channels */ int sample_rate; /**< sample rate */ @@ -195,6 +196,8 @@ static const AVOption amix_options[] = { OFFSET(dropout_transition), AV_OPT_TYPE_FLOAT, { .dbl = 2.0 }, 0, INT_MAX, A|F }, { "weights", "Set weight for each input.", OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F|T }, + { "sum", "Do not scale inputs instead do only sum", + OFFSET(sum), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A|F|T }, { NULL } }; @@ -227,10 +230,14 @@ static void calculate_scales(MixContext *s, int nb_samples) } for (i = 0; i < s->nb_inputs; i++) { - if (s->input_state[i] & INPUT_ON) - s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]); - else + if (s->input_state[i] & INPUT_ON) { + if (s->sum) + s->input_scale[i] = 1.0f; + else + s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]); + } else { s->input_scale[i] = 0.0f; + } } }