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