Split biquad coefficients from biquad state.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -39,9 +39,12 @@ · 38 unmodified lines | ||
| 39 | 39 | #define MAX_SPLITS 16 |
| 40 | 40 | #define MAX_BANDS MAX_SPLITS + 1 |
| 41 | 41 | |
| 42 | −typedef struct BiquadContext { | |
| 42 | +typedef struct BiquadCoeffs { | |
| 43 | 43 | double b0, b1, b2; |
| 44 | 44 | double a1, a2; |
| 45 | +} BiquadCoeffs; | |
| 46 | + | |
| 47 | +typedef struct BiquadContext { | |
| 45 | 48 | double z1, z2; |
| 46 | 49 | } BiquadContext; |
| 47 | 50 | |
| @@ -65,6 +68,10 @@ typedef struct AudioCrossoverContext { · 17 unmodified lines | ||
| 65 | 68 | int nb_splits; |
| 66 | 69 | float *splits; |
| 67 | 70 | |
| 71 | + BiquadCoeffs lp[MAX_BANDS][20]; | |
| 72 | + BiquadCoeffs hp[MAX_BANDS][20]; | |
| 73 | + BiquadCoeffs ap[MAX_BANDS][20]; | |
| 74 | + | |
| 68 | 75 | CrossoverChannel *xover; |
| 69 | 76 | |
| 70 | 77 | AVFrame *input_frame; |
| @@ -158,7 +165,7 @@ static av_cold int init(AVFilterContext *ctx) · 87 unmodified lines | ||
| 158 | 165 | return ret; |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | −static void set_lp(BiquadContext *b, double fc, double q, double sr) | |
| 168 | +static void set_lp(BiquadCoeffs *b, double fc, double q, double sr) | |
| 162 | 169 | { |
| 163 | 170 | double omega = M_PI * fc / sr; |
| 164 | 171 | double cosine = cos(omega); |
| @@ -178,7 +185,7 @@ static void set_lp(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines | ||
| 178 | 185 | b->a2 = -a2 / a0; |
| 179 | 186 | } |
| 180 | 187 | |
| 181 | −static void set_hp(BiquadContext *b, double fc, double q, double sr) | |
| 188 | +static void set_hp(BiquadCoeffs *b, double fc, double q, double sr) | |
| 182 | 189 | { |
| 183 | 190 | double omega = M_PI * fc / sr; |
| 184 | 191 | double cosine = cos(omega); |
| @@ -198,7 +205,7 @@ static void set_hp(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines | ||
| 198 | 205 | b->a2 = -a2 / a0; |
| 199 | 206 | } |
| 200 | 207 | |
| 201 | −static void set_ap(BiquadContext *b, double fc, double q, double sr) | |
| 208 | +static void set_ap(BiquadCoeffs *b, double fc, double q, double sr) | |
| 202 | 209 | { |
| 203 | 210 | double omega = M_PI * fc / sr; |
| 204 | 211 | double cosine = cos(omega); |
| @@ -218,7 +225,7 @@ static void set_ap(BiquadContext *b, double fc, double q, double sr) · 13 unmodified lines | ||
| 218 | 225 | b->a2 = -a2 / a0; |
| 219 | 226 | } |
| 220 | 227 | |
| 221 | −static void set_ap1(BiquadContext *b, double fc, double sr) | |
| 228 | +static void set_ap1(BiquadCoeffs *b, double fc, double sr) | |
| 222 | 229 | { |
| 223 | 230 | double omega = M_PI * fc / sr; |
| 224 | 231 | |
| @@ -268,15 +275,16 @@ static int query_formats(AVFilterContext *ctx) · 43 unmodified lines | ||
| 268 | 275 | } |
| 269 | 276 | |
| 270 | 277 | #define BIQUAD_PROCESS(name, type) \ |
| 271 | −static void biquad_process_## name(BiquadContext *b, \ | |
| 278 | +static void biquad_process_## name(const BiquadCoeffs *const c,\ | |
| 279 | + BiquadContext *b, \ | |
| 272 | 280 | type *dst, const type *src, \ |
| 273 | 281 | int nb_samples) \ |
| 274 | 282 | { \ |
| 275 | − const type b0 = b->b0; \ | |
| 276 | − const type b1 = b->b1; \ | |
| 277 | − const type b2 = b->b2; \ | |
| 278 | − const type a1 = b->a1; \ | |
| 279 | − const type a2 = b->a2; \ | |
| 283 | + const type b0 = c->b0; \ | |
| 284 | + const type b1 = c->b1; \ | |
| 285 | + const type b2 = c->b2; \ | |
| 286 | + const type a1 = c->a1; \ | |
| 287 | + const type a2 = c->a2; \ | |
| 280 | 288 | type z1 = b->z1; \ |
| 281 | 289 | type z2 = b->z2; \ |
| 282 | 290 | \ |
| @@ -321,16 +329,18 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 38 unmodified lines | ||
| 321 | 329 | type *dst = (type *)frames[band + 1]->extended_data[ch]; \ |
| 322 | 330 | const type *hsrc = f == 0 ? prv : dst; \ |
| 323 | 331 | BiquadContext *hp = &xover->hp[band][f]; \ |
| 332 | + BiquadCoeffs *hpc = &s->hp[band][f]; \ | |
| 324 | 333 | \ |
| 325 | − biquad_process_## name(hp, dst, hsrc, nb_samples); \ | |
| 334 | + biquad_process_## name(hpc, hp, dst, hsrc, nb_samples); \ | |
| 326 | 335 | } \ |
| 327 | 336 | \ |
| 328 | 337 | for (int f = 0; band + 1 < ctx->nb_outputs && f < s->filter_count; f++) { \ |
| 329 | 338 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 330 | 339 | const type *lsrc = dst; \ |
| 331 | 340 | BiquadContext *lp = &xover->lp[band][f]; \ |
| 341 | + BiquadCoeffs *lpc = &s->lp[band][f]; \ | |
| 332 | 342 | \ |
| 333 | − biquad_process_## name(lp, dst, lsrc, nb_samples); \ | |
| 343 | + biquad_process_## name(lpc, lp, dst, lsrc, nb_samples); \ | |
| 334 | 344 | } \ |
| 335 | 345 | \ |
| 336 | 346 | for (int aband = band + 1; aband + 1 < ctx->nb_outputs; aband++) { \ |
| @@ -338,16 +348,18 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i · 1 unmodified line | ||
| 338 | 348 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 339 | 349 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 340 | 350 | BiquadContext *ap = &xover->ap[band][aband][0]; \ |
| 351 | + BiquadCoeffs *apc = &s->ap[aband][0]; \ | |
| 341 | 352 | \ |
| 342 | − biquad_process_## name(ap, dst, asrc, nb_samples); \ | |
| 353 | + biquad_process_## name(apc, ap, dst, asrc, nb_samples); \ | |
| 343 | 354 | } \ |
| 344 | 355 | \ |
| 345 | 356 | for (int f = s->first_order; f < s->ap_filter_count; f++) { \ |
| 346 | 357 | const type *asrc = (const type *)frames[band]->extended_data[ch]; \ |
| 347 | 358 | type *dst = (type *)frames[band]->extended_data[ch]; \ |
| 348 | 359 | BiquadContext *ap = &xover->ap[band][aband][f]; \ |
| 360 | + BiquadCoeffs *apc = &s->ap[aband][f]; \ | |
| 349 | 361 | \ |
| 350 | − biquad_process_## name(ap, dst, asrc, nb_samples); \ | |
| 362 | + biquad_process_## name(apc, ap, dst, asrc, nb_samples); \ | |
| 351 | 363 | } \ |
| 352 | 364 | } \ |
| 353 | 365 | } \ |
| @@ -385,29 +397,26 @@ static int config_input(AVFilterLink *inlink) · 31 unmodified lines | ||
| 385 | 397 | s->ap_filter_count = s->filter_count / 2 + s->first_order; |
| 386 | 398 | calc_q_factors(s->order, q); |
| 387 | 399 | |
| 388 | − for (int ch = 0; ch < inlink->channels; ch++) { | |
| 389 | − for (int band = 0; band <= s->nb_splits; band++) { | |
| 390 | − if (s->first_order) { | |
| 391 | − set_lp(&s->xover[ch].lp[band][0], s->splits[band], 0.5, sample_rate); | |
| 392 | − set_hp(&s->xover[ch].hp[band][0], s->splits[band], 0.5, sample_rate); | |
| 393 | − } | |
| 400 | + for (int band = 0; band <= s->nb_splits; band++) { | |
| 401 | + if (s->first_order) { | |
| 402 | + set_lp(&s->lp[band][0], s->splits[band], 0.5, sample_rate); | |
| 403 | + set_hp(&s->hp[band][0], s->splits[band], 0.5, sample_rate); | |
| 404 | + } | |
| 394 | 405 | |
| 395 | − for (int n = s->first_order; n < s->filter_count; n++) { | |
| 396 | − const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1; | |
| 406 | + for (int n = s->first_order; n < s->filter_count; n++) { | |
| 407 | + const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1; | |
| 397 | 408 | |
| 398 | − set_lp(&s->xover[ch].lp[band][n], s->splits[band], q[idx], sample_rate); | |
| 399 | − set_hp(&s->xover[ch].hp[band][n], s->splits[band], q[idx], sample_rate); | |
| 400 | − } | |
| 409 | + set_lp(&s->lp[band][n], s->splits[band], q[idx], sample_rate); | |
| 410 | + set_hp(&s->hp[band][n], s->splits[band], q[idx], sample_rate); | |
| 411 | + } | |
| 401 | 412 | |
| 402 | − for (int x = 0; x <= s->nb_splits && s->first_order; x++) | |
| 403 | − set_ap1(&s->xover[ch].ap[x][band][0], s->splits[band], sample_rate); | |
| 413 | + if (s->first_order) | |
| 414 | + set_ap1(&s->ap[band][0], s->splits[band], sample_rate); | |
| 404 | 415 | |
| 405 | − for (int n = s->first_order; n < s->ap_filter_count; n++) { | |
| 406 | − const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1); | |
| 416 | + for (int n = s->first_order; n < s->ap_filter_count; n++) { | |
| 417 | + const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1); | |
| 407 | 418 | |
| 408 | − for (int x = 0; x <= s->nb_splits; x++) | |
| 409 | − set_ap(&s->xover[ch].ap[x][band][n], s->splits[band], q[idx], sample_rate); | |
| 410 | − } | |
| 419 | + set_ap(&s->ap[band][n], s->splits[band], q[idx], sample_rate); | |
| 411 | 420 | } |
| 412 | 421 | } |
| 413 | 422 | |