History

avfilter/af_adynamicequalizer: add auto option

Paul B Mahol committed 3 years ago

Commit 40512db1 parent 6869a802 files · +42 −6Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/af_adynamicequalizer.c+24−4
@@ -40,6 +40,7 @@ typedef struct AudioDynamicEqualizerContext { · 39 unmodified lines
4040 double release_coef;
4141 int mode;
4242 int direction;
43+ int detection;
4344 int type;
4445
4546 AVFrame *state;
@@ -92,7 +93,6 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 46 unmodified lines
9293 const double range = s->range;
9394 const double dfrequency = fmin(s->dfrequency, sample_rate * 0.5);
9495 const double tfrequency = fmin(s->tfrequency, sample_rate * 0.5);
95− const double threshold = s->threshold;
9696 const double release = s->release_coef;
9797 const double irelease = 1. - release;
9898 const double attack = s->attack_coef;
@@ -103,6 +103,7 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 4 unmodified lines
103103 const double dg = tan(M_PI * dfrequency / sample_rate);
104104 const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
105105 const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
106+ const int detection = s->detection;
106107 const int direction = s->direction;
107108 const int mode = s->mode;
108109 const int type = s->type;
@@ -124,6 +125,10 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 15 unmodified lines
124125 const double *src = (const double *)in->extended_data[ch];
125126 double *dst = (double *)out->extended_data[ch];
126127 double *state = (double *)s->state->extended_data[ch];
128+ const double threshold = detection == 0 ? state[5] : s->threshold;
129+
130+ if (detection < 0)
131+ state[5] = threshold;
127132
128133 for (int n = 0; n < out->nb_samples; n++) {
129134 double detect, gain, v, listen;
@@ -133,6 +138,9 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 3 unmodified lines
133138 detect = listen = get_svf(src[n], dm, da, state);
134139 detect = fabs(detect);
135140
141+ if (detection > 0)
142+ state[5] = fmax(state[5], detect);
143+
136144 if (direction == 0 && mode == 0 && detect < threshold)
137145 detect = 1. / av_clipd(1. + makeup + (threshold - detect) * ratio, 1., range);
138146 else if (direction == 0 && mode == 1 && detect < threshold)
@@ -144,10 +152,18 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 5 unmodified lines
144152 else
145153 detect = 1.;
146154
147− if (detect < state[4]) {
148− detect = iattack * detect + attack * state[4];
155+ if (direction == 0) {
156+ if (detect > state[4]) {
157+ detect = iattack * detect + attack * state[4];
158+ } else {
159+ detect = irelease * detect + release * state[4];
160+ }
149161 } else {
150− detect = irelease * detect + release * state[4];
162+ if (detect < state[4]) {
163+ detect = iattack * detect + attack * state[4];
164+ } else {
165+ detect = irelease * detect + release * state[4];
166+ }
151167 }
152168
153169 if (state[4] != detect || n == 0) {
@@ -270,6 +286,10 @@ static const AVOption adynamicequalizer_options[] = { · 116 unmodified lines
270286 { "direction", "set direction", OFFSET(direction), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "direction" },
271287 { "downward", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "direction" },
272288 { "upward", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "direction" },
289+ { "auto", "set auto threshold", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS, "auto" },
290+ { "disabled", 0, 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "auto" },
291+ { "off", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "auto" },
292+ { "on", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "auto" },
273293 { NULL }
274294 };
275295

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