History

avfilter/adynamicequalizer_template: refactor and improve output

Paul B Mahol committed 3 years ago

Commit 8622dcb1 parent 9ff834c2 files · +20 −38Browse files

Unified · Split

2 files
  1. libavfilter/adynamicequalizer_template.c +19 −27
  2. libavfilter/af_adynamicequalizer.c +1 −11
libavfilter/adynamicequalizer_template.c+19−27
@@ -167,13 +167,16 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 166 unmodified lines
167167 ftype *dst = (ftype *)out->extended_data[ch];
168168 ftype *state = (ftype *)s->state->extended_data[ch];
169169 const ftype threshold = detection == 0 ? state[5] : s->threshold;
170+ ftype fa[3], fm[3];
170171
171172 if (detection < 0)
172173 state[5] = threshold;
173174
175+ memcpy(fa, state + 8, sizeof(fa));
176+ memcpy(fm, state + 11, sizeof(fm));
177+
174178 for (int n = 0; n < out->nb_samples; n++) {
175179 ftype detect, gain, v, listen;
176− ftype fa[3], fm[3];
177180 ftype k, g;
178181
179182 detect = listen = fn(get_svf)(src[n], dm, da, state);
@@ -182,46 +185,32 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 2 unmodified lines
182185 if (detection > 0)
183186 state[5] = FMAX(state[5], detect);
184187
185− if (direction == 0) {
186− if (detect < threshold) {
187− if (mode == 0)
188− detect = ONE / CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
189− else
190− detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
188+ if (mode >= 0) {
189+ if (direction == 0 && detect < threshold) {
190+ detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
191+ if (!mode)
192+ detect = ONE / detect;
193+ } else if (direction == 1 && detect > threshold) {
194+ detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
195+ if (!mode)
196+ detect = ONE / detect;
191197 } else {
192198 detect = ONE;
193199 }
194− } else {
195− if (detect > threshold) {
196− if (mode == 0)
197− detect = ONE / CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
198− else
199− detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
200− } else {
201− detect = ONE;
202− }
203− }
204200
205− if (direction == 0) {
206− if (detect > state[4]) {
207− detect = iattack * detect + attack * state[4];
208− } else {
209− detect = irelease * detect + release * state[4];
210− }
211− } else {
212− if (detect < state[4]) {
201+ if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
213202 detect = iattack * detect + attack * state[4];
214203 } else {
215204 detect = irelease * detect + release * state[4];
216205 }
217206 }
218207
219− if (state[4] != detect || n == 0) {
208+ if (state[4] != detect) {
220209 state[4] = gain = detect;
221210
222211 switch (tftype) {
223212 case 0:
224− k = ONE / (tqfactor * gain);
213+ k = itqfactor / gain;
225214
226215 fa[0] = ONE / (ONE + fg * (fg + k));
227216 fa[1] = fg * fa[0];
@@ -262,6 +251,9 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 34 unmodified lines
262251 v = mode == -1 ? listen : v;
263252 dst[n] = ctx->is_disabled ? src[n] : v;
264253 }
254+
255+ memcpy(state + 8, fa, sizeof(fa));
256+ memcpy(state + 11, fm, sizeof(fm));
265257 }
266258
267259 return 0;
libavfilter/af_adynamicequalizer.c+1−11
@@ -96,26 +96,16 @@ static int config_input(AVFilterLink *inlink) · 95 unmodified lines
9696 AudioDynamicEqualizerContext *s = ctx->priv;
9797
9898 s->format = inlink->format;
99− s->state = ff_get_audio_buffer(inlink, 8);
99+ s->state = ff_get_audio_buffer(inlink, 16);
100100 if (!s->state)
101101 return AVERROR(ENOMEM);
102102
103103 switch (s->format) {
104104 case AV_SAMPLE_FMT_DBLP:
105− for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
106− double *state = (double *)s->state->extended_data[ch];
107−
108− state[4] = 1.;
109− }
110105 s->filter_prepare = filter_prepare_double;
111106 s->filter_channels = filter_channels_double;
112107 break;
113108 case AV_SAMPLE_FMT_FLTP:
114− for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
115− float *state = (float *)s->state->extended_data[ch];
116−
117− state[4] = 1.;
118− }
119109 s->filter_prepare = filter_prepare_float;
120110 s->filter_channels = filter_channels_float;
121111 break;

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