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 | for (int ch = start; ch < end; ch++) { | 166 | for (int ch = start; ch < end; ch++) { |
| 167 | const ftype *src = (const ftype *)in->extended_data[ch]; | 167 | const ftype *src = (const ftype *)in->extended_data[ch]; |
| 168 | ftype *dst = (ftype *)out->extended_data[ch]; | 168 | ftype *dst = (ftype *)out->extended_data[ch]; |
| 169 | ftype *state = (ftype *)s->state->extended_data[ch]; | 169 | ChannelContext *cc = &s->cc[ch]; |
| 170 | const ftype threshold = detection == 0 ? state[5] : s->threshold; | 170 | const ftype threshold = detection == 0 ? fn(cc->threshold) : s->threshold; |
| 171 | ftype fa[3], fm[3]; | 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 | if (detection < 0) | 176 | if (detection < 0) |
| 174 | state[5] = threshold; | 177 | fn(cc->threshold) = threshold; |
| 175 | |||
| 176 | memcpy(fa, state + 8, sizeof(fa)); | ||
| 177 | memcpy(fm, state + 11, sizeof(fm)); | ||
| 178 | 178 | ||
| 179 | for (int n = 0; n < out->nb_samples; n++) { | 179 | for (int n = 0; n < out->nb_samples; n++) { |
| 180 | ftype detect, gain, v, listen; | 180 | ftype detect, v, listen; |
| 181 | ftype k, g; | 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 | detect = FABS(detect); | 184 | detect = FABS(detect); |
| 185 | 185 | ||
| 186 | if (detection > 0) | 186 | if (detection > 0) |
| 187 | state[5] = FMAX(state[5], detect); | 187 | fn(cc->threshold) = FMAX(fn(cc->threshold), detect); |
| 188 | 188 | ||
| 189 | if (mode >= 0) { | 189 | if (mode >= 0) { |
| 190 | if (direction == 0 && detect < threshold) { | 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 | if (delta > EPSILON) | 205 | if (delta > EPSILON) |
| 206 | detect = state[4] + attack * delta; | 206 | detect = gain + attack * delta; |
| 207 | else if (delta < -EPSILON) | 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) { | 212 | if (gain != detect) { |
| 213 | state[4] = gain = detect; | 213 | gain = detect; |
| 214 | 214 | ||
| 215 | switch (tftype) { | 215 | switch (tftype) { |
| 216 | case 0: | 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 | v = mode == -1 ? listen : v; | 255 | v = mode == -1 ? listen : v; |
| 256 | dst[n] = ctx->is_disabled ? src[n] : v; | 256 | dst[n] = ctx->is_disabled ? src[n] : v; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | memcpy(state + 8, fa, sizeof(fa)); | 259 | fn(cc->gain) = gain; |
| 260 | memcpy(state + 11, fm, sizeof(fm)); | ||
| 261 | } | 260 | } |
| 262 | 261 | ||
| 263 | return 0; | 262 | return 0; |
| @@ -23,6 +23,19 @@ · 22 unmodified lines | |||
| 23 | #include "audio.h" | 23 | #include "audio.h" |
| 24 | #include "formats.h" | 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 | typedef struct AudioDynamicEqualizerContext { | 39 | typedef struct AudioDynamicEqualizerContext { |
| 27 | const AVClass *class; | 40 | const AVClass *class; |
| 28 | 41 | ||
| @@ -52,7 +65,7 @@ typedef struct AudioDynamicEqualizerContext { · 23 unmodified lines | |||
| 52 | double da_double[3], dm_double[3]; | 65 | double da_double[3], dm_double[3]; |
| 53 | float da_float[3], dm_float[3]; | 66 | float da_float[3], dm_float[3]; |
| 54 | 67 | ||
| 55 | AVFrame *state; | 68 | ChannelContext *cc; |
| 56 | } AudioDynamicEqualizerContext; | 69 | } AudioDynamicEqualizerContext; |
| 57 | 70 | ||
| 58 | static int query_formats(AVFilterContext *ctx) | 71 | static int query_formats(AVFilterContext *ctx) |
| @@ -96,8 +109,8 @@ static int config_input(AVFilterLink *inlink) · 37 unmodified lines | |||
| 96 | AudioDynamicEqualizerContext *s = ctx->priv; | 109 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 97 | 110 | ||
| 98 | s->format = inlink->format; | 111 | s->format = inlink->format; |
| 99 | s->state = ff_get_audio_buffer(inlink, 16); | 112 | s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc)); |
| 100 | if (!s->state) | 113 | if (!s->cc) |
| 101 | return AVERROR(ENOMEM); | 114 | return AVERROR(ENOMEM); |
| 102 | 115 | ||
| 103 | switch (s->format) { | 116 | switch (s->format) { |
| @@ -148,7 +161,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 44 unmodified lines | |||
| 148 | { | 161 | { |
| 149 | AudioDynamicEqualizerContext *s = ctx->priv; | 162 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 150 | 163 | ||
| 151 | av_frame_free(&s->state); | 164 | av_freep(&s->cc); |
| 152 | } | 165 | } |
| 153 | 166 | ||
| 154 | #define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x) | 167 | #define OFFSET(x) offsetof(AudioDynamicEqualizerContext, x) |