1
0
Fork 0

avfilter/af_adynamicequalizer: do detection of threshold first

Makes better results in final output if multiple filters are cascaded at once.
This commit is contained in:
Paul B Mahol 2023-11-05 15:52:46 +01:00
parent 799fad1828
commit 44a0148fad
2 changed files with 23 additions and 8 deletions

View File

@ -158,25 +158,41 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
const ftype fg = TAN(M_PI * tfrequency / sample_rate);
const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
const int is_disabled = ctx->is_disabled;
const int detection = s->detection;
const int tftype = s->tftype;
const ftype *da = fn(s->da);
const ftype *dm = fn(s->dm);
if (detection > 0) {
for (int ch = start; ch < end; ch++) {
const ftype *src = (const ftype *)in->extended_data[ch];
ChannelContext *cc = &s->cc[ch];
ftype *tstate = fn(cc->tstate);
for (int n = 0; n < in->nb_samples; n++) {
ftype detect = fn(get_svf)(src[n], dm, da, tstate);
fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
}
}
} else if (detection < 0) {
for (int ch = start; ch < end; ch++) {
ChannelContext *cc = &s->cc[ch];
fn(cc->threshold) = s->threshold;
}
}
for (int ch = start; ch < end; ch++) {
const ftype *src = (const ftype *)in->extended_data[ch];
ftype *dst = (ftype *)out->extended_data[ch];
ChannelContext *cc = &s->cc[ch];
const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold;
const ftype threshold = fn(cc->threshold);
ftype *fa = fn(cc->fa), *fm = fn(cc->fm);
ftype *fstate = fn(cc->fstate);
ftype *dstate = fn(cc->dstate);
ftype gain = fn(cc->gain);
const int init = cc->init;
if (detection < 0)
fn(cc->threshold) = threshold;
for (int n = 0; n < out->nb_samples; n++) {
ftype detect, v, listen, new_gain = ONE;
ftype k, g;
@ -184,9 +200,6 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
detect = listen = fn(get_svf)(src[n], dm, da, dstate);
detect = FABS(detect);
if (detection > 0)
fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
switch (mode) {
case LISTEN:
break;
@ -258,7 +271,7 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
v = fn(get_svf)(src[n], fm, fa, fstate);
v = mode == -1 ? listen : v;
dst[n] = ctx->is_disabled ? src[n] : v;
dst[n] = is_disabled ? src[n] : v;
}
fn(cc->gain) = gain;

View File

@ -36,11 +36,13 @@ typedef struct ChannelContext {
double fa_double[3], fm_double[3];
double dstate_double[2];
double fstate_double[2];
double tstate_double[2];
double gain_double;
double threshold_double;
float fa_float[3], fm_float[3];
float dstate_float[2];
float fstate_float[2];
float tstate_float[2];
float gain_float;
float threshold_float;
int init;