| @@ -54,6 +54,7 @@ typedef struct AudioCrossoverContext { · 53 unmodified lines |
| 54 | 54 | const AVClass *class; |
| 55 | 55 | |
| 56 | 56 | char *splits_str; |
| 57 | + char *gains_str; |
| 57 | 58 | int order_opt; |
| 58 | 59 | float level_in; |
| 59 | 60 | |
| @@ -64,6 +65,8 @@ typedef struct AudioCrossoverContext { · 4 unmodified lines |
| 64 | 65 | int nb_splits; |
| 65 | 66 | float splits[MAX_SPLITS]; |
| 66 | 67 | |
| 68 | + float gains[MAX_BANDS]; |
| 69 | + |
| 67 | 70 | BiquadCoeffs lp[MAX_BANDS][20]; |
| 68 | 71 | BiquadCoeffs hp[MAX_BANDS][20]; |
| 69 | 72 | BiquadCoeffs ap[MAX_BANDS][20]; |
| @@ -95,11 +98,47 @@ static const AVOption acrossover_options[] = { · 25 unmodified lines |
| 95 | 98 | { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" }, |
| 96 | 99 | { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" }, |
| 97 | 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 | 102 | { NULL } |
| 99 | 103 | }; |
| 100 | 104 | |
| 101 | 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 | 142 | static av_cold int init(AVFilterContext *ctx) |
| 104 | 143 | { |
| 105 | 144 | AudioCrossoverContext *s = ctx->priv; |
| @@ -138,6 +177,10 @@ static av_cold int init(AVFilterContext *ctx) · 32 unmodified lines |
| 138 | 177 | |
| 139 | 178 | s->nb_splits = i; |
| 140 | 179 | |
| 180 | + ret = parse_gains(ctx); |
| 181 | + if (ret < 0) |
| 182 | + return ret; |
| 183 | + |
| 141 | 184 | for (i = 0; i <= s->nb_splits; i++) { |
| 142 | 185 | AVFilterPad pad = { 0 }; |
| 143 | 186 | char *name; |
| @@ -349,6 +392,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 205 unmodified lines |
| 349 | 392 | const int end = (in->channels * (jobnr+1)) / nb_jobs; \ |
| 350 | 393 | const int nb_samples = in->nb_samples; \ |
| 351 | 394 | const int nb_outs = ctx->nb_outputs; \ |
| 395 | + const int first_order = s->first_order; \ |
| 352 | 396 | \ |
| 353 | 397 | for (int ch = start; ch < end; ch++) { \ |
| 354 | 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 | 424 | for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \ |
| 381 | | − if (s->first_order) { \ |
| 425 | + if (first_order) { \ |
| 382 | 426 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 383 | 427 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 384 | 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 | 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 | 435 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 392 | 436 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 393 | 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++) { \ |
| 402 | | − if (band & 1) { \ |
| 403 | | − type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 404 | | − s->fdsp->vector_## ff ##mul_scalar(dst, dst, -one, \ |
| 405 | | − FFALIGN(nb_samples, sizeof(type))); \ |
| 406 | | − } \ |
| 445 | + for (int band = 0; band < nb_outs; band++) { \ |
| 446 | + const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \ |
| 447 | + type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 448 | + \ |
| 449 | + s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \ |
| 450 | + FFALIGN(nb_samples, sizeof(type))); \ |
| 407 | 451 | } \ |
| 408 | 452 | } \ |
| 409 | 453 | \ |