Unified · Split
| @@ -44,6 +44,7 @@ typedef struct AudioDynamicEqualizerContext { · 43 unmodified lines | |||
| 44 | int tftype; | 44 | int tftype; |
| 45 | int dftype; | 45 | int dftype; |
| 46 | 46 | ||
| 47 | double da[3], dm[3]; | ||
| 47 | AVFrame *state; | 48 | AVFrame *state; |
| 48 | } AudioDynamicEqualizerContext; | 49 | } AudioDynamicEqualizerContext; |
| 49 | 50 | ||
| @@ -65,7 +66,7 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines | |||
| 65 | return 0; | 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 | const double v0 = in; | 71 | const double v0 = in; |
| 71 | const double v3 = v0 - b[1]; | 72 | const double v3 = v0 - b[1]; |
| @@ -82,34 +83,25 @@ typedef struct ThreadData { · 10 unmodified lines | |||
| 82 | AVFrame *in, *out; | 83 | AVFrame *in, *out; |
| 83 | } ThreadData; | 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 | AudioDynamicEqualizerContext *s = ctx->priv; | 93 | AudioDynamicEqualizerContext *s = ctx->priv; |
| 88 | ThreadData *td = arg; | 94 | const double sample_rate = ctx->inputs[0]->sample_rate; |
| 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; | ||
| 95 | const double dfrequency = fmin(s->dfrequency, sample_rate * 0.5); | 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 | const double dg = tan(M_PI * dfrequency / sample_rate); | 96 | const double dg = tan(M_PI * dfrequency / sample_rate); |
| 105 | const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs; | 97 | const double dqfactor = s->dqfactor; |
| 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; | ||
| 109 | const int dftype = s->dftype; | 98 | const int dftype = s->dftype; |
| 110 | const int tftype = s->tftype; | 99 | double *da = s->da; |
| 111 | const int mode = s->mode; | 100 | double *dm = s->dm; |
| 112 | double k, da[3], dm[3]; | 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 | switch (dftype) { | 106 | switch (dftype) { |
| 115 | case 0: | 107 | case 0: |
| @@ -158,6 +150,35 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 42 unmodified lines | |||
| 158 | break; | 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 | for (int ch = start; ch < end; ch++) { | 182 | for (int ch = start; ch < end; ch++) { |
| 162 | const double *src = (const double *)in->extended_data[ch]; | 183 | const double *src = (const double *)in->extended_data[ch]; |
| 163 | double *dst = (double *)out->extended_data[ch]; | 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 | return 0; | 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 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 278 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| 263 | { | 279 | { |
| 264 | AVFilterContext *ctx = inlink->dst; | 280 | AVFilterContext *ctx = inlink->dst; |
| 265 | AVFilterLink *outlink = ctx->outputs[0]; | 281 | AVFilterLink *outlink = ctx->outputs[0]; |
| 266 | AudioDynamicEqualizerContext *s = ctx->priv; | ||
| 267 | ThreadData td; | 282 | ThreadData td; |
| 268 | AVFrame *out; | 283 | AVFrame *out; |
| 269 | 284 | ||
| @@ -278,11 +293,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 8 unmodified lines | |||
| 278 | av_frame_copy_props(out, in); | 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 | td.in = in; | 296 | td.in = in; |
| 285 | td.out = out; | 297 | td.out = out; |
| 298 | filter_prepare(ctx); | ||
| 286 | ff_filter_execute(ctx, filter_channels, &td, NULL, | 299 | ff_filter_execute(ctx, filter_channels, &td, NULL, |
| 287 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); | 300 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); |
| 288 | 301 | ||