Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -166,25 +166,25 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 165 unmodified lines | ||
| 166 | 166 | for (int ch = start; ch < end; ch++) { |
| 167 | 167 | const ftype *src = (const ftype *)in->extended_data[ch]; |
| 168 | 168 | ftype *dst = (ftype *)out->extended_data[ch]; |
| 169 | − ftype *state = (ftype *)s->state->extended_data[ch]; | |
| 170 | − const ftype threshold = detection == 0 ? state[5] : s->threshold; | |
| 171 | − ftype fa[3], fm[3]; | |
| 169 | + ChannelContext *cc = &s->cc[ch]; | |
| 170 | + const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold; | |
| 171 | + ftype *fa = fn(cc->fa), *fm = fn(cc->fm); | |
| 172 | + ftype *fstate = fn(cc->fstate); | |
| 173 | + ftype *dstate = fn(cc->dstate); | |
| 174 | + ftype gain = fn(cc->gain); | |
| 172 | 175 | |
| 173 | 176 | if (detection < 0) |
| 174 | − state[5] = threshold; | |
| 175 | − | |
| 176 | − memcpy(fa, state + 8, sizeof(fa)); | |
| 177 | − memcpy(fm, state + 11, sizeof(fm)); | |
| 177 | + fn(cc->threshold) = threshold; | |
| 178 | 178 | |
| 179 | 179 | for (int n = 0; n < out->nb_samples; n++) { |
| 180 | − ftype detect, gain, v, listen; | |
| 180 | + ftype detect, v, listen; | |
| 181 | 181 | ftype k, g; |
| 182 | 182 | |
| 183 | − detect = listen = fn(get_svf)(src[n], dm, da, state); | |
| 183 | + detect = listen = fn(get_svf)(src[n], dm, da, dstate); | |
| 184 | 184 | detect = FABS(detect); |
| 185 | 185 | |
| 186 | 186 | if (detection > 0) |
| 187 | − state[5] = FMAX(state[5], detect); | |
| 187 | + fn(cc->threshold) = FMAX(fn(cc->threshold), detect); | |
| 188 | 188 | |
| 189 | 189 | if (mode >= 0) { |
| 190 | 190 | if (direction == 0 && detect < threshold) { |
| @@ -200,17 +200,17 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 9 unmodified lines | ||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | { |
| 203 | − ftype delta = detect - state[4]; | |
| 203 | + ftype delta = detect - gain; | |
| 204 | 204 | |
| 205 | 205 | if (delta > EPSILON) |
| 206 | − detect = state[4] + attack * delta; | |
| 206 | + detect = gain + attack * delta; | |
| 207 | 207 | else if (delta < -EPSILON) |
| 208 | − detect = state[4] + release * delta; | |
| 208 | + detect = gain + release * delta; | |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | − if (state[4] != detect) { | |
| 213 | − state[4] = gain = detect; | |
| 212 | + if (gain != detect) { | |
| 213 | + gain = detect; | |
| 214 | 214 | |
| 215 | 215 | switch (tftype) { |
| 216 | 216 | case 0: |
| @@ -251,13 +251,12 @@ static int fn(filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int n · 34 unmodified lines | ||
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | − v = fn(get_svf)(src[n], fm, fa, &state[2]); | |
| 254 | + v = fn(get_svf)(src[n], fm, fa, fstate); | |
| 255 | 255 | v = mode == -1 ? listen : v; |
| 256 | 256 | dst[n] = ctx->is_disabled ? src[n] : v; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | − memcpy(state + 8, fa, sizeof(fa)); | |
| 260 | − memcpy(state + 11, fm, sizeof(fm)); | |
| 259 | + fn(cc->gain) = gain; | |
| 261 | 260 | } |
| 262 | 261 | |
| 263 | 262 | return 0; |
| @@ -23,6 +23,19 @@ · 22 unmodified lines | ||
| 23 | 23 | #include "audio.h" |
| 24 | 24 | #include "formats.h" |
| 25 | 25 | |
| 26 | +typedef struct ChannelContext { | |
| 27 | + double fa_double[3], fm_double[3]; | |
| 28 | + double dstate_double[2]; | |
| 29 | + double fstate_double[2]; | |
| 30 | + double gain_double; | |
| 31 | + double threshold_double; | |
| 32 | + float fa_float[3], fm_float[3]; | |
| 33 | + float dstate_float[2]; | |
| 34 | + float fstate_float[2]; | |
| 35 | + float gain_float; | |
| 36 | + float threshold_float; | |
| 37 | +} ChannelContext; | |
| 38 | + | |
| 26 | 39 | typedef struct AudioDynamicEqualizerContext { |
| 27 | 40 | const AVClass *class; |
| 28 | 41 | |
| @@ -52,7 +65,7 @@ typedef struct AudioDynamicEqualizerContext { · 23 unmodified lines | ||
| 52 | 65 | double da_double[3], dm_double[3]; |
| 53 | 66 | float da_float[3], dm_float[3]; |
| 54 | 67 | |
| 55 | − AVFrame *state; | |
| 68 | + ChannelContext *cc; | |
| 56 | 69 | } AudioDynamicEqualizerContext; |
| 57 | 70 | |
| 58 | 71 | static int query_formats(AVFilterContext *ctx) |
| @@ -96,8 +109,8 @@ static int config_input(AVFilterLink *inlink) · 37 unmodified lines | ||
| 96 | 109 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 97 | 110 | |
| 98 | 111 | s->format = inlink->format; |
| 99 | − s->state = ff_get_audio_buffer(inlink, 16); | |
| 100 | − if (!s->state) | |
| 112 | + s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc)); | |
| 113 | + if (!s->cc) | |
| 101 | 114 | return AVERROR(ENOMEM); |
| 102 | 115 | |
| 103 | 116 | switch (s->format) { |
| @@ -148,7 +161,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 44 unmodified lines | ||
| 148 | 161 | { |
| 149 | 162 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 150 | 163 | |
| 151 | − av_frame_free(&s->state); | |
| 164 | + av_freep(&s->cc); | |
| 152 | 165 | } |
| 153 | 166 | |
| 154 | 167 | #define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x) |