History

avfilter/af_adynamicequalizer: factor detection filter code

Paul B Mahol committed 3 years ago

Commit 153aaae1 parent 51504cf1 file · +46 −33Browse files

Unified · Split

libavfilter/af_adynamicequalizer.c+46−33
@@ -44,6 +44,7 @@ typedef struct AudioDynamicEqualizerContext { · 43 unmodified lines
4444 int tftype;
4545 int dftype;
4646
47+ double da[3], dm[3];
4748 AVFrame *state;
4849 } AudioDynamicEqualizerContext;
4950
@@ -65,7 +66,7 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines
6566 return 0;
6667 }
6768
68−static double get_svf(double in, double *m, double *a, double *b)
69+static double get_svf(double in, const double *m, const double *a, double *b)
6970 {
7071 const double v0 = in;
7172 const double v3 = v0 - b[1];
@@ -82,34 +83,25 @@ typedef struct ThreadData { · 10 unmodified lines
8283 AVFrame *in, *out;
8384 } ThreadData;
8485
85−static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
86+static double get_coef(double x, double sr)
87+{
88+ return exp(-1000. / (x * sr));
89+}
90+
91+static int filter_prepare(AVFilterContext *ctx)
8692 {
8793 AudioDynamicEqualizerContext *s = ctx->priv;
88− ThreadData *td = arg;
89− AVFrame *in = td->in;
90− AVFrame *out = td->out;
91− const double sample_rate = in->sample_rate;
92− const double makeup = s->makeup;
93− const double ratio = s->ratio;
94− const double range = s->range;
94+ const double sample_rate = ctx->inputs[0]->sample_rate;
9595 const double dfrequency = fmin(s->dfrequency, sample_rate * 0.5);
96− const double tfrequency = fmin(s->tfrequency, sample_rate * 0.5);
97− const double release = s->release_coef;
98− const double irelease = 1. - release;
99− const double attack = s->attack_coef;
100− const double iattack = 1. - attack;
101− const double dqfactor = s->dqfactor;
102− const double tqfactor = s->tqfactor;
103− const double fg = tan(M_PI * tfrequency / sample_rate);
10496 const double dg = tan(M_PI * dfrequency / sample_rate);
105− const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
106− const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
107− const int detection = s->detection;
108− const int direction = s->direction;
97+ const double dqfactor = s->dqfactor;
10998 const int dftype = s->dftype;
110− const int tftype = s->tftype;
111− const int mode = s->mode;
112− double k, da[3], dm[3];
99+ double *da = s->da;
100+ double *dm = s->dm;
101+ double k;
102+
103+ s->attack_coef = get_coef(s->attack, sample_rate);
104+ s->release_coef = get_coef(s->release, sample_rate);
113105
114106 switch (dftype) {
115107 case 0:
@@ -158,6 +150,35 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 42 unmodified lines
158150 break;
159151 }
160152
153+ return 0;
154+}
155+
156+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
157+{
158+ AudioDynamicEqualizerContext *s = ctx->priv;
159+ ThreadData *td = arg;
160+ AVFrame *in = td->in;
161+ AVFrame *out = td->out;
162+ const double sample_rate = in->sample_rate;
163+ const double makeup = s->makeup;
164+ const double ratio = s->ratio;
165+ const double range = s->range;
166+ const double tfrequency = fmin(s->tfrequency, sample_rate * 0.5);
167+ const double release = s->release_coef;
168+ const double irelease = 1. - release;
169+ const double attack = s->attack_coef;
170+ const double iattack = 1. - attack;
171+ const double tqfactor = s->tqfactor;
172+ const double fg = tan(M_PI * tfrequency / sample_rate);
173+ const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
174+ const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
175+ const int detection = s->detection;
176+ const int direction = s->direction;
177+ const int tftype = s->tftype;
178+ const int mode = s->mode;
179+ const double *da = s->da;
180+ const double *dm = s->dm;
181+
161182 for (int ch = start; ch < end; ch++) {
162183 const double *src = (const double *)in->extended_data[ch];
163184 double *dst = (double *)out->extended_data[ch];
@@ -254,16 +275,10 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 90 unmodified lines
254275 return 0;
255276 }
256277
257−static double get_coef(double x, double sr)
258−{
259− return exp(-1000. / (x * sr));
260−}
261−
262278 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
263279 {
264280 AVFilterContext *ctx = inlink->dst;
265281 AVFilterLink *outlink = ctx->outputs[0];
266− AudioDynamicEqualizerContext *s = ctx->priv;
267282 ThreadData td;
268283 AVFrame *out;
269284
@@ -278,11 +293,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 8 unmodified lines
278293 av_frame_copy_props(out, in);
279294 }
280295
281− s->attack_coef = get_coef(s->attack, in->sample_rate);
282− s->release_coef = get_coef(s->release, in->sample_rate);
283−
284296 td.in = in;
285297 td.out = out;
298+ filter_prepare(ctx);
286299 ff_filter_execute(ctx, filter_channels, &td, NULL,
287300 FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
288301

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