Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -58,6 +58,8 @@ typedef struct AudioCrossoverContext { · 57 unmodified lines | ||
| 58 | 58 | |
| 59 | 59 | int order; |
| 60 | 60 | int filter_count; |
| 61 | + int first_order; | |
| 62 | + int ap_filter_count; | |
| 61 | 63 | int nb_splits; |
| 62 | 64 | float *splits; |
| 63 | 65 | |
| @@ -205,6 +207,18 @@ static void set_ap(BiquadContext *b, double fc, double q, double sr) · 141 unmodified lines | ||
| 205 | 207 | b->a2 = -a2 / a0; |
| 206 | 208 | } |
| 207 | 209 | |
| 210 | +static void set_ap1(BiquadContext *b, double fc, double sr) | |
| 211 | +{ | |
| 212 | + double omega = M_PI * fc / sr; | |
| 213 | + double K = tan(omega); | |
| 214 | + | |
| 215 | + b->a1 = -(1. - K) / (1. + K); | |
| 216 | + b->a2 = 0.; | |
| 217 | + b->b0 = -b->a1; | |
| 218 | + b->b1 = 1.; | |
| 219 | + b->b2 = 0.; | |
| 220 | +} | |
| 221 | + | |
| 208 | 222 | static void calc_q_factors(int order, double *q) |
| 209 | 223 | { |
| 210 | 224 | double n = order / 2.; |
| @@ -218,7 +232,6 @@ static int config_input(AVFilterLink *inlink) · 7 unmodified lines | ||
| 218 | 232 | AVFilterContext *ctx = inlink->dst; |
| 219 | 233 | AudioCrossoverContext *s = ctx->priv; |
| 220 | 234 | int sample_rate = inlink->sample_rate; |
| 221 | − int first_order; | |
| 222 | 235 | double q[16]; |
| 223 | 236 | |
| 224 | 237 | s->xover = av_calloc(inlink->channels, sizeof(*s->xover)); |
| @@ -227,21 +240,29 @@ static int config_input(AVFilterLink *inlink) · 2 unmodified lines | ||
| 227 | 240 | |
| 228 | 241 | s->order = (s->order_opt + 1) * 2; |
| 229 | 242 | s->filter_count = s->order / 2; |
| 230 | − first_order = s->filter_count & 1; | |
| 243 | + s->first_order = s->filter_count & 1; | |
| 244 | + s->ap_filter_count = s->filter_count / 2 + s->first_order; | |
| 231 | 245 | calc_q_factors(s->order, q); |
| 232 | 246 | |
| 233 | 247 | for (int ch = 0; ch < inlink->channels; ch++) { |
| 234 | 248 | for (int band = 0; band <= s->nb_splits; band++) { |
| 235 | − if (first_order) { | |
| 249 | + if (s->first_order) { | |
| 236 | 250 | set_lp(&s->xover[ch].lp[band][0], s->splits[band], 0.5, sample_rate); |
| 237 | 251 | set_hp(&s->xover[ch].hp[band][0], s->splits[band], 0.5, sample_rate); |
| 238 | 252 | } |
| 239 | 253 | |
| 240 | − for (int n = first_order; n < s->filter_count; n++) { | |
| 241 | − const int idx = s->filter_count / 2 - ((n + first_order) / 2 - first_order) - 1; | |
| 254 | + for (int n = s->first_order; n < s->filter_count; n++) { | |
| 255 | + const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1; | |
| 242 | 256 | |
| 243 | 257 | set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate); |
| 244 | 258 | set_hp(&s->xover[ch].hp[band][n], s->splits[band], q[idx], sample_rate); |
| 259 | + } | |
| 260 | + | |
| 261 | + for (int x = 0; x <= s->nb_splits && s->first_order; x++) | |
| 262 | + set_ap1(&s->xover[ch].ap[x][band][0], s->splits[band], sample_rate); | |
| 263 | + | |
| 264 | + for (int n = s->first_order; n < s->ap_filter_count; n++) { | |
| 265 | + const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1); | |
| 245 | 266 | |
| 246 | 267 | for (int x = 0; x <= s->nb_splits; x++) |
| 247 | 268 | set_ap(&s->xover[ch].ap[x][band][n], s->splits[band], q[idx], sample_rate); |
| @@ -340,17 +361,25 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo · 92 unmodified lines | ||
| 340 | 361 | } |
| 341 | 362 | |
| 342 | 363 | for (int aband = band + 1; aband < ctx->nb_outputs; aband++) { |
| 343 | − for (int f = 0; f < s->filter_count / 2; f++) { | |
| 364 | + if (s->first_order) { | |
| 365 | + const double *src = (const double *)frames[band]->extended_data[ch]; | |
| 366 | + double *dst = (double *)frames[band]->extended_data[ch]; | |
| 367 | + BiquadContext *ap = &xover->ap[band][aband][0]; | |
| 368 | + | |
| 369 | + biquad_process(ap, dst, src, nb_samples); | |
| 370 | + } | |
| 371 | + | |
| 372 | + for (int f = s->first_order; f < s->ap_filter_count; f++) { | |
| 344 | 373 | const double *src = (const double *)frames[band]->extended_data[ch]; |
| 345 | 374 | double *dst = (double *)frames[band]->extended_data[ch]; |
| 346 | − BiquadContext *ap = &xover->ap[band][aband][f * 2 + (s->filter_count & 1)]; | |
| 375 | + BiquadContext *ap = &xover->ap[band][aband][f]; | |
| 347 | 376 | |
| 348 | 377 | biquad_process(ap, dst, src, nb_samples); |
| 349 | 378 | } |
| 350 | 379 | } |
| 351 | 380 | } |
| 352 | 381 | |
| 353 | − for (int band = 0; band < ctx->nb_outputs && (s->filter_count & 1); band++) { | |
| 382 | + for (int band = 0; band < ctx->nb_outputs && s->first_order; band++) { | |
| 354 | 383 | if (band & 1) { |
| 355 | 384 | double *dst = (double *)frames[band]->extended_data[ch]; |
| 356 | 385 | |