| @@ -32,6 +32,7 @@ typedef struct ASuperCutContext { · 31 unmodified lines |
| 32 | 32 | const AVClass *class; |
| 33 | 33 | |
| 34 | 34 | double cutoff; |
| 35 | + double level; |
| 35 | 36 | int order; |
| 36 | 37 | |
| 37 | 38 | int filter_count; |
| @@ -95,27 +96,52 @@ static int get_coeffs(AVFilterContext *ctx) · 57 unmodified lines |
| 95 | 96 | s->filter_count = s->order / 2 + (s->order & 1); |
| 96 | 97 | calc_q_factors(s->order, q); |
| 97 | 98 | |
| 98 | | − if (s->order & 1) { |
| 99 | | − BiquadCoeffs *coeffs = &s->coeffs[0]; |
| 100 | | − double omega = 2. * tan(M_PI * w0); |
| 99 | + if (!strcmp(ctx->filter->name, "asubcut")) { |
| 100 | + if (s->order & 1) { |
| 101 | + BiquadCoeffs *coeffs = &s->coeffs[0]; |
| 102 | + double omega = 2. * tan(M_PI * w0); |
| 101 | 103 | |
| 102 | | − coeffs->b0 = omega / (2. + omega); |
| 103 | | − coeffs->b1 = coeffs->b0; |
| 104 | | − coeffs->b2 = 0.; |
| 105 | | − coeffs->a1 = -(omega - 2.) / (2. + omega); |
| 106 | | − coeffs->a2 = 0.; |
| 107 | | − } |
| 104 | + coeffs->b0 = 2. / (2. + omega); |
| 105 | + coeffs->b1 = -coeffs->b0; |
| 106 | + coeffs->b2 = 0.; |
| 107 | + coeffs->a1 = -(omega - 2.) / (2. + omega); |
| 108 | + coeffs->a2 = 0.; |
| 109 | + } |
| 110 | + |
| 111 | + for (int b = (s->order & 1); b < s->filter_count; b++) { |
| 112 | + BiquadCoeffs *coeffs = &s->coeffs[b]; |
| 113 | + const int idx = b - (s->order & 1); |
| 114 | + double norm = 1.0 / (1.0 + K / q[idx] + K * K); |
| 108 | 115 | |
| 109 | | − for (int b = (s->order & 1); b < s->filter_count; b++) { |
| 110 | | − BiquadCoeffs *coeffs = &s->coeffs[b]; |
| 111 | | − const int idx = b - (s->order & 1); |
| 112 | | − double norm = 1.0 / (1.0 + K / q[idx] + K * K); |
| 116 | + coeffs->b0 = norm; |
| 117 | + coeffs->b1 = -2.0 * coeffs->b0; |
| 118 | + coeffs->b2 = coeffs->b0; |
| 119 | + coeffs->a1 = -2.0 * (K * K - 1.0) * norm; |
| 120 | + coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm; |
| 121 | + } |
| 122 | + } else { |
| 123 | + if (s->order & 1) { |
| 124 | + BiquadCoeffs *coeffs = &s->coeffs[0]; |
| 125 | + double omega = 2. * tan(M_PI * w0); |
| 126 | + |
| 127 | + coeffs->b0 = omega / (2. + omega); |
| 128 | + coeffs->b1 = coeffs->b0; |
| 129 | + coeffs->b2 = 0.; |
| 130 | + coeffs->a1 = -(omega - 2.) / (2. + omega); |
| 131 | + coeffs->a2 = 0.; |
| 132 | + } |
| 113 | 133 | |
| 114 | | − coeffs->b0 = K * K * norm; |
| 115 | | − coeffs->b1 = 2.0 * coeffs->b0; |
| 116 | | − coeffs->b2 = coeffs->b0; |
| 117 | | − coeffs->a1 = -2.0 * (K * K - 1.0) * norm; |
| 118 | | − coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm; |
| 134 | + for (int b = (s->order & 1); b < s->filter_count; b++) { |
| 135 | + BiquadCoeffs *coeffs = &s->coeffs[b]; |
| 136 | + const int idx = b - (s->order & 1); |
| 137 | + double norm = 1.0 / (1.0 + K / q[idx] + K * K); |
| 138 | + |
| 139 | + coeffs->b0 = K * K * norm; |
| 140 | + coeffs->b1 = 2.0 * coeffs->b0; |
| 141 | + coeffs->b2 = coeffs->b0; |
| 142 | + coeffs->a1 = -2.0 * (K * K - 1.0) * norm; |
| 143 | + coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm; |
| 144 | + } |
| 119 | 145 | } |
| 120 | 146 | |
| 121 | 147 | return 0; |
| @@ -135,6 +161,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \ · 13 unmodified lines |
| 135 | 161 | AVFrame *in = td->in; \ |
| 136 | 162 | const int start = (in->channels * jobnr) / nb_jobs; \ |
| 137 | 163 | const int end = (in->channels * (jobnr+1)) / nb_jobs; \ |
| 164 | + const double level = s->level; \ |
| 138 | 165 | \ |
| 139 | 166 | for (int ch = start; ch < end; ch++) { \ |
| 140 | 167 | const type *src = (const type *)in->extended_data[ch]; \ |
| @@ -150,7 +177,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \ · 9 unmodified lines |
| 150 | 177 | type *w = ((type *)s->w->extended_data[ch]) + b * 2; \ |
| 151 | 178 | \ |
| 152 | 179 | for (int n = 0; n < in->nb_samples; n++) { \ |
| 153 | | − type sin = b ? dst[n] : src[n]; \ |
| 180 | + type sin = b ? dst[n] : src[n] * level; \ |
| 154 | 181 | type sout = sin * b0 + w[0]; \ |
| 155 | 182 | \ |
| 156 | 183 | w[0] = b1 * sin + w[1] + a1 * sout; \ |
| @@ -240,6 +267,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 83 unmodified lines |
| 240 | 267 | static const AVOption asupercut_options[] = { |
| 241 | 268 | { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20000}, 20000, 192000, FLAGS }, |
| 242 | 269 | { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=10}, 3, 20, FLAGS }, |
| 270 | + { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 1., FLAGS }, |
| 243 | 271 | { NULL } |
| 244 | 272 | }; |
| 245 | 273 | |
| @@ -276,3 +304,26 @@ AVFilter ff_af_asupercut = { · 30 unmodified lines |
| 276 | 304 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | |
| 277 | 305 | AVFILTER_FLAG_SLICE_THREADS, |
| 278 | 306 | }; |
| 307 | + |
| 308 | +static const AVOption asubcut_options[] = { |
| 309 | + { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 2, 200, FLAGS }, |
| 310 | + { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=10}, 3, 20, FLAGS }, |
| 311 | + { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 1., FLAGS }, |
| 312 | + { NULL } |
| 313 | +}; |
| 314 | + |
| 315 | +AVFILTER_DEFINE_CLASS(asubcut); |
| 316 | + |
| 317 | +AVFilter ff_af_asubcut = { |
| 318 | + .name = "asubcut", |
| 319 | + .description = NULL_IF_CONFIG_SMALL("Cut subwoofer frequencies."), |
| 320 | + .query_formats = query_formats, |
| 321 | + .priv_size = sizeof(ASuperCutContext), |
| 322 | + .priv_class = &asubcut_class, |
| 323 | + .uninit = uninit, |
| 324 | + .inputs = inputs, |
| 325 | + .outputs = outputs, |
| 326 | + .process_command = process_command, |
| 327 | + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | |
| 328 | + AVFILTER_FLAG_SLICE_THREADS, |
| 329 | +}; |