avfilter/af_adynamicequalizer: add new structure to hold filtering state
This commit is contained in:
parent
3f890fbfd9
commit
43226efc21
@ -166,25 +166,25 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
|
|||||||
for (int ch = start; ch < end; ch++) {
|
for (int ch = start; ch < end; ch++) {
|
||||||
const ftype *src = (const ftype *)in->extended_data[ch];
|
const ftype *src = (const ftype *)in->extended_data[ch];
|
||||||
ftype *dst = (ftype *)out->extended_data[ch];
|
ftype *dst = (ftype *)out->extended_data[ch];
|
||||||
ftype *state = (ftype *)s->state->extended_data[ch];
|
ChannelContext *cc = &s->cc[ch];
|
||||||
const ftype threshold = detection == 0 ? state[5] : s->threshold;
|
const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold;
|
||||||
ftype fa[3], fm[3];
|
ftype *fa = fn(cc->fa), *fm = fn(cc->fm);
|
||||||
|
ftype *fstate = fn(cc->fstate);
|
||||||
|
ftype *dstate = fn(cc->dstate);
|
||||||
|
ftype gain = fn(cc->gain);
|
||||||
|
|
||||||
if (detection < 0)
|
if (detection < 0)
|
||||||
state[5] = threshold;
|
fn(cc->threshold) = 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, v, listen;
|
||||||
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, dstate);
|
||||||
detect = FABS(detect);
|
detect = FABS(detect);
|
||||||
|
|
||||||
if (detection > 0)
|
if (detection > 0)
|
||||||
state[5] = FMAX(state[5], detect);
|
fn(cc->threshold) = FMAX(fn(cc->threshold), detect);
|
||||||
|
|
||||||
if (mode >= 0) {
|
if (mode >= 0) {
|
||||||
if (direction == 0 && detect < threshold) {
|
if (direction == 0 && detect < threshold) {
|
||||||
@ -200,17 +200,17 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ftype delta = detect - state[4];
|
ftype delta = detect - gain;
|
||||||
|
|
||||||
if (delta > EPSILON)
|
if (delta > EPSILON)
|
||||||
detect = state[4] + attack * delta;
|
detect = gain + attack * delta;
|
||||||
else if (delta < -EPSILON)
|
else if (delta < -EPSILON)
|
||||||
detect = state[4] + release * delta;
|
detect = gain + release * delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state[4] != detect) {
|
if (gain != detect) {
|
||||||
state[4] = gain = detect;
|
gain = detect;
|
||||||
|
|
||||||
switch (tftype) {
|
switch (tftype) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -251,13 +251,12 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v = fn(get_svf)(src[n], fm, fa, &state[2]);
|
v = fn(get_svf)(src[n], fm, fa, fstate);
|
||||||
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));
|
fn(cc->gain) = gain;
|
||||||
memcpy(state + 11, fm, sizeof(fm));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -23,6 +23,19 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "formats.h"
|
#include "formats.h"
|
||||||
|
|
||||||
|
typedef struct ChannelContext {
|
||||||
|
double fa_double[3], fm_double[3];
|
||||||
|
double dstate_double[2];
|
||||||
|
double fstate_double[2];
|
||||||
|
double gain_double;
|
||||||
|
double threshold_double;
|
||||||
|
float fa_float[3], fm_float[3];
|
||||||
|
float dstate_float[2];
|
||||||
|
float fstate_float[2];
|
||||||
|
float gain_float;
|
||||||
|
float threshold_float;
|
||||||
|
} ChannelContext;
|
||||||
|
|
||||||
typedef struct AudioDynamicEqualizerContext {
|
typedef struct AudioDynamicEqualizerContext {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
|
|
||||||
@ -52,7 +65,7 @@ typedef struct AudioDynamicEqualizerContext {
|
|||||||
double da_double[3], dm_double[3];
|
double da_double[3], dm_double[3];
|
||||||
float da_float[3], dm_float[3];
|
float da_float[3], dm_float[3];
|
||||||
|
|
||||||
AVFrame *state;
|
ChannelContext *cc;
|
||||||
} AudioDynamicEqualizerContext;
|
} AudioDynamicEqualizerContext;
|
||||||
|
|
||||||
static int query_formats(AVFilterContext *ctx)
|
static int query_formats(AVFilterContext *ctx)
|
||||||
@ -96,8 +109,8 @@ 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, 16);
|
s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc));
|
||||||
if (!s->state)
|
if (!s->cc)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
switch (s->format) {
|
switch (s->format) {
|
||||||
@ -148,7 +161,7 @@ static av_cold void uninit(AVFilterContext *ctx)
|
|||||||
{
|
{
|
||||||
AudioDynamicEqualizerContext *s = ctx->priv;
|
AudioDynamicEqualizerContext *s = ctx->priv;
|
||||||
|
|
||||||
av_frame_free(&s->state);
|
av_freep(&s->cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x)
|
#define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user