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 *state = (ftype *)s->state->extended_data[ch];
|
||||
const ftype threshold = detection == 0 ? state[5] : s->threshold;
|
||||
ftype fa[3], fm[3];
|
||||
|
||||
if (detection < 0)
|
||||
state[5] = threshold;
|
||||
|
||||
memcpy(fa, state + 8, sizeof(fa));
|
||||
memcpy(fm, state + 11, sizeof(fm));
|
||||
|
||||
for (int n = 0; n < out->nb_samples; n++) {
|
||||
ftype detect, gain, v, listen;
|
||||
ftype fa[3], fm[3];
|
||||
ftype k, g;
|
||||
|
||||
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)
|
||||
state[5] = FMAX(state[5], detect);
|
||||
|
||||
if (direction == 0) {
|
||||
if (detect < threshold) {
|
||||
if (mode == 0)
|
||||
detect = ONE / CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
||||
else
|
||||
detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
||||
if (mode >= 0) {
|
||||
if (direction == 0 && detect < threshold) {
|
||||
detect = CLIP(ONE + makeup + (threshold - detect) * ratio, ONE, range);
|
||||
if (!mode)
|
||||
detect = ONE / detect;
|
||||
} else if (direction == 1 && detect > threshold) {
|
||||
detect = CLIP(ONE + makeup + (detect - threshold) * ratio, ONE, range);
|
||||
if (!mode)
|
||||
detect = ONE / detect;
|
||||
} else {
|
||||
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 (detect > state[4]) {
|
||||
detect = iattack * detect + attack * state[4];
|
||||
} else {
|
||||
detect = irelease * detect + release * state[4];
|
||||
}
|
||||
} else {
|
||||
if (detect < state[4]) {
|
||||
if ((direction == 0 && detect > state[4]) || (direction == 1 && detect < state[4])) {
|
||||
detect = iattack * detect + attack * state[4];
|
||||
} else {
|
||||
detect = irelease * detect + release * state[4];
|
||||
}
|
||||
}
|
||||
|
||||
if (state[4] != detect || n == 0) {
|
||||
if (state[4] != detect) {
|
||||
state[4] = gain = detect;
|
||||
|
||||
switch (tftype) {
|
||||
case 0:
|
||||
k = ONE / (tqfactor * gain);
|
||||
k = itqfactor / gain;
|
||||
|
||||
fa[0] = ONE / (ONE + fg * (fg + k));
|
||||
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;
|
||||
dst[n] = ctx->is_disabled ? src[n] : v;
|
||||
}
|
||||
|
||||
memcpy(state + 8, fa, sizeof(fa));
|
||||
memcpy(state + 11, fm, sizeof(fm));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -96,26 +96,16 @@ static int config_input(AVFilterLink *inlink)
|
||||
AudioDynamicEqualizerContext *s = ctx->priv;
|
||||
|
||||
s->format = inlink->format;
|
||||
s->state = ff_get_audio_buffer(inlink, 8);
|
||||
s->state = ff_get_audio_buffer(inlink, 16);
|
||||
if (!s->state)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
switch (s->format) {
|
||||
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_channels = filter_channels_double;
|
||||
break;
|
||||
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_channels = filter_channels_float;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user