| @@ -54,6 +54,7 @@ typedef struct AudioCrossoverContext { · 53 unmodified lines |
| 54 | const AVClass *class; | 54 | const AVClass *class; |
| 55 | | 55 | |
| 56 | char *splits_str; | 56 | char *splits_str; |
| | 57 | char *gains_str; |
| 57 | int order_opt; | 58 | int order_opt; |
| 58 | float level_in; | 59 | float level_in; |
| 59 | | 60 | |
| @@ -64,6 +65,8 @@ typedef struct AudioCrossoverContext { · 4 unmodified lines |
| 64 | int nb_splits; | 65 | int nb_splits; |
| 65 | float splits[MAX_SPLITS]; | 66 | float splits[MAX_SPLITS]; |
| 66 | | 67 | |
| | 68 | float gains[MAX_BANDS]; |
| | 69 | |
| 67 | BiquadCoeffs lp[MAX_BANDS][20]; | 70 | BiquadCoeffs lp[MAX_BANDS][20]; |
| 68 | BiquadCoeffs hp[MAX_BANDS][20]; | 71 | BiquadCoeffs hp[MAX_BANDS][20]; |
| 69 | BiquadCoeffs ap[MAX_BANDS][20]; | 72 | BiquadCoeffs ap[MAX_BANDS][20]; |
| @@ -95,11 +98,47 @@ static const AVOption acrossover_options[] = { · 25 unmodified lines |
| 95 | { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" }, | 98 | { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" }, |
| 96 | { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" }, | 99 | { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" }, |
| 97 | { "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF }, | 100 | { "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF }, |
| | 101 | { "gain", "set output bands gain", OFFSET(gains_str), AV_OPT_TYPE_STRING, {.str="1.f"}, 0, 0, AF }, |
| 98 | { NULL } | 102 | { NULL } |
| 99 | }; | 103 | }; |
| 100 | | 104 | |
| 101 | AVFILTER_DEFINE_CLASS(acrossover); | 105 | AVFILTER_DEFINE_CLASS(acrossover); |
| 102 | | 106 | |
| | 107 | static int parse_gains(AVFilterContext *ctx) |
| | 108 | { |
| | 109 | AudioCrossoverContext *s = ctx->priv; |
| | 110 | char *p, *arg, *saveptr = NULL; |
| | 111 | int i, ret = 0; |
| | 112 | |
| | 113 | saveptr = NULL; |
| | 114 | p = s->gains_str; |
| | 115 | for (i = 0; i < MAX_BANDS; i++) { |
| | 116 | float gain; |
| | 117 | char c[3] = { 0 }; |
| | 118 | |
| | 119 | if (!(arg = av_strtok(p, " |", &saveptr))) |
| | 120 | break; |
| | 121 | |
| | 122 | p = NULL; |
| | 123 | |
| | 124 | if (av_sscanf(arg, "%f%2s", &gain, c) < 1) { |
| | 125 | av_log(ctx, AV_LOG_ERROR, "Invalid syntax for gain[%d].\n", i); |
| | 126 | ret = AVERROR(EINVAL); |
| | 127 | break; |
| | 128 | } |
| | 129 | |
| | 130 | if (c[0] == 'd' && c[1] == 'B') |
| | 131 | s->gains[i] = expf(gain * M_LN10 / 20.f); |
| | 132 | else |
| | 133 | s->gains[i] = gain; |
| | 134 | } |
| | 135 | |
| | 136 | for (; i < MAX_BANDS; i++) |
| | 137 | s->gains[i] = 1.f; |
| | 138 | |
| | 139 | return ret; |
| | 140 | } |
| | 141 | |
| 103 | static av_cold int init(AVFilterContext *ctx) | 142 | static av_cold int init(AVFilterContext *ctx) |
| 104 | { | 143 | { |
| 105 | AudioCrossoverContext *s = ctx->priv; | 144 | AudioCrossoverContext *s = ctx->priv; |
| @@ -138,6 +177,10 @@ static av_cold int init(AVFilterContext *ctx) · 32 unmodified lines |
| 138 | | 177 | |
| 139 | s->nb_splits = i; | 178 | s->nb_splits = i; |
| 140 | | 179 | |
| | 180 | ret = parse_gains(ctx); |
| | 181 | if (ret < 0) |
| | 182 | return ret; |
| | 183 | |
| 141 | for (i = 0; i <= s->nb_splits; i++) { | 184 | for (i = 0; i <= s->nb_splits; i++) { |
| 142 | AVFilterPad pad = { 0 }; | 185 | AVFilterPad pad = { 0 }; |
| 143 | char *name; | 186 | char *name; |
| @@ -349,6 +392,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 205 unmodified lines |
| 349 | const int end = (in->channels * (jobnr+1)) / nb_jobs; \ | 392 | const int end = (in->channels * (jobnr+1)) / nb_jobs; \ |
| 350 | const int nb_samples = in->nb_samples; \ | 393 | const int nb_samples = in->nb_samples; \ |
| 351 | const int nb_outs = ctx->nb_outputs; \ | 394 | const int nb_outs = ctx->nb_outputs; \ |
| | 395 | const int first_order = s->first_order; \ |
| 352 | \ | 396 | \ |
| 353 | for (int ch = start; ch < end; ch++) { \ | 397 | for (int ch = start; ch < end; ch++) { \ |
| 354 | const type *src = (const type *)in->extended_data[ch]; \ | 398 | const type *src = (const type *)in->extended_data[ch]; \ |
| @@ -378,7 +422,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 23 unmodified lines |
| 378 | } \ | 422 | } \ |
| 379 | \ | 423 | \ |
| 380 | for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \ | 424 | for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \ |
| 381 | if (s->first_order) { \ | 425 | if (first_order) { \ |
| 382 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ | 426 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 383 | type *dst = (type *)frames[band]->extended_data[ch]; \ | 427 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 384 | type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \ | 428 | type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \ |
| @@ -387,7 +431,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 2 unmodified lines |
| 387 | biquad_process_## name(apc, ap, dst, asrc, nb_samples); \ | 431 | biquad_process_## name(apc, ap, dst, asrc, nb_samples); \ |
| 388 | } \ | 432 | } \ |
| 389 | \ | 433 | \ |
| 390 | for (int f = s->first_order; f < s->ap_filter_count; f++) { \ | 434 | for (int f = first_order; f < s->ap_filter_count; f++) { \ |
| 391 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ | 435 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 392 | type *dst = (type *)frames[band]->extended_data[ch]; \ | 436 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 393 | type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\ | 437 | type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\ |
| @@ -398,12 +442,12 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 4 unmodified lines |
| 398 | } \ | 442 | } \ |
| 399 | } \ | 443 | } \ |
| 400 | \ | 444 | \ |
| 401 | for (int band = 0; band < nb_outs && s->first_order; band++) { \ | 445 | for (int band = 0; band < nb_outs; band++) { \ |
| 402 | if (band & 1) { \ | 446 | const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \ |
| 403 | type *dst = (type *)frames[band]->extended_data[ch]; \ | 447 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 404 | s->fdsp->vector_## ff ##mul_scalar(dst, dst, -one, \ | 448 | \ |
| 405 | FFALIGN(nb_samples, sizeof(type))); \ | 449 | s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \ |
| 406 | } \ | 450 | FFALIGN(nb_samples, sizeof(type))); \ |
| 407 | } \ | 451 | } \ |
| 408 | } \ | 452 | } \ |
| 409 | \ | 453 | \ |