Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -109,14 +109,6 @@ enum TransformType { · 108 unmodified lines | ||
| 109 | 109 | NB_TTYPE, |
| 110 | 110 | }; |
| 111 | 111 | |
| 112 | −typedef struct ChanCache { | |
| 113 | − double i1, i2; | |
| 114 | − double o1, o2; | |
| 115 | − double ri1, ri2; | |
| 116 | − double ro1, ro2; | |
| 117 | − int clippings; | |
| 118 | −} ChanCache; | |
| 119 | − | |
| 120 | 112 | typedef struct BiquadsContext { |
| 121 | 113 | const AVClass *class; |
| 122 | 114 | |
| @@ -139,24 +131,26 @@ typedef struct BiquadsContext { · 16 unmodified lines | ||
| 139 | 131 | int normalize; |
| 140 | 132 | int order; |
| 141 | 133 | |
| 142 | − double a0, a1, a2; | |
| 143 | − double b0, b1, b2; | |
| 134 | + double a_double[3]; | |
| 135 | + double b_double[3]; | |
| 136 | + | |
| 137 | + float a_float[3]; | |
| 138 | + float b_float[3]; | |
| 144 | 139 | |
| 145 | − double oa0, oa1, oa2; | |
| 146 | − double ob0, ob1, ob2; | |
| 140 | + double oa[3]; | |
| 141 | + double ob[3]; | |
| 147 | 142 | |
| 148 | 143 | AVFrame *block[3]; |
| 149 | 144 | |
| 150 | − ChanCache *cache; | |
| 145 | + int *clip; | |
| 146 | + AVFrame *cache[2]; | |
| 151 | 147 | int block_align; |
| 152 | 148 | |
| 153 | 149 | int64_t pts; |
| 154 | 150 | int nb_samples; |
| 155 | 151 | |
| 156 | 152 | void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len, |
| 157 | − double *i1, double *i2, double *o1, double *o2, | |
| 158 | − double b0, double b1, double b2, double a0, double a1, double a2, int *clippings, | |
| 159 | − int disabled); | |
| 153 | + void *cache, int *clip, int disabled); | |
| 160 | 154 | } BiquadsContext; |
| 161 | 155 | |
| 162 | 156 | static int query_formats(AVFilterContext *ctx) |
| @@ -202,27 +196,26 @@ static int query_formats(AVFilterContext *ctx) · 39 unmodified lines | ||
| 202 | 196 | return ff_set_common_all_samplerates(ctx); |
| 203 | 197 | } |
| 204 | 198 | |
| 205 | −#define BIQUAD_FILTER(name, type, min, max, need_clipping) \ | |
| 199 | +#define BIQUAD_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 206 | 200 | static void biquad_## name (BiquadsContext *s, \ |
| 207 | 201 | const void *input, void *output, int len, \ |
| 208 | − double *in1, double *in2, \ | |
| 209 | − double *out1, double *out2, \ | |
| 210 | − double b0, double b1, double b2, \ | |
| 211 | − double a0, double a1, double a2, int *clippings, \ | |
| 212 | − int disabled) \ | |
| 202 | + void *cache, int *clippings, int disabled) \ | |
| 213 | 203 | { \ |
| 214 | 204 | const type *ibuf = input; \ |
| 215 | 205 | type *obuf = output; \ |
| 216 | − double i1 = *in1; \ | |
| 217 | − double i2 = *in2; \ | |
| 218 | − double o1 = *out1; \ | |
| 219 | − double o2 = *out2; \ | |
| 220 | − double wet = s->mix; \ | |
| 221 | − double dry = 1. - wet; \ | |
| 222 | − double out; \ | |
| 206 | + ftype *fcache = cache; \ | |
| 207 | + ftype i1 = fcache[0], i2 = fcache[1], o1 = fcache[2], o2 = fcache[3]; \ | |
| 208 | + ftype *a = s->a_##ftype; \ | |
| 209 | + ftype *b = s->b_##ftype; \ | |
| 210 | + ftype a1 = -a[1]; \ | |
| 211 | + ftype a2 = -a[2]; \ | |
| 212 | + ftype b0 = b[0]; \ | |
| 213 | + ftype b1 = b[1]; \ | |
| 214 | + ftype b2 = b[2]; \ | |
| 215 | + ftype wet = s->mix; \ | |
| 216 | + ftype dry = 1. - wet; \ | |
| 217 | + ftype out; \ | |
| 223 | 218 | int i; \ |
| 224 | − a1 = -a1; \ | |
| 225 | − a2 = -a2; \ | |
| 226 | 219 | \ |
| 227 | 220 | for (i = 0; i+1 < len; i++) { \ |
| 228 | 221 | o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \ |
| @@ -256,7 +249,7 @@ static void biquad_## name (BiquadsContext *s, \ · 27 unmodified lines | ||
| 256 | 249 | } \ |
| 257 | 250 | } \ |
| 258 | 251 | if (i < len) { \ |
| 259 | − double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ | |
| 252 | + ftype o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ | |
| 260 | 253 | i2 = i1; \ |
| 261 | 254 | i1 = ibuf[i]; \ |
| 262 | 255 | o2 = o1; \ |
| @@ -274,36 +267,37 @@ static void biquad_## name (BiquadsContext *s, \ · 11 unmodified lines | ||
| 274 | 267 | obuf[i] = out; \ |
| 275 | 268 | } \ |
| 276 | 269 | } \ |
| 277 | − *in1 = i1; \ | |
| 278 | − *in2 = i2; \ | |
| 279 | − *out1 = o1; \ | |
| 280 | − *out2 = o2; \ | |
| 270 | + fcache[0] = i1; \ | |
| 271 | + fcache[1] = i2; \ | |
| 272 | + fcache[2] = o1; \ | |
| 273 | + fcache[3] = o2; \ | |
| 281 | 274 | } |
| 282 | 275 | |
| 283 | −BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 284 | −BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 285 | −BIQUAD_FILTER(flt, float, -1., 1., 0) | |
| 286 | −BIQUAD_FILTER(dbl, double, -1., 1., 0) | |
| 276 | +BIQUAD_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 277 | +BIQUAD_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 278 | +BIQUAD_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 279 | +BIQUAD_FILTER(dbl, double, double, -1., 1., 0) | |
| 287 | 280 | |
| 288 | −#define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \ | |
| 281 | +#define BIQUAD_DII_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 289 | 282 | static void biquad_dii_## name (BiquadsContext *s, \ |
| 290 | 283 | const void *input, void *output, int len, \ |
| 291 | − double *z1, double *z2, \ | |
| 292 | − double *unused1, double *unused2, \ | |
| 293 | − double b0, double b1, double b2, \ | |
| 294 | − double a0, double a1, double a2, int *clippings, \ | |
| 295 | − int disabled) \ | |
| 284 | + void *cache, int *clippings, int disabled) \ | |
| 296 | 285 | { \ |
| 297 | 286 | const type *ibuf = input; \ |
| 298 | 287 | type *obuf = output; \ |
| 299 | − double w1 = *z1; \ | |
| 300 | − double w2 = *z2; \ | |
| 301 | − double wet = s->mix; \ | |
| 302 | − double dry = 1. - wet; \ | |
| 303 | − double in, out, w0; \ | |
| 304 | − \ | |
| 305 | − a1 = -a1; \ | |
| 306 | − a2 = -a2; \ | |
| 288 | + ftype *fcache = cache; \ | |
| 289 | + ftype *a = s->a_##ftype; \ | |
| 290 | + ftype *b = s->b_##ftype; \ | |
| 291 | + ftype a1 = -a[1]; \ | |
| 292 | + ftype a2 = -a[2]; \ | |
| 293 | + ftype b0 = b[0]; \ | |
| 294 | + ftype b1 = b[1]; \ | |
| 295 | + ftype b2 = b[2]; \ | |
| 296 | + ftype w1 = fcache[0]; \ | |
| 297 | + ftype w2 = fcache[1]; \ | |
| 298 | + ftype wet = s->mix; \ | |
| 299 | + ftype dry = 1. - wet; \ | |
| 300 | + ftype in, out, w0; \ | |
| 307 | 301 | \ |
| 308 | 302 | for (int i = 0; i < len; i++) { \ |
| 309 | 303 | in = ibuf[i]; \ |
| @@ -324,39 +318,40 @@ static void biquad_dii_## name (BiquadsContext *s, \ · 14 unmodified lines | ||
| 324 | 318 | obuf[i] = out; \ |
| 325 | 319 | } \ |
| 326 | 320 | } \ |
| 327 | − *z1 = w1; \ | |
| 328 | − *z2 = w2; \ | |
| 321 | + fcache[0] = w1; \ | |
| 322 | + fcache[1] = w2; \ | |
| 329 | 323 | } |
| 330 | 324 | |
| 331 | −BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 332 | −BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 333 | −BIQUAD_DII_FILTER(flt, float, -1., 1., 0) | |
| 334 | −BIQUAD_DII_FILTER(dbl, double, -1., 1., 0) | |
| 325 | +BIQUAD_DII_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 326 | +BIQUAD_DII_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 327 | +BIQUAD_DII_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 328 | +BIQUAD_DII_FILTER(dbl, double, double, -1., 1., 0) | |
| 335 | 329 | |
| 336 | −#define BIQUAD_TDI_FILTER(name, type, min, max, need_clipping) \ | |
| 330 | +#define BIQUAD_TDI_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 337 | 331 | static void biquad_tdi_## name (BiquadsContext *s, \ |
| 338 | 332 | const void *input, void *output, int len, \ |
| 339 | − double *z1, double *z2, \ | |
| 340 | − double *z3, double *z4, \ | |
| 341 | − double b0, double b1, double b2, \ | |
| 342 | − double a0, double a1, double a2, int *clippings, \ | |
| 343 | − int disabled) \ | |
| 333 | + void *cache, int *clippings, int disabled) \ | |
| 344 | 334 | { \ |
| 345 | 335 | const type *ibuf = input; \ |
| 346 | 336 | type *obuf = output; \ |
| 347 | − double s1 = *z1; \ | |
| 348 | − double s2 = *z2; \ | |
| 349 | − double s3 = *z3; \ | |
| 350 | − double s4 = *z4; \ | |
| 351 | − double wet = s->mix; \ | |
| 352 | − double dry = 1. - wet; \ | |
| 353 | − double in, out; \ | |
| 354 | − \ | |
| 355 | − a1 = -a1; \ | |
| 356 | − a2 = -a2; \ | |
| 337 | + ftype *fcache = cache; \ | |
| 338 | + ftype *a = s->a_##ftype; \ | |
| 339 | + ftype *b = s->b_##ftype; \ | |
| 340 | + ftype a1 = -a[1]; \ | |
| 341 | + ftype a2 = -a[2]; \ | |
| 342 | + ftype b0 = b[0]; \ | |
| 343 | + ftype b1 = b[1]; \ | |
| 344 | + ftype b2 = b[2]; \ | |
| 345 | + ftype s1 = fcache[0]; \ | |
| 346 | + ftype s2 = fcache[1]; \ | |
| 347 | + ftype s3 = fcache[2]; \ | |
| 348 | + ftype s4 = fcache[3]; \ | |
| 349 | + ftype wet = s->mix; \ | |
| 350 | + ftype dry = 1. - wet; \ | |
| 351 | + ftype in, out; \ | |
| 357 | 352 | \ |
| 358 | 353 | for (int i = 0; i < len; i++) { \ |
| 359 | − double t1, t2, t3, t4; \ | |
| 354 | + ftype t1, t2, t3, t4; \ | |
| 360 | 355 | in = ibuf[i] + s1; \ |
| 361 | 356 | t1 = in * a1 + s2; \ |
| 362 | 357 | t2 = in * a2; \ |
| @@ -378,36 +373,37 @@ static void biquad_tdi_## name (BiquadsContext *s, \ · 15 unmodified lines | ||
| 378 | 373 | } \ |
| 379 | 374 | } \ |
| 380 | 375 | \ |
| 381 | − *z1 = s1; \ | |
| 382 | − *z2 = s2; \ | |
| 383 | − *z3 = s3; \ | |
| 384 | − *z4 = s4; \ | |
| 376 | + fcache[0] = s1; \ | |
| 377 | + fcache[1] = s2; \ | |
| 378 | + fcache[2] = s3; \ | |
| 379 | + fcache[3] = s4; \ | |
| 385 | 380 | } |
| 386 | 381 | |
| 387 | −BIQUAD_TDI_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 388 | −BIQUAD_TDI_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 389 | −BIQUAD_TDI_FILTER(flt, float, -1., 1., 0) | |
| 390 | −BIQUAD_TDI_FILTER(dbl, double, -1., 1., 0) | |
| 382 | +BIQUAD_TDI_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 383 | +BIQUAD_TDI_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 384 | +BIQUAD_TDI_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 385 | +BIQUAD_TDI_FILTER(dbl, double, double, -1., 1., 0) | |
| 391 | 386 | |
| 392 | −#define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \ | |
| 387 | +#define BIQUAD_TDII_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 393 | 388 | static void biquad_tdii_## name (BiquadsContext *s, \ |
| 394 | 389 | const void *input, void *output, int len, \ |
| 395 | − double *z1, double *z2, \ | |
| 396 | − double *unused1, double *unused2, \ | |
| 397 | − double b0, double b1, double b2, \ | |
| 398 | − double a0, double a1, double a2, int *clippings, \ | |
| 399 | − int disabled) \ | |
| 390 | + void *cache, int *clippings, int disabled) \ | |
| 400 | 391 | { \ |
| 401 | 392 | const type *ibuf = input; \ |
| 402 | 393 | type *obuf = output; \ |
| 403 | − double w1 = *z1; \ | |
| 404 | − double w2 = *z2; \ | |
| 405 | − double wet = s->mix; \ | |
| 406 | − double dry = 1. - wet; \ | |
| 407 | − double in, out; \ | |
| 408 | − \ | |
| 409 | − a1 = -a1; \ | |
| 410 | − a2 = -a2; \ | |
| 394 | + ftype *fcache = cache; \ | |
| 395 | + ftype *a = s->a_##ftype; \ | |
| 396 | + ftype *b = s->b_##ftype; \ | |
| 397 | + ftype a1 = -a[1]; \ | |
| 398 | + ftype a2 = -a[2]; \ | |
| 399 | + ftype b0 = b[0]; \ | |
| 400 | + ftype b1 = b[1]; \ | |
| 401 | + ftype b2 = b[2]; \ | |
| 402 | + ftype w1 = fcache[0]; \ | |
| 403 | + ftype w2 = fcache[1]; \ | |
| 404 | + ftype wet = s->mix; \ | |
| 405 | + ftype dry = 1. - wet; \ | |
| 406 | + ftype in, out; \ | |
| 411 | 407 | \ |
| 412 | 408 | for (int i = 0; i < len; i++) { \ |
| 413 | 409 | in = ibuf[i]; \ |
| @@ -427,33 +423,36 @@ static void biquad_tdii_## name (BiquadsContext *s, \ · 13 unmodified lines | ||
| 427 | 423 | obuf[i] = out; \ |
| 428 | 424 | } \ |
| 429 | 425 | } \ |
| 430 | − *z1 = w1; \ | |
| 431 | − *z2 = w2; \ | |
| 426 | + fcache[0] = w1; \ | |
| 427 | + fcache[1] = w2; \ | |
| 432 | 428 | } |
| 433 | 429 | |
| 434 | −BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 435 | −BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 436 | −BIQUAD_TDII_FILTER(flt, float, -1., 1., 0) | |
| 437 | −BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0) | |
| 430 | +BIQUAD_TDII_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 431 | +BIQUAD_TDII_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 432 | +BIQUAD_TDII_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 433 | +BIQUAD_TDII_FILTER(dbl, double, double, -1., 1., 0) | |
| 438 | 434 | |
| 439 | −#define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \ | |
| 435 | +#define BIQUAD_LATT_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 440 | 436 | static void biquad_latt_## name (BiquadsContext *s, \ |
| 441 | 437 | const void *input, void *output, int len, \ |
| 442 | − double *z1, double *z2, \ | |
| 443 | − double *unused1, double *unused2, \ | |
| 444 | − double v0, double v1, double v2, \ | |
| 445 | − double unused, double k0, double k1, \ | |
| 446 | − int *clippings, \ | |
| 447 | − int disabled) \ | |
| 438 | + void *cache, int *clippings, int disabled) \ | |
| 448 | 439 | { \ |
| 449 | 440 | const type *ibuf = input; \ |
| 450 | 441 | type *obuf = output; \ |
| 451 | − double s0 = *z1; \ | |
| 452 | − double s1 = *z2; \ | |
| 453 | − double wet = s->mix; \ | |
| 454 | − double dry = 1. - wet; \ | |
| 455 | − double in, out; \ | |
| 456 | − double t0, t1; \ | |
| 442 | + ftype *fcache = cache; \ | |
| 443 | + ftype *a = s->a_##ftype; \ | |
| 444 | + ftype *b = s->b_##ftype; \ | |
| 445 | + ftype k0 = a[1]; \ | |
| 446 | + ftype k1 = a[2]; \ | |
| 447 | + ftype v0 = b[0]; \ | |
| 448 | + ftype v1 = b[1]; \ | |
| 449 | + ftype v2 = b[2]; \ | |
| 450 | + ftype s0 = fcache[0]; \ | |
| 451 | + ftype s1 = fcache[1]; \ | |
| 452 | + ftype wet = s->mix; \ | |
| 453 | + ftype dry = 1. - wet; \ | |
| 454 | + ftype in, out; \ | |
| 455 | + ftype t0, t1; \ | |
| 457 | 456 | \ |
| 458 | 457 | for (int i = 0; i < len; i++) { \ |
| 459 | 458 | out = 0.; \ |
| @@ -483,32 +482,36 @@ static void biquad_latt_## name (BiquadsContext *s, \ · 23 unmodified lines | ||
| 483 | 482 | obuf[i] = out; \ |
| 484 | 483 | } \ |
| 485 | 484 | } \ |
| 486 | − *z1 = s0; \ | |
| 487 | − *z2 = s1; \ | |
| 485 | + fcache[0] = s0; \ | |
| 486 | + fcache[1] = s1; \ | |
| 488 | 487 | } |
| 489 | 488 | |
| 490 | −BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 491 | −BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 492 | −BIQUAD_LATT_FILTER(flt, float, -1., 1., 0) | |
| 493 | −BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0) | |
| 489 | +BIQUAD_LATT_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 490 | +BIQUAD_LATT_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 491 | +BIQUAD_LATT_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 492 | +BIQUAD_LATT_FILTER(dbl, double, double, -1., 1., 0) | |
| 494 | 493 | |
| 495 | −#define BIQUAD_SVF_FILTER(name, type, min, max, need_clipping) \ | |
| 494 | +#define BIQUAD_SVF_FILTER(name, type, ftype, min, max, need_clipping) \ | |
| 496 | 495 | static void biquad_svf_## name (BiquadsContext *s, \ |
| 497 | 496 | const void *input, void *output, int len, \ |
| 498 | − double *y0, double *y1, \ | |
| 499 | − double *unused1, double *unused2, \ | |
| 500 | − double b0, double b1, double b2, \ | |
| 501 | − double a0, double a1, double a2, int *clippings, \ | |
| 502 | − int disabled) \ | |
| 497 | + void *cache, int *clippings, int disabled) \ | |
| 503 | 498 | { \ |
| 504 | 499 | const type *ibuf = input; \ |
| 505 | 500 | type *obuf = output; \ |
| 506 | − double s0 = *y0; \ | |
| 507 | − double s1 = *y1; \ | |
| 508 | − double wet = s->mix; \ | |
| 509 | − double dry = 1. - wet; \ | |
| 510 | − double in, out; \ | |
| 511 | − double t0, t1; \ | |
| 501 | + ftype *fcache = cache; \ | |
| 502 | + ftype *a = s->a_##ftype; \ | |
| 503 | + ftype *b = s->b_##ftype; \ | |
| 504 | + ftype a1 = a[1]; \ | |
| 505 | + ftype a2 = a[2]; \ | |
| 506 | + ftype b0 = b[0]; \ | |
| 507 | + ftype b1 = b[1]; \ | |
| 508 | + ftype b2 = b[2]; \ | |
| 509 | + ftype s0 = fcache[0]; \ | |
| 510 | + ftype s1 = fcache[1]; \ | |
| 511 | + ftype wet = s->mix; \ | |
| 512 | + ftype dry = 1. - wet; \ | |
| 513 | + ftype in, out; \ | |
| 514 | + ftype t0, t1; \ | |
| 512 | 515 | \ |
| 513 | 516 | for (int i = 0; i < len; i++) { \ |
| 514 | 517 | in = ibuf[i]; \ |
| @@ -531,41 +534,46 @@ static void biquad_svf_## name (BiquadsContext *s, \ · 16 unmodified lines | ||
| 531 | 534 | obuf[i] = out; \ |
| 532 | 535 | } \ |
| 533 | 536 | } \ |
| 534 | − *y0 = s0; \ | |
| 535 | − *y1 = s1; \ | |
| 537 | + fcache[0] = s0; \ | |
| 538 | + fcache[1] = s1; \ | |
| 536 | 539 | } |
| 537 | 540 | |
| 538 | −BIQUAD_SVF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 539 | −BIQUAD_SVF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 540 | −BIQUAD_SVF_FILTER(flt, float, -1., 1., 0) | |
| 541 | −BIQUAD_SVF_FILTER(dbl, double, -1., 1., 0) | |
| 541 | +BIQUAD_SVF_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1) | |
| 542 | +BIQUAD_SVF_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1) | |
| 543 | +BIQUAD_SVF_FILTER(flt, float, float, -1.f, 1.f, 0) | |
| 544 | +BIQUAD_SVF_FILTER(dbl, double, double, -1., 1., 0) | |
| 542 | 545 | |
| 543 | −#define BIQUAD_ZDF_FILTER(name, type, min, max, need_clipping) \ | |
| 546 | +#define BIQUAD_ZDF_FILTER(name, type, ftype, min, max, need_clipping, two) \ | |
| 544 | 547 | static void biquad_zdf_## name (BiquadsContext *s, \ |
| 545 | 548 | const void *input, void *output, int len, \ |
| 546 | − double *y0, double *y1, \ | |
| 547 | − double *unused1, double *unused2, \ | |
| 548 | − double m0, double m1, double m2, \ | |
| 549 | − double a0, double a1, double a2, int *clippings, \ | |
| 550 | − int disabled) \ | |
| 549 | + void *cache, int *clippings, int disabled) \ | |
| 551 | 550 | { \ |
| 552 | 551 | const type *ibuf = input; \ |
| 553 | 552 | type *obuf = output; \ |
| 554 | − double b0 = *y0; \ | |
| 555 | − double b1 = *y1; \ | |
| 556 | − double wet = s->mix; \ | |
| 557 | − double dry = 1. - wet; \ | |
| 558 | − double out; \ | |
| 553 | + ftype *fcache = cache; \ | |
| 554 | + ftype *a = s->a_##ftype; \ | |
| 555 | + ftype *b = s->b_##ftype; \ | |
| 556 | + ftype m0 = b[0]; \ | |
| 557 | + ftype m1 = b[1]; \ | |
| 558 | + ftype m2 = b[2]; \ | |
| 559 | + ftype a0 = a[0]; \ | |
| 560 | + ftype a1 = a[1]; \ | |
| 561 | + ftype a2 = a[2]; \ | |
| 562 | + ftype b0 = fcache[0]; \ | |
| 563 | + ftype b1 = fcache[1]; \ | |
| 564 | + ftype wet = s->mix; \ | |
| 565 | + ftype dry = 1. - wet; \ | |
| 566 | + ftype out; \ | |
| 559 | 567 | \ |
| 560 | 568 | for (int i = 0; i < len; i++) { \ |
| 561 | − const double in = ibuf[i]; \ | |
| 562 | − const double v0 = in; \ | |
| 563 | − const double v3 = v0 - b1; \ | |
| 564 | − const double v1 = a0 * b0 + a1 * v3; \ | |
| 565 | − const double v2 = b1 + a1 * b0 + a2 * v3; \ | |
| 569 | + const ftype in = ibuf[i]; \ | |
| 570 | + const ftype v0 = in; \ | |
| 571 | + const ftype v3 = v0 - b1; \ | |
| 572 | + const ftype v1 = a0 * b0 + a1 * v3; \ | |
| 573 | + const ftype v2 = b1 + a1 * b0 + a2 * v3; \ | |
| 566 | 574 | \ |
| 567 | − b0 = 2. * v1 - b0; \ | |
| 568 | − b1 = 2. * v2 - b1; \ | |
| 575 | + b0 = two * v1 - b0; \ | |
| 576 | + b1 = two * v2 - b1; \ | |
| 569 | 577 | \ |
| 570 | 578 | out = m0 * v0 + m1 * v1 + m2 * v2; \ |
| 571 | 579 | out = out * wet + in * dry; \ |
| @@ -581,30 +589,30 @@ static void biquad_zdf_## name (BiquadsContext *s, \ · 9 unmodified lines | ||
| 581 | 589 | obuf[i] = out; \ |
| 582 | 590 | } \ |
| 583 | 591 | } \ |
| 584 | − *y0 = b0; \ | |
| 585 | − *y1 = b1; \ | |
| 592 | + fcache[0] = b0; \ | |
| 593 | + fcache[1] = b1; \ | |
| 586 | 594 | } |
| 587 | 595 | |
| 588 | −BIQUAD_ZDF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1) | |
| 589 | −BIQUAD_ZDF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1) | |
| 590 | −BIQUAD_ZDF_FILTER(flt, float, -1., 1., 0) | |
| 591 | −BIQUAD_ZDF_FILTER(dbl, double, -1., 1., 0) | |
| 596 | +BIQUAD_ZDF_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1, 2.f) | |
| 597 | +BIQUAD_ZDF_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1, 2.0) | |
| 598 | +BIQUAD_ZDF_FILTER(flt, float, float, -1.f, 1.f, 0, 2.f) | |
| 599 | +BIQUAD_ZDF_FILTER(dbl, double, double, -1., 1., 0, 2.0) | |
| 592 | 600 | |
| 593 | 601 | static void convert_dir2latt(BiquadsContext *s) |
| 594 | 602 | { |
| 595 | 603 | double k0, k1, v0, v1, v2; |
| 596 | 604 | |
| 597 | − k1 = s->a2; | |
| 598 | − k0 = s->a1 / (1. + k1); | |
| 599 | − v2 = s->b2; | |
| 600 | − v1 = s->b1 - v2 * s->a1; | |
| 601 | − v0 = s->b0 - v1 * k0 - v2 * k1; | |
| 602 | − | |
| 603 | − s->a1 = k0; | |
| 604 | − s->a2 = k1; | |
| 605 | − s->b0 = v0; | |
| 606 | − s->b1 = v1; | |
| 607 | − s->b2 = v2; | |
| 605 | + k1 = s->a_double[2]; | |
| 606 | + k0 = s->a_double[1] / (1. + k1); | |
| 607 | + v2 = s->b_double[2]; | |
| 608 | + v1 = s->b_double[1] - v2 * s->a_double[1]; | |
| 609 | + v0 = s->b_double[0] - v1 * k0 - v2 * k1; | |
| 610 | + | |
| 611 | + s->a_double[1] = k0; | |
| 612 | + s->a_double[2] = k1; | |
| 613 | + s->b_double[0] = v0; | |
| 614 | + s->b_double[1] = v1; | |
| 615 | + s->b_double[2] = v2; | |
| 608 | 616 | } |
| 609 | 617 | |
| 610 | 618 | static void convert_dir2svf(BiquadsContext *s) |
| @@ -612,17 +620,17 @@ static void convert_dir2svf(BiquadsContext *s) · 1 unmodified line | ||
| 612 | 620 | double a[2]; |
| 613 | 621 | double b[3]; |
| 614 | 622 | |
| 615 | − a[0] = -s->a1; | |
| 616 | − a[1] = -s->a2; | |
| 617 | − b[0] = s->b1 - s->a1 * s->b0; | |
| 618 | − b[1] = s->b2 - s->a2 * s->b0; | |
| 619 | − b[2] = s->b0; | |
| 620 | − | |
| 621 | − s->a1 = a[0]; | |
| 622 | − s->a2 = a[1]; | |
| 623 | − s->b0 = b[0]; | |
| 624 | − s->b1 = b[1]; | |
| 625 | − s->b2 = b[2]; | |
| 623 | + a[0] = -s->a_double[1]; | |
| 624 | + a[1] = -s->a_double[2]; | |
| 625 | + b[0] = s->b_double[1] - s->a_double[1] * s->b_double[0]; | |
| 626 | + b[1] = s->b_double[2] - s->a_double[2] * s->b_double[0]; | |
| 627 | + b[2] = s->b_double[0]; | |
| 628 | + | |
| 629 | + s->a_double[1] = a[0]; | |
| 630 | + s->a_double[2] = a[1]; | |
| 631 | + s->b_double[0] = b[0]; | |
| 632 | + s->b_double[1] = b[1]; | |
| 633 | + s->b_double[2] = b[2]; | |
| 626 | 634 | } |
| 627 | 635 | |
| 628 | 636 | static double convert_width2qfactor(double width, |
| @@ -669,12 +677,12 @@ static void convert_dir2zdf(BiquadsContext *s, int sample_rate) · 40 unmodified lines | ||
| 669 | 677 | |
| 670 | 678 | switch (s->filter_type) { |
| 671 | 679 | case biquad: |
| 672 | − a[0] = s->oa0; | |
| 673 | − a[1] = s->oa1; | |
| 674 | − a[2] = s->oa2; | |
| 675 | − m[0] = s->ob0; | |
| 676 | − m[1] = s->ob1; | |
| 677 | − m[2] = s->ob2; | |
| 680 | + a[0] = s->oa[0]; | |
| 681 | + a[1] = s->oa[1]; | |
| 682 | + a[2] = s->oa[2]; | |
| 683 | + m[0] = s->ob[0]; | |
| 684 | + m[1] = s->ob[1]; | |
| 685 | + m[2] = s->ob[2]; | |
| 678 | 686 | break; |
| 679 | 687 | case equalizer: |
| 680 | 688 | A = ff_exp10(s->gain / 40.); |
| @@ -776,12 +784,12 @@ static void convert_dir2zdf(BiquadsContext *s, int sample_rate) · 95 unmodified lines | ||
| 776 | 784 | av_assert0(0); |
| 777 | 785 | } |
| 778 | 786 | |
| 779 | − s->a0 = a[0]; | |
| 780 | − s->a1 = a[1]; | |
| 781 | − s->a2 = a[2]; | |
| 782 | − s->b0 = m[0]; | |
| 783 | − s->b1 = m[1]; | |
| 784 | − s->b2 = m[2]; | |
| 787 | + s->a_double[0] = a[0]; | |
| 788 | + s->a_double[1] = a[1]; | |
| 789 | + s->a_double[2] = a[2]; | |
| 790 | + s->b_double[0] = m[0]; | |
| 791 | + s->b_double[1] = m[1]; | |
| 792 | + s->b_double[2] = m[2]; | |
| 785 | 793 | } |
| 786 | 794 | |
| 787 | 795 | static int config_filter(AVFilterLink *outlink, int reset) |
| @@ -831,20 +839,20 @@ static int config_filter(AVFilterLink *outlink, int reset) · 43 unmodified lines | ||
| 831 | 839 | |
| 832 | 840 | switch (s->filter_type) { |
| 833 | 841 | case biquad: |
| 834 | − s->a0 = s->oa0; | |
| 835 | − s->a1 = s->oa1; | |
| 836 | − s->a2 = s->oa2; | |
| 837 | − s->b0 = s->ob0; | |
| 838 | − s->b1 = s->ob1; | |
| 839 | − s->b2 = s->ob2; | |
| 842 | + s->a_double[0] = s->oa[0]; | |
| 843 | + s->a_double[1] = s->oa[1]; | |
| 844 | + s->a_double[2] = s->oa[2]; | |
| 845 | + s->b_double[0] = s->ob[0]; | |
| 846 | + s->b_double[1] = s->ob[1]; | |
| 847 | + s->b_double[2] = s->ob[2]; | |
| 840 | 848 | break; |
| 841 | 849 | case equalizer: |
| 842 | − s->a0 = 1 + alpha / A; | |
| 843 | − s->a1 = -2 * cos(w0); | |
| 844 | − s->a2 = 1 - alpha / A; | |
| 845 | − s->b0 = 1 + alpha * A; | |
| 846 | − s->b1 = -2 * cos(w0); | |
| 847 | − s->b2 = 1 - alpha * A; | |
| 850 | + s->a_double[0] = 1 + alpha / A; | |
| 851 | + s->a_double[1] = -2 * cos(w0); | |
| 852 | + s->a_double[2] = 1 - alpha / A; | |
| 853 | + s->b_double[0] = 1 + alpha * A; | |
| 854 | + s->b_double[1] = -2 * cos(w0); | |
| 855 | + s->b_double[2] = 1 - alpha * A; | |
| 848 | 856 | break; |
| 849 | 857 | case bass: |
| 850 | 858 | beta = sqrt((A * A + 1) - (A - 1) * (A - 1)); |
| @@ -858,19 +866,19 @@ static int config_filter(AVFilterLink *outlink, int reset) · 7 unmodified lines | ||
| 858 | 866 | double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5; |
| 859 | 867 | double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5; |
| 860 | 868 | |
| 861 | − s->a0 = 1 + ro * alpha1; | |
| 862 | − s->a1 = -ro - alpha1; | |
| 863 | − s->a2 = 0; | |
| 864 | − s->b0 = beta0 + ro * beta1; | |
| 865 | − s->b1 = -beta1 - ro * beta0; | |
| 866 | − s->b2 = 0; | |
| 869 | + s->a_double[0] = 1 + ro * alpha1; | |
| 870 | + s->a_double[1] = -ro - alpha1; | |
| 871 | + s->a_double[2] = 0; | |
| 872 | + s->b_double[0] = beta0 + ro * beta1; | |
| 873 | + s->b_double[1] = -beta1 - ro * beta0; | |
| 874 | + s->b_double[2] = 0; | |
| 867 | 875 | } else { |
| 868 | − s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha; | |
| 869 | − s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0)); | |
| 870 | − s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha; | |
| 871 | − s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha); | |
| 872 | − s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0)); | |
| 873 | − s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha); | |
| 876 | + s->a_double[0] = (A + 1) + (A - 1) * cos(w0) + beta * alpha; | |
| 877 | + s->a_double[1] = -2 * ((A - 1) + (A + 1) * cos(w0)); | |
| 878 | + s->a_double[2] = (A + 1) + (A - 1) * cos(w0) - beta * alpha; | |
| 879 | + s->b_double[0] = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha); | |
| 880 | + s->b_double[1] = 2 * A * ((A - 1) - (A + 1) * cos(w0)); | |
| 881 | + s->b_double[2] = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha); | |
| 874 | 882 | } |
| 875 | 883 | break; |
| 876 | 884 | case treble: |
| @@ -884,97 +892,97 @@ static int config_filter(AVFilterLink *outlink, int reset) · 7 unmodified lines | ||
| 884 | 892 | double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5; |
| 885 | 893 | double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5; |
| 886 | 894 | |
| 887 | − s->a0 = 1 + ro * alpha1; | |
| 888 | − s->a1 = ro + alpha1; | |
| 889 | − s->a2 = 0; | |
| 890 | − s->b0 = beta0 + ro * beta1; | |
| 891 | − s->b1 = beta1 + ro * beta0; | |
| 892 | − s->b2 = 0; | |
| 895 | + s->a_double[0] = 1 + ro * alpha1; | |
| 896 | + s->a_double[1] = ro + alpha1; | |
| 897 | + s->a_double[2] = 0; | |
| 898 | + s->b_double[0] = beta0 + ro * beta1; | |
| 899 | + s->b_double[1] = beta1 + ro * beta0; | |
| 900 | + s->b_double[2] = 0; | |
| 893 | 901 | } else { |
| 894 | − s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha; | |
| 895 | − s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0)); | |
| 896 | − s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha; | |
| 897 | − s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha); | |
| 898 | − s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0)); | |
| 899 | − s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha); | |
| 902 | + s->a_double[0] = (A + 1) - (A - 1) * cos(w0) + beta * alpha; | |
| 903 | + s->a_double[1] = 2 * ((A - 1) - (A + 1) * cos(w0)); | |
| 904 | + s->a_double[2] = (A + 1) - (A - 1) * cos(w0) - beta * alpha; | |
| 905 | + s->b_double[0] = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha); | |
| 906 | + s->b_double[1] =-2 * A * ((A - 1) + (A + 1) * cos(w0)); | |
| 907 | + s->b_double[2] = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha); | |
| 900 | 908 | } |
| 901 | 909 | break; |
| 902 | 910 | case bandpass: |
| 903 | 911 | if (s->csg) { |
| 904 | − s->a0 = 1 + alpha; | |
| 905 | − s->a1 = -2 * cos(w0); | |
| 906 | − s->a2 = 1 - alpha; | |
| 907 | − s->b0 = sin(w0) / 2; | |
| 908 | − s->b1 = 0; | |
| 909 | − s->b2 = -sin(w0) / 2; | |
| 912 | + s->a_double[0] = 1 + alpha; | |
| 913 | + s->a_double[1] = -2 * cos(w0); | |
| 914 | + s->a_double[2] = 1 - alpha; | |
| 915 | + s->b_double[0] = sin(w0) / 2; | |
| 916 | + s->b_double[1] = 0; | |
| 917 | + s->b_double[2] = -sin(w0) / 2; | |
| 910 | 918 | } else { |
| 911 | − s->a0 = 1 + alpha; | |
| 912 | − s->a1 = -2 * cos(w0); | |
| 913 | − s->a2 = 1 - alpha; | |
| 914 | − s->b0 = alpha; | |
| 915 | − s->b1 = 0; | |
| 916 | − s->b2 = -alpha; | |
| 919 | + s->a_double[0] = 1 + alpha; | |
| 920 | + s->a_double[1] = -2 * cos(w0); | |
| 921 | + s->a_double[2] = 1 - alpha; | |
| 922 | + s->b_double[0] = alpha; | |
| 923 | + s->b_double[1] = 0; | |
| 924 | + s->b_double[2] = -alpha; | |
| 917 | 925 | } |
| 918 | 926 | break; |
| 919 | 927 | case bandreject: |
| 920 | − s->a0 = 1 + alpha; | |
| 921 | − s->a1 = -2 * cos(w0); | |
| 922 | − s->a2 = 1 - alpha; | |
| 923 | − s->b0 = 1; | |
| 924 | − s->b1 = -2 * cos(w0); | |
| 925 | − s->b2 = 1; | |
| 928 | + s->a_double[0] = 1 + alpha; | |
| 929 | + s->a_double[1] = -2 * cos(w0); | |
| 930 | + s->a_double[2] = 1 - alpha; | |
| 931 | + s->b_double[0] = 1; | |
| 932 | + s->b_double[1] = -2 * cos(w0); | |
| 933 | + s->b_double[2] = 1; | |
| 926 | 934 | break; |
| 927 | 935 | case lowpass: |
| 928 | 936 | if (s->poles == 1) { |
| 929 | − s->a0 = 1; | |
| 930 | − s->a1 = -exp(-w0); | |
| 931 | − s->a2 = 0; | |
| 932 | − s->b0 = 1 + s->a1; | |
| 933 | − s->b1 = 0; | |
| 934 | − s->b2 = 0; | |
| 937 | + s->a_double[0] = 1; | |
| 938 | + s->a_double[1] = -exp(-w0); | |
| 939 | + s->a_double[2] = 0; | |
| 940 | + s->b_double[0] = 1 + s->a_double[1]; | |
| 941 | + s->b_double[1] = 0; | |
| 942 | + s->b_double[2] = 0; | |
| 935 | 943 | } else { |
| 936 | − s->a0 = 1 + alpha; | |
| 937 | − s->a1 = -2 * cos(w0); | |
| 938 | − s->a2 = 1 - alpha; | |
| 939 | − s->b0 = (1 - cos(w0)) / 2; | |
| 940 | − s->b1 = 1 - cos(w0); | |
| 941 | − s->b2 = (1 - cos(w0)) / 2; | |
| 944 | + s->a_double[0] = 1 + alpha; | |
| 945 | + s->a_double[1] = -2 * cos(w0); | |
| 946 | + s->a_double[2] = 1 - alpha; | |
| 947 | + s->b_double[0] = (1 - cos(w0)) / 2; | |
| 948 | + s->b_double[1] = 1 - cos(w0); | |
| 949 | + s->b_double[2] = (1 - cos(w0)) / 2; | |
| 942 | 950 | } |
| 943 | 951 | break; |
| 944 | 952 | case highpass: |
| 945 | 953 | if (s->poles == 1) { |
| 946 | − s->a0 = 1; | |
| 947 | − s->a1 = -exp(-w0); | |
| 948 | − s->a2 = 0; | |
| 949 | − s->b0 = (1 - s->a1) / 2; | |
| 950 | − s->b1 = -s->b0; | |
| 951 | − s->b2 = 0; | |
| 954 | + s->a_double[0] = 1; | |
| 955 | + s->a_double[1] = -exp(-w0); | |
| 956 | + s->a_double[2] = 0; | |
| 957 | + s->b_double[0] = (1 - s->a_double[1]) / 2; | |
| 958 | + s->b_double[1] = -s->b_double[0]; | |
| 959 | + s->b_double[2] = 0; | |
| 952 | 960 | } else { |
| 953 | − s->a0 = 1 + alpha; | |
| 954 | − s->a1 = -2 * cos(w0); | |
| 955 | − s->a2 = 1 - alpha; | |
| 956 | − s->b0 = (1 + cos(w0)) / 2; | |
| 957 | − s->b1 = -(1 + cos(w0)); | |
| 958 | − s->b2 = (1 + cos(w0)) / 2; | |
| 961 | + s->a_double[0] = 1 + alpha; | |
| 962 | + s->a_double[1] = -2 * cos(w0); | |
| 963 | + s->a_double[2] = 1 - alpha; | |
| 964 | + s->b_double[0] = (1 + cos(w0)) / 2; | |
| 965 | + s->b_double[1] = -(1 + cos(w0)); | |
| 966 | + s->b_double[2] = (1 + cos(w0)) / 2; | |
| 959 | 967 | } |
| 960 | 968 | break; |
| 961 | 969 | case allpass: |
| 962 | 970 | switch (s->order) { |
| 963 | 971 | case 1: |
| 964 | − s->a0 = 1.; | |
| 965 | − s->a1 = -(1. - K) / (1. + K); | |
| 966 | − s->a2 = 0.; | |
| 967 | − s->b0 = s->a1; | |
| 968 | − s->b1 = s->a0; | |
| 969 | − s->b2 = 0.; | |
| 972 | + s->a_double[0] = 1.; | |
| 973 | + s->a_double[1] = -(1. - K) / (1. + K); | |
| 974 | + s->a_double[2] = 0.; | |
| 975 | + s->b_double[0] = s->a_double[1]; | |
| 976 | + s->b_double[1] = s->a_double[0]; | |
| 977 | + s->b_double[2] = 0.; | |
| 970 | 978 | break; |
| 971 | 979 | case 2: |
| 972 | − s->a0 = 1 + alpha; | |
| 973 | − s->a1 = -2 * cos(w0); | |
| 974 | − s->a2 = 1 - alpha; | |
| 975 | − s->b0 = 1 - alpha; | |
| 976 | − s->b1 = -2 * cos(w0); | |
| 977 | − s->b2 = 1 + alpha; | |
| 980 | + s->a_double[0] = 1 + alpha; | |
| 981 | + s->a_double[1] = -2 * cos(w0); | |
| 982 | + s->a_double[2] = 1 - alpha; | |
| 983 | + s->b_double[0] = 1 - alpha; | |
| 984 | + s->b_double[1] = -2 * cos(w0); | |
| 985 | + s->b_double[2] = 1 + alpha; | |
| 978 | 986 | break; |
| 979 | 987 | } |
| 980 | 988 | break; |
| @@ -982,40 +990,55 @@ static int config_filter(AVFilterLink *outlink, int reset) · 1 unmodified line | ||
| 982 | 990 | av_assert0(0); |
| 983 | 991 | } |
| 984 | 992 | |
| 985 | − av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n", s->a0, s->a1, s->a2, s->b0, s->b1, s->b2); | |
| 993 | + av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n", | |
| 994 | + s->a_double[0], s->a_double[1], s->a_double[2], | |
| 995 | + s->b_double[0], s->b_double[1], s->b_double[2]); | |
| 986 | 996 | |
| 987 | − s->a1 /= s->a0; | |
| 988 | − s->a2 /= s->a0; | |
| 989 | − s->b0 /= s->a0; | |
| 990 | − s->b1 /= s->a0; | |
| 991 | − s->b2 /= s->a0; | |
| 992 | − s->a0 /= s->a0; | |
| 997 | + s->a_double[1] /= s->a_double[0]; | |
| 998 | + s->a_double[2] /= s->a_double[0]; | |
| 999 | + s->b_double[0] /= s->a_double[0]; | |
| 1000 | + s->b_double[1] /= s->a_double[0]; | |
| 1001 | + s->b_double[2] /= s->a_double[0]; | |
| 1002 | + s->a_double[0] /= s->a_double[0]; | |
| 993 | 1003 | |
| 994 | − if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) { | |
| 995 | − double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2); | |
| 1004 | + if (s->normalize && fabs(s->b_double[0] + s->b_double[1] + s->b_double[2]) > 1e-6) { | |
| 1005 | + double factor = (s->a_double[0] + s->a_double[1] + s->a_double[2]) / | |
| 1006 | + (s->b_double[0] + s->b_double[1] + s->b_double[2]); | |
| 996 | 1007 | |
| 997 | − s->b0 *= factor; | |
| 998 | − s->b1 *= factor; | |
| 999 | − s->b2 *= factor; | |
| 1008 | + s->b_double[0] *= factor; | |
| 1009 | + s->b_double[1] *= factor; | |
| 1010 | + s->b_double[2] *= factor; | |
| 1000 | 1011 | } |
| 1001 | 1012 | |
| 1002 | 1013 | switch (s->filter_type) { |
| 1003 | 1014 | case tiltshelf: |
| 1004 | − s->b0 /= A; | |
| 1005 | − s->b1 /= A; | |
| 1006 | − s->b2 /= A; | |
| 1015 | + s->b_double[0] /= A; | |
| 1016 | + s->b_double[1] /= A; | |
| 1017 | + s->b_double[2] /= A; | |
| 1007 | 1018 | break; |
| 1008 | 1019 | } |
| 1009 | 1020 | |
| 1010 | − s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->ch_layout.nb_channels); | |
| 1011 | − if (!s->cache) | |
| 1021 | + if (!s->cache[0]) | |
| 1022 | + s->cache[0] = ff_get_audio_buffer(outlink, 4 * sizeof(double)); | |
| 1023 | + if (!s->clip) | |
| 1024 | + s->clip = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->clip)); | |
| 1025 | + if (!s->cache[0] || !s->clip) | |
| 1012 | 1026 | return AVERROR(ENOMEM); |
| 1013 | − if (reset) | |
| 1014 | − memset(s->cache, 0, sizeof(ChanCache) * inlink->ch_layout.nb_channels); | |
| 1027 | + if (reset) { | |
| 1028 | + av_samples_set_silence(s->cache[0]->extended_data, 0, s->cache[0]->nb_samples, | |
| 1029 | + s->cache[0]->ch_layout.nb_channels, s->cache[0]->format); | |
| 1030 | + } | |
| 1015 | 1031 | |
| 1016 | 1032 | if (reset && s->block_samples > 0) { |
| 1033 | + if (!s->cache[1]) | |
| 1034 | + s->cache[1] = ff_get_audio_buffer(outlink, 4 * sizeof(double)); | |
| 1035 | + if (!s->cache[1]) | |
| 1036 | + return AVERROR(ENOMEM); | |
| 1037 | + av_samples_set_silence(s->cache[1]->extended_data, 0, s->cache[1]->nb_samples, | |
| 1038 | + s->cache[1]->ch_layout.nb_channels, s->cache[1]->format); | |
| 1017 | 1039 | for (int i = 0; i < 3; i++) { |
| 1018 | − s->block[i] = ff_get_audio_buffer(outlink, s->block_samples * 2); | |
| 1040 | + if (!s->block[i]) | |
| 1041 | + s->block[i] = ff_get_audio_buffer(outlink, s->block_samples * 2); | |
| 1019 | 1042 | if (!s->block[i]) |
| 1020 | 1043 | return AVERROR(ENOMEM); |
| 1021 | 1044 | av_samples_set_silence(s->block[i]->extended_data, 0, s->block_samples * 2, |
| @@ -1145,16 +1168,23 @@ static int config_filter(AVFilterLink *outlink, int reset) · 123 unmodified lines | ||
| 1145 | 1168 | break; |
| 1146 | 1169 | default: |
| 1147 | 1170 | av_assert0(0); |
| 1148 | − } | |
| 1171 | + } | |
| 1172 | + | |
| 1173 | + s->block_align = av_get_bytes_per_sample(inlink->format); | |
| 1149 | 1174 | |
| 1150 | − s->block_align = av_get_bytes_per_sample(inlink->format); | |
| 1175 | + if (s->transform_type == LATT) | |
| 1176 | + convert_dir2latt(s); | |
| 1177 | + else if (s->transform_type == SVF) | |
| 1178 | + convert_dir2svf(s); | |
| 1179 | + else if (s->transform_type == ZDF) | |
| 1180 | + convert_dir2zdf(s, inlink->sample_rate); | |
| 1151 | 1181 | |
| 1152 | − if (s->transform_type == LATT) | |
| 1153 | − convert_dir2latt(s); | |
| 1154 | − else if (s->transform_type == SVF) | |
| 1155 | − convert_dir2svf(s); | |
| 1156 | − else if (s->transform_type == ZDF) | |
| 1157 | − convert_dir2zdf(s, inlink->sample_rate); | |
| 1182 | + s->a_float[0] = s->a_double[0]; | |
| 1183 | + s->a_float[1] = s->a_double[1]; | |
| 1184 | + s->a_float[2] = s->a_double[2]; | |
| 1185 | + s->b_float[0] = s->b_double[0]; | |
| 1186 | + s->b_float[1] = s->b_double[1]; | |
| 1187 | + s->b_float[2] = s->b_double[2]; | |
| 1158 | 1188 | |
| 1159 | 1189 | return 0; |
| 1160 | 1190 | } |
| @@ -1227,8 +1257,7 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job · 66 unmodified lines | ||
| 1227 | 1257 | |
| 1228 | 1258 | if (!s->block_samples) { |
| 1229 | 1259 | s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples, |
| 1230 | − &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2, | |
| 1231 | − s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled); | |
| 1260 | + s->cache[0]->extended_data[ch], s->clip+ch, ctx->is_disabled); | |
| 1232 | 1261 | } else if (td->eof) { |
| 1233 | 1262 | memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch] + s->block_align * s->block_samples, |
| 1234 | 1263 | s->nb_samples * s->block_align); |
| @@ -1238,25 +1267,19 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job · 3 unmodified lines | ||
| 1238 | 1267 | memset(s->block[0]->extended_data[ch] + s->block_align * (s->block_samples + buf->nb_samples), |
| 1239 | 1268 | 0, (s->block_samples - buf->nb_samples) * s->block_align); |
| 1240 | 1269 | s->filter(s, s->block[0]->extended_data[ch], s->block[1]->extended_data[ch], s->block_samples, |
| 1241 | − &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2, | |
| 1242 | − s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled); | |
| 1243 | − s->cache[ch].ri1 = s->cache[ch].i1; | |
| 1244 | − s->cache[ch].ri2 = s->cache[ch].i2; | |
| 1245 | − s->cache[ch].ro1 = s->cache[ch].o1; | |
| 1246 | − s->cache[ch].ro2 = s->cache[ch].o2; | |
| 1270 | + s->cache[0]->extended_data[ch], s->clip+ch, ctx->is_disabled); | |
| 1271 | + av_samples_copy(s->cache[1]->extended_data, s->cache[0]->extended_data, 0, 0, | |
| 1272 | + s->cache[0]->nb_samples, s->cache[0]->ch_layout.nb_channels, | |
| 1273 | + s->cache[0]->format); | |
| 1247 | 1274 | s->filter(s, s->block[0]->extended_data[ch] + s->block_samples * s->block_align, |
| 1248 | 1275 | s->block[1]->extended_data[ch] + s->block_samples * s->block_align, |
| 1249 | − s->block_samples, | |
| 1250 | − &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2, | |
| 1251 | − s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled); | |
| 1276 | + s->block_samples, s->cache[1]->extended_data[ch], s->clip+ch, | |
| 1277 | + ctx->is_disabled); | |
| 1252 | 1278 | reverse_samples(s->block[2], s->block[1], ch, 0, 0, 2 * s->block_samples); |
| 1253 | − s->cache[ch].ri1 = 0.; | |
| 1254 | − s->cache[ch].ri2 = 0.; | |
| 1255 | − s->cache[ch].ro1 = 0.; | |
| 1256 | − s->cache[ch].ro2 = 0.; | |
| 1279 | + av_samples_set_silence(s->cache[1]->extended_data, 0, s->cache[1]->nb_samples, | |
| 1280 | + s->cache[1]->ch_layout.nb_channels, s->cache[1]->format); | |
| 1257 | 1281 | s->filter(s, s->block[2]->extended_data[ch], s->block[2]->extended_data[ch], 2 * s->block_samples, |
| 1258 | − &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2, | |
| 1259 | − s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled); | |
| 1282 | + s->cache[1]->extended_data[ch], s->clip+ch, ctx->is_disabled); | |
| 1260 | 1283 | reverse_samples(s->block[1], s->block[2], ch, 0, 0, 2 * s->block_samples); |
| 1261 | 1284 | memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch], |
| 1262 | 1285 | s->block_samples * s->block_align); |
| @@ -1309,10 +1332,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf, int eof) · 46 unmodified lines | ||
| 1309 | 1332 | FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx))); |
| 1310 | 1333 | |
| 1311 | 1334 | for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) { |
| 1312 | − if (s->cache[ch].clippings > 0) | |
| 1335 | + if (s->clip[ch] > 0) | |
| 1313 | 1336 | av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n", |
| 1314 | − ch, s->cache[ch].clippings); | |
| 1315 | − s->cache[ch].clippings = 0; | |
| 1337 | + ch, s->clip[ch]); | |
| 1338 | + s->clip[ch] = 0; | |
| 1316 | 1339 | } |
| 1317 | 1340 | |
| 1318 | 1341 | if (s->block_samples > 0) { |
| @@ -1402,7 +1425,9 @@ static av_cold void uninit(AVFilterContext *ctx) · 83 unmodified lines | ||
| 1402 | 1425 | |
| 1403 | 1426 | for (int i = 0; i < 3; i++) |
| 1404 | 1427 | av_frame_free(&s->block[i]); |
| 1405 | − av_freep(&s->cache); | |
| 1428 | + av_frame_free(&s->cache[0]); | |
| 1429 | + av_frame_free(&s->cache[1]); | |
| 1430 | + av_freep(&s->clip); | |
| 1406 | 1431 | av_channel_layout_uninit(&s->ch_layout); |
| 1407 | 1432 | } |
| 1408 | 1433 | |
| @@ -1657,12 +1682,12 @@ DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter."); · 248 unmodified lines | ||
| 1657 | 1682 | #endif /* CONFIG_ALLPASS_FILTER */ |
| 1658 | 1683 | #if CONFIG_BIQUAD_FILTER |
| 1659 | 1684 | static const AVOption biquad_options[] = { |
| 1660 | − {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1661 | − {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1662 | − {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1663 | − {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1664 | − {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1665 | − {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1685 | + {"a0", NULL, OFFSET(oa[0]), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1686 | + {"a1", NULL, OFFSET(oa[1]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1687 | + {"a2", NULL, OFFSET(oa[2]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1688 | + {"b0", NULL, OFFSET(ob[0]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1689 | + {"b1", NULL, OFFSET(ob[1]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1690 | + {"b2", NULL, OFFSET(ob[2]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS}, | |
| 1666 | 1691 | MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0), |
| 1667 | 1692 | TRANSFORM_OPTION(DI), |
| 1668 | 1693 | PRECISION_OPTION(-1), |