]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/af_amix: rename sum option to normalize
authorPaul B Mahol <onemda@gmail.com>
Fri, 12 Feb 2021 21:58:13 +0000 (22:58 +0100)
committerPaul B Mahol <onemda@gmail.com>
Fri, 12 Feb 2021 22:01:52 +0000 (23:01 +0100)
It makes more sense to still use provided weights.

doc/filters.texi
libavfilter/af_amix.c

index b3b34bb2e87b53728880e663a07a529a9a391c71..282109e8087dc4c39a1ed71d3055923c87f1b55e 100644 (file)
@@ -1936,10 +1936,10 @@ stream ends. The default value is 2 seconds.
 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 of filtering
-or output from @var{amix} normalized after filtering. By default is disabled.
+@item normalize
+Always scale inputs instead of only doing summation of samples.
+Beware of heavy clipping if inputs are not normalized prior or after filtering
+by this filter if this option is disabled. By default is enabled.
 @end table
 
 @subsection Commands
index beaf7bcadac1774b8b39ebbd9193e0a39f0c15d8..45a5dadf0ab4d2e11f694a352461cc105c04395c 100644 (file)
@@ -164,7 +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 normalize;              /**< if inputs are scaled */
 
     int nb_channels;            /**< number of channels */
     int sample_rate;            /**< sample rate */
@@ -196,8 +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 },
+    { "normalize", "Scale inputs",
+            OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, A|F|T },
     { NULL }
 };
 
@@ -231,8 +231,8 @@ static void calculate_scales(MixContext *s, int nb_samples)
 
     for (i = 0; i < s->nb_inputs; i++) {
         if (s->input_state[i] & INPUT_ON) {
-            if (s->sum)
-                s->input_scale[i] = 1.0f;
+            if (!s->normalize)
+                s->input_scale[i] = FFABS(s->weights[i]);
             else
                 s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]);
         } else {