History

avfilter/af_amix: add sum option

Paul B Mahol committed 5 years ago

Commit 57651491 parent e955f5a2 files · +16 −3Browse files

Unified · Split

2 files
  1. doc/filters.texi +6 −0
  2. libavfilter/af_amix.c +10 −3
doc/filters.texi+6−0
@@ -1879,6 +1879,11 @@ stream ends. The default value is 2 seconds. · 1878 unmodified lines
1879@item weights1879@item weights
1880Specify weight of each input audio stream as sequence.1880Specify weight of each input audio stream as sequence.
1881Each weight is separated by space. By default all inputs have same weight.1881Each weight is separated by space. By default all inputs have same weight.
1882
1883@item sum
1884Do not scale inputs but instead do only summation of samples.
1885Beware of heavy clipping if inputs are not normalized prior of filtering
1886or output from @var{amix} normalized after filtering. By default is disabled.
1882@end table1887@end table
1883 1888
1884@subsection Commands1889@subsection Commands
@@ -1886,6 +1891,7 @@ Each weight is separated by space. By default all inputs have same weight. · 1 unmodified line
1886This filter supports the following commands:1891This filter supports the following commands:
1887@table @option1892@table @option
1888@item weights1893@item weights
1894@item sum
1889Syntax is same as option with same name.1895Syntax is same as option with same name.
1890@end table1896@end table
1891 1897
libavfilter/af_amix.c+10−3
@@ -164,6 +164,7 @@ typedef struct MixContext { · 163 unmodified lines
164 int duration_mode; /**< mode for determining duration */164 int duration_mode; /**< mode for determining duration */
165 float dropout_transition; /**< transition time when an input drops out */165 float dropout_transition; /**< transition time when an input drops out */
166 char *weights_str; /**< string for custom weights for every input */166 char *weights_str; /**< string for custom weights for every input */
167 int sum; /**< inputs are not scaled, only added */
167 168
168 int nb_channels; /**< number of channels */169 int nb_channels; /**< number of channels */
169 int sample_rate; /**< sample rate */170 int sample_rate; /**< sample rate */
@@ -195,6 +196,8 @@ static const AVOption amix_options[] = { · 25 unmodified lines
195 OFFSET(dropout_transition), AV_OPT_TYPE_FLOAT, { .dbl = 2.0 }, 0, INT_MAX, A|F },196 OFFSET(dropout_transition), AV_OPT_TYPE_FLOAT, { .dbl = 2.0 }, 0, INT_MAX, A|F },
196 { "weights", "Set weight for each input.",197 { "weights", "Set weight for each input.",
197 OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F|T },198 OFFSET(weights_str), AV_OPT_TYPE_STRING, {.str="1 1"}, 0, 0, A|F|T },
199 { "sum", "Do not scale inputs instead do only sum",
200 OFFSET(sum), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A|F|T },
198 { NULL }201 { NULL }
199};202};
200 203
@@ -227,10 +230,14 @@ static void calculate_scales(MixContext *s, int nb_samples) · 26 unmodified lines
227 }230 }
228 231
229 for (i = 0; i < s->nb_inputs; i++) {232 for (i = 0; i < s->nb_inputs; i++) {
230 if (s->input_state[i] & INPUT_ON)233 if (s->input_state[i] & INPUT_ON) {
231 s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]);234 if (s->sum)
232 else235 s->input_scale[i] = 1.0f;
236 else
237 s->input_scale[i] = 1.0f / s->scale_norm[i] * FFSIGN(s->weights[i]);
238 } else {
233 s->input_scale[i] = 0.0f;239 s->input_scale[i] = 0.0f;
240 }
234 }241 }
235}242}
236 243

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t