History

avfilter/af_adynamicequalizer: add new structure to hold filtering state

Paul B Mahol committed 3 years ago

Commit 43226ef1 parent 3f890fb2 files · +34 −22Browse files

Unified · Split

2 files
  1. libavfilter/adynamicequalizer_template.c +17 −18
  2. libavfilter/af_adynamicequalizer.c +17 −4
libavfilter/adynamicequalizer_template.c+17−18
@@ -166,25 +166,25 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 165 unmodified lines
166166 for (int ch = start; ch < end; ch++) {
167167 const ftype *src = (const ftype *)in->extended_data[ch];
168168 ftype *dst = (ftype *)out->extended_data[ch];
169− ftype *state = (ftype *)s->state->extended_data[ch];
170− const ftype threshold = detection == 0 ? state[5] : s->threshold;
171− ftype fa[3], fm[3];
169+ ChannelContext *cc = &s->cc[ch];
170+ const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold;
171+ ftype *fa = fn(cc->fa), *fm = fn(cc->fm);
172+ ftype *fstate = fn(cc->fstate);
173+ ftype *dstate = fn(cc->dstate);
174+ ftype gain = fn(cc->gain);
172175
173176 if (detection < 0)
174− state[5] = threshold;
175−
176− memcpy(fa, state + 8, sizeof(fa));
177− memcpy(fm, state + 11, sizeof(fm));
177+ fn(cc->threshold) = threshold;
178178
179179 for (int n = 0; n < out->nb_samples; n++) {
180− ftype detect, gain, v, listen;
180+ ftype detect, v, listen;
181181 ftype k, g;
182182
183− detect = listen = fn(get_svf)(src[n], dm, da, state);
183+ detect = listen = fn(get_svf)(src[n], dm, da, dstate);
184184 detect = FABS(detect);
185185
186186 if (detection > 0)
187− state[5] = FMAX(state[5], detect);
187+ fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
188188
189189 if (mode >= 0) {
190190 if (direction == 0 && detect < threshold) {
@@ -200,17 +200,17 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 9 unmodified lines
200200 }
201201
202202 {
203− ftype delta = detect - state[4];
203+ ftype delta = detect - gain;
204204
205205 if (delta > EPSILON)
206− detect = state[4] + attack * delta;
206+ detect = gain + attack * delta;
207207 else if (delta < -EPSILON)
208− detect = state[4] + release * delta;
208+ detect = gain + release * delta;
209209 }
210210 }
211211
212− if (state[4] != detect) {
213− state[4] = gain = detect;
212+ if (gain != detect) {
213+ gain = detect;
214214
215215 switch (tftype) {
216216 case 0:
@@ -251,13 +251,12 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 34 unmodified lines
251251 }
252252 }
253253
254− v = fn(get_svf)(src[n], fm, fa, &state[2]);
254+ v = fn(get_svf)(src[n], fm, fa, fstate);
255255 v = mode == -1 ? listen : v;
256256 dst[n] = ctx->is_disabled ? src[n] : v;
257257 }
258258
259− memcpy(state + 8, fa, sizeof(fa));
260− memcpy(state + 11, fm, sizeof(fm));
259+ fn(cc->gain) = gain;
261260 }
262261
263262 return 0;
libavfilter/af_adynamicequalizer.c+17−4
@@ -23,6 +23,19 @@ · 22 unmodified lines
2323 #include "audio.h"
2424 #include "formats.h"
2525
26+typedef struct ChannelContext {
27+ double fa_double[3], fm_double[3];
28+ double dstate_double[2];
29+ double fstate_double[2];
30+ double gain_double;
31+ double threshold_double;
32+ float fa_float[3], fm_float[3];
33+ float dstate_float[2];
34+ float fstate_float[2];
35+ float gain_float;
36+ float threshold_float;
37+} ChannelContext;
38+
2639 typedef struct AudioDynamicEqualizerContext {
2740 const AVClass *class;
2841
@@ -52,7 +65,7 @@ typedef struct AudioDynamicEqualizerContext { · 23 unmodified lines
5265 double da_double[3], dm_double[3];
5366 float da_float[3], dm_float[3];
5467
55− AVFrame *state;
68+ ChannelContext *cc;
5669 } AudioDynamicEqualizerContext;
5770
5871 static int query_formats(AVFilterContext *ctx)
@@ -96,8 +109,8 @@ static int config_input(AVFilterLink *inlink) · 37 unmodified lines
96109 AudioDynamicEqualizerContext *s = ctx->priv;
97110
98111 s->format = inlink->format;
99− s->state = ff_get_audio_buffer(inlink, 16);
100− if (!s->state)
112+ s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc));
113+ if (!s->cc)
101114 return AVERROR(ENOMEM);
102115
103116 switch (s->format) {
@@ -148,7 +161,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 44 unmodified lines
148161 {
149162 AudioDynamicEqualizerContext *s = ctx->priv;
150163
151− av_frame_free(&s->state);
164+ av_freep(&s->cc);
152165 }
153166
154167 #define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x)

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