mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avfilter/adynamicequalizer_template: refactor and improve output
This commit is contained in:
parent
9ff834c2a0
commit
8622dcb39b
@ -167,13 +167,16 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
|
|||||||
ftype *dst = (ftype *)out->extended_data[ch];
|
ftype *dst = (ftype *)out->extended_data[ch];
|
||||||
ftype *state = (ftype *)s->state->extended_data[ch];
|
ftype *state = (ftype *)s->state->extended_data[ch];
|
||||||
const ftype threshold = detection == 0 ? state[5] : s->threshold;
|
const ftype threshold = detection == 0 ? state[5] : s->threshold;
|
||||||
|
ftype fa[3], fm[3];
|
||||||
|
|
||||||
if (detection < 0)
|
if (detection < 0)
|
||||||
state[5] = threshold;
|
state[5] = threshold;
|
||||||
|
|
||||||
|
memcpy(fa, state + 8, sizeof(fa));
|
||||||
|
memcpy(fm, state + 11, sizeof(fm));
|
||||||
|
|
||||||
for (int n = 0; n < out->nb_samples; n++) {
|
for (int n = 0; n < out->nb_samples; n++) {
|
||||||
ftype detect, gain, v, listen;
|
ftype detect, gain, v, listen;
|
||||||
ftype fa[3], fm[3];
|
|
||||||
ftype k, g;
|
ftype k, g;
|
||||||
|
|
||||||
detect = listen = fn(get_svf)(src[n], dm, da, state);
|
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
|
|||||||
if (detection > 0)
|
if (detection > 0)
|
||||||
state[5] = FMAX(state[5], detect);
|
state[5] = FMAX(state[5], detect);
|
||||||
|
|
||||||
if (direction == 0) {
|
if (mode >= 0) {
|
||||||
if (detect < threshold) {
|
if (direction == 0 && detect < threshold) {
|
||||||
if (mode == 0)
|
detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
||||||
detect = ONE / CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
if (!mode)
|
||||||
else
|
detect = ONE / detect;
|
||||||
detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
} else if (direction == 1 && detect > threshold) {
|
||||||
|
detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
|
||||||
|
if (!mode)
|
||||||
|
detect = ONE / detect;
|
||||||
} else {
|
} else {
|
||||||
detect = ONE;
|
detect = ONE;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (detect > threshold) {
|
|
||||||
if (mode == 0)
|
|
||||||
detect = ONE / CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
|
|
||||||
else
|
|
||||||
detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
|
|
||||||
} else {
|
|
||||||
detect = ONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == 0) {
|
if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
|
||||||
if (detect > state[4]) {
|
|
||||||
detect = iattack * detect + attack * state[4];
|
|
||||||
} else {
|
|
||||||
detect = irelease * detect + release * state[4];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (detect < state[4]) {
|
|
||||||
detect = iattack * detect + attack * state[4];
|
detect = iattack * detect + attack * state[4];
|
||||||
} else {
|
} else {
|
||||||
detect = irelease * detect + release * state[4];
|
detect = irelease * detect + release * state[4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state[4] != detect || n == 0) {
|
if (state[4] != detect) {
|
||||||
state[4] = gain = detect;
|
state[4] = gain = detect;
|
||||||
|
|
||||||
switch (tftype) {
|
switch (tftype) {
|
||||||
case 0:
|
case 0:
|
||||||
k = ONE / (tqfactor * gain);
|
k = itqfactor / gain;
|
||||||
|
|
||||||
fa[0] = ONE / (ONE + fg * (fg + k));
|
fa[0] = ONE / (ONE + fg * (fg + k));
|
||||||
fa[1] = fg * fa[0];
|
fa[1] = fg * fa[0];
|
||||||
@ -262,6 +251,9 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
|
|||||||
v = mode == -1 ? listen : v;
|
v = mode == -1 ? listen : v;
|
||||||
dst[n] = ctx->is_disabled ? src[n] : v;
|
dst[n] = ctx->is_disabled ? src[n] : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(state + 8, fa, sizeof(fa));
|
||||||
|
memcpy(state + 11, fm, sizeof(fm));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -96,26 +96,16 @@ static int config_input(AVFilterLink *inlink)
|
|||||||
AudioDynamicEqualizerContext *s = ctx->priv;
|
AudioDynamicEqualizerContext *s = ctx->priv;
|
||||||
|
|
||||||
s->format = inlink->format;
|
s->format = inlink->format;
|
||||||
s->state = ff_get_audio_buffer(inlink, 8);
|
s->state = ff_get_audio_buffer(inlink, 16);
|
||||||
if (!s->state)
|
if (!s->state)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
switch (s->format) {
|
switch (s->format) {
|
||||||
case AV_SAMPLE_FMT_DBLP:
|
case AV_SAMPLE_FMT_DBLP:
|
||||||
for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
|
||||||
double *state = (double *)s->state->extended_data[ch];
|
|
||||||
|
|
||||||
state[4] = 1.;
|
|
||||||
}
|
|
||||||
s->filter_prepare = filter_prepare_double;
|
s->filter_prepare = filter_prepare_double;
|
||||||
s->filter_channels = filter_channels_double;
|
s->filter_channels = filter_channels_double;
|
||||||
break;
|
break;
|
||||||
case AV_SAMPLE_FMT_FLTP:
|
case AV_SAMPLE_FMT_FLTP:
|
||||||
for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
|
||||||
float *state = (float *)s->state->extended_data[ch];
|
|
||||||
|
|
||||||
state[4] = 1.;
|
|
||||||
}
|
|
||||||
s->filter_prepare = filter_prepare_float;
|
s->filter_prepare = filter_prepare_float;
|
||||||
s->filter_channels = filter_channels_float;
|
s->filter_channels = filter_channels_float;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user