]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_amix.c
avfilter/af_amix: change the max range of the number of inputs
[ffmpeg] / libavfilter / af_amix.c
index ec2556f920742d4655e9d3d72b73928ac383f929..af8ad58262f96596520a8418e8e57595fbd3e8f8 100644 (file)
@@ -182,7 +182,7 @@ typedef struct MixContext {
 #define F AV_OPT_FLAG_FILTERING_PARAM
 static const AVOption amix_options[] = {
     { "inputs", "Number of inputs.",
-            OFFSET(nb_inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 1024, A|F },
+            OFFSET(nb_inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT16_MAX, A|F },
     { "duration", "How to determine the end-of-stream.",
             OFFSET(duration_mode), AV_OPT_TYPE_INT, { .i64 = DURATION_LONGEST }, 0,  2, A|F, "duration" },
         { "longest",  "Duration of longest input.",  0, AV_OPT_TYPE_CONST, { .i64 = DURATION_LONGEST  }, 0, 0, A|F, "duration" },
@@ -212,21 +212,21 @@ static void calculate_scales(MixContext *s, int nb_samples)
 
     for (i = 0; i < s->nb_inputs; i++)
         if (s->input_state[i] & INPUT_ON)
-            weight_sum += s->weights[i];
+            weight_sum += FFABS(s->weights[i]);
 
     for (i = 0; i < s->nb_inputs; i++) {
         if (s->input_state[i] & INPUT_ON) {
-            if (s->scale_norm[i] > weight_sum / s->weights[i]) {
-                s->scale_norm[i] -= ((s->weight_sum / s->weights[i]) / s->nb_inputs) *
+            if (s->scale_norm[i] > weight_sum / FFABS(s->weights[i])) {
+                s->scale_norm[i] -= ((s->weight_sum / FFABS(s->weights[i])) / s->nb_inputs) *
                                     nb_samples / (s->dropout_transition * s->sample_rate);
-                s->scale_norm[i] = FFMAX(s->scale_norm[i], weight_sum / s->weights[i]);
+                s->scale_norm[i] = FFMAX(s->scale_norm[i], weight_sum / FFABS(s->weights[i]));
             }
         }
     }
 
     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];
+            s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]);
         else
             s->input_scale[i] = 0.0f;
     }
@@ -270,7 +270,7 @@ static int config_output(AVFilterLink *outlink)
     if (!s->input_scale || !s->scale_norm)
         return AVERROR(ENOMEM);
     for (i = 0; i < s->nb_inputs; i++)
-        s->scale_norm[i] = s->weight_sum / s->weights[i];
+        s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
     calculate_scales(s, 0);
 
     av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout);
@@ -540,12 +540,12 @@ static av_cold int init(AVFilterContext *ctx)
         p = NULL;
         sscanf(arg, "%f", &last_weight);
         s->weights[i] = last_weight;
-        s->weight_sum += last_weight;
+        s->weight_sum += FFABS(last_weight);
     }
 
     for (; i < s->nb_inputs; i++) {
         s->weights[i] = last_weight;
-        s->weight_sum += last_weight;
+        s->weight_sum += FFABS(last_weight);
     }
 
     return 0;