Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -44,6 +44,7 @@ typedef struct AudioDynamicEqualizerContext { · 43 unmodified lines | ||
| 44 | 44 | int tftype; |
| 45 | 45 | int dftype; |
| 46 | 46 | |
| 47 | + double da[3], dm[3]; | |
| 47 | 48 | AVFrame *state; |
| 48 | 49 | } AudioDynamicEqualizerContext; |
| 49 | 50 | |
| @@ -65,7 +66,7 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines | ||
| 65 | 66 | return 0; |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | −static double get_svf(double in, double *m, double *a, double *b) | |
| 69 | +static double get_svf(double in, const double *m, const double *a, double *b) | |
| 69 | 70 | { |
| 70 | 71 | const double v0 = in; |
| 71 | 72 | const double v3 = v0 - b[1]; |
| @@ -82,34 +83,25 @@ typedef struct ThreadData { · 10 unmodified lines | ||
| 82 | 83 | AVFrame *in, *out; |
| 83 | 84 | } ThreadData; |
| 84 | 85 | |
| 85 | −static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 86 | +static double get_coef(double x, double sr) | |
| 87 | +{ | |
| 88 | + return exp(-1000. / (x * sr)); | |
| 89 | +} | |
| 90 | + | |
| 91 | +static int filter_prepare(AVFilterContext *ctx) | |
| 86 | 92 | { |
| 87 | 93 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 88 | − ThreadData *td = arg; | |
| 89 | − AVFrame *in = td->in; | |
| 90 | − AVFrame *out = td->out; | |
| 91 | − const double sample_rate = in->sample_rate; | |
| 92 | − const double makeup = s->makeup; | |
| 93 | − const double ratio = s->ratio; | |
| 94 | − const double range = s->range; | |
| 94 | + const double sample_rate = ctx->inputs[0]->sample_rate; | |
| 95 | 95 | const double dfrequency = fmin(s->dfrequency, sample_rate * 0.5); |
| 96 | − const double tfrequency = fmin(s->tfrequency, sample_rate * 0.5); | |
| 97 | − const double release = s->release_coef; | |
| 98 | − const double irelease = 1. - release; | |
| 99 | − const double attack = s->attack_coef; | |
| 100 | − const double iattack = 1. - attack; | |
| 101 | − const double dqfactor = s->dqfactor; | |
| 102 | − const double tqfactor = s->tqfactor; | |
| 103 | − const double fg = tan(M_PI * tfrequency / sample_rate); | |
| 104 | 96 | const double dg = tan(M_PI * dfrequency / sample_rate); |
| 105 | − const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs; | |
| 106 | − const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs; | |
| 107 | − const int detection = s->detection; | |
| 108 | − const int direction = s->direction; | |
| 97 | + const double dqfactor = s->dqfactor; | |
| 109 | 98 | const int dftype = s->dftype; |
| 110 | − const int tftype = s->tftype; | |
| 111 | − const int mode = s->mode; | |
| 112 | − double k, da[3], dm[3]; | |
| 99 | + double *da = s->da; | |
| 100 | + double *dm = s->dm; | |
| 101 | + double k; | |
| 102 | + | |
| 103 | + s->attack_coef = get_coef(s->attack, sample_rate); | |
| 104 | + s->release_coef = get_coef(s->release, sample_rate); | |
| 113 | 105 | |
| 114 | 106 | switch (dftype) { |
| 115 | 107 | case 0: |
| @@ -158,6 +150,35 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 42 unmodified lines | ||
| 158 | 150 | break; |
| 159 | 151 | } |
| 160 | 152 | |
| 153 | + return 0; | |
| 154 | +} | |
| 155 | + | |
| 156 | +static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 157 | +{ | |
| 158 | + AudioDynamicEqualizerContext *s = ctx->priv; | |
| 159 | + ThreadData *td = arg; | |
| 160 | + AVFrame *in = td->in; | |
| 161 | + AVFrame *out = td->out; | |
| 162 | + const double sample_rate = in->sample_rate; | |
| 163 | + const double makeup = s->makeup; | |
| 164 | + const double ratio = s->ratio; | |
| 165 | + const double range = s->range; | |
| 166 | + const double tfrequency = fmin(s->tfrequency, sample_rate * 0.5); | |
| 167 | + const double release = s->release_coef; | |
| 168 | + const double irelease = 1. - release; | |
| 169 | + const double attack = s->attack_coef; | |
| 170 | + const double iattack = 1. - attack; | |
| 171 | + const double tqfactor = s->tqfactor; | |
| 172 | + const double fg = tan(M_PI * tfrequency / sample_rate); | |
| 173 | + const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs; | |
| 174 | + const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs; | |
| 175 | + const int detection = s->detection; | |
| 176 | + const int direction = s->direction; | |
| 177 | + const int tftype = s->tftype; | |
| 178 | + const int mode = s->mode; | |
| 179 | + const double *da = s->da; | |
| 180 | + const double *dm = s->dm; | |
| 181 | + | |
| 161 | 182 | for (int ch = start; ch < end; ch++) { |
| 162 | 183 | const double *src = (const double *)in->extended_data[ch]; |
| 163 | 184 | double *dst = (double *)out->extended_data[ch]; |
| @@ -254,16 +275,10 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 90 unmodified lines | ||
| 254 | 275 | return 0; |
| 255 | 276 | } |
| 256 | 277 | |
| 257 | −static double get_coef(double x, double sr) | |
| 258 | −{ | |
| 259 | − return exp(-1000. / (x * sr)); | |
| 260 | −} | |
| 261 | − | |
| 262 | 278 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| 263 | 279 | { |
| 264 | 280 | AVFilterContext *ctx = inlink->dst; |
| 265 | 281 | AVFilterLink *outlink = ctx->outputs[0]; |
| 266 | − AudioDynamicEqualizerContext *s = ctx->priv; | |
| 267 | 282 | ThreadData td; |
| 268 | 283 | AVFrame *out; |
| 269 | 284 | |
| @@ -278,11 +293,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 8 unmodified lines | ||
| 278 | 293 | av_frame_copy_props(out, in); |
| 279 | 294 | } |
| 280 | 295 | |
| 281 | − s->attack_coef = get_coef(s->attack, in->sample_rate); | |
| 282 | − s->release_coef = get_coef(s->release, in->sample_rate); | |
| 283 | − | |
| 284 | 296 | td.in = in; |
| 285 | 297 | td.out = out; |
| 298 | + filter_prepare(ctx); | |
| 286 | 299 | ff_filter_execute(ctx, filter_channels, &td, NULL, |
| 287 | 300 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); |
| 288 | 301 | |