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
167 ftype *dst = (ftype *)out->extended_data[ch];167 ftype *dst = (ftype *)out->extended_data[ch];
168 ftype *state = (ftype *)s->state->extended_data[ch];168 ftype *state = (ftype *)s->state->extended_data[ch];
169 const ftype threshold = detection == 0 ? state[5] : s->threshold;169 const ftype threshold = detection == 0 ? state[5] : s->threshold;
170 ftype fa[3], fm[3];
170 171
171 if (detection < 0)172 if (detection < 0)
172 state[5] = threshold;173 state[5] = threshold;
173 174
175 memcpy(fa, state + 8, sizeof(fa));
176 memcpy(fm, state + 11, sizeof(fm));
177
174 for (int n = 0; n < out->nb_samples; n++) {178 for (int n = 0; n < out->nb_samples; n++) {
175 ftype detect, gain, v, listen;179 ftype detect, gain, v, listen;
176 ftype fa[3], fm[3];
177 ftype k, g;180 ftype k, g;
178 181
179 detect = listen = fn(get_svf)(src[n], dm, da, state);182 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
182 if (detection > 0)185 if (detection > 0)
183 state[5] = FMAX(state[5], detect);186 state[5] = FMAX(state[5], detect);
184 187
185 if (direction == 0) {188 if (mode >= 0) {
186 if (detect < threshold) {189 if (direction == 0 && detect < threshold) {
187 if (mode == 0)190 detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
188 detect = ONE / CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);191 if (!mode)
189 else192 detect = ONE / detect;
190 detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);193 } else if (direction == 1 && detect > threshold) {
194 detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
195 if (!mode)
196 detect = ONE / detect;
191 } else {197 } else {
192 detect = ONE;198 detect = ONE;
193 }199 }
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 }
204 200
205 if (direction == 0) {201 if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
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]) {
213 detect = iattack * detect + attack * state[4];202 detect = iattack * detect + attack * state[4];
214 } else {203 } else {
215 detect = irelease * detect + release * state[4];204 detect = irelease * detect + release * state[4];
216 }205 }
217 }206 }
218 207
219 if (state[4] != detect || n == 0) {208 if (state[4] != detect) {
220 state[4] = gain = detect;209 state[4] = gain = detect;
221 210
222 switch (tftype) {211 switch (tftype) {
223 case 0:212 case 0:
224 k = ONE / (tqfactor * gain);213 k = itqfactor / gain;
225 214
226 fa[0] = ONE / (ONE + fg * (fg + k));215 fa[0] = ONE / (ONE + fg * (fg + k));
227 fa[1] = fg * fa[0];216 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
262 v = mode == -1 ? listen : v;251 v = mode == -1 ? listen : v;
263 dst[n] = ctx->is_disabled ? src[n] : v;252 dst[n] = ctx->is_disabled ? src[n] : v;
264 }253 }
254
255 memcpy(state + 8, fa, sizeof(fa));
256 memcpy(state + 11, fm, sizeof(fm));
265 }257 }
266 258
267 return 0;259 return 0;
libavfilter/af_adynamicequalizer.c+1−11
@@ -96,26 +96,16 @@ static int config_input(AVFilterLink *inlink) · 95 unmodified lines
96 AudioDynamicEqualizerContext *s = ctx->priv;96 AudioDynamicEqualizerContext *s = ctx->priv;
97 97
98 s->format = inlink->format;98 s->format = inlink->format;
99 s->state = ff_get_audio_buffer(inlink, 8);99 s->state = ff_get_audio_buffer(inlink, 16);
100 if (!s->state)100 if (!s->state)
101 return AVERROR(ENOMEM);101 return AVERROR(ENOMEM);
102 102
103 switch (s->format) {103 switch (s->format) {
104 case AV_SAMPLE_FMT_DBLP:104 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 }
110 s->filter_prepare = filter_prepare_double;105 s->filter_prepare = filter_prepare_double;
111 s->filter_channels = filter_channels_double;106 s->filter_channels = filter_channels_double;
112 break;107 break;
113 case AV_SAMPLE_FMT_FLTP:108 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 }
119 s->filter_prepare = filter_prepare_float;109 s->filter_prepare = filter_prepare_float;
120 s->filter_channels = filter_channels_float;110 s->filter_channels = filter_channels_float;
121 break;111 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