You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1255 lines
66KB

  1. /*
  2. * Copyright (c) 2013 Paul B Mahol
  3. * Copyright (c) 2006-2008 Rob Sykes <robs@users.sourceforge.net>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /*
  22. * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
  23. * see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
  24. *
  25. * 1-pole filters based on code (c) 2000 Chris Bagwell <cbagwell@sprynet.com>
  26. * Algorithms: Recursive single pole low/high pass filter
  27. * Reference: The Scientist and Engineer's Guide to Digital Signal Processing
  28. *
  29. * low-pass: output[N] = input[N] * A + output[N-1] * B
  30. * X = exp(-2.0 * pi * Fc)
  31. * A = 1 - X
  32. * B = X
  33. * Fc = cutoff freq / sample rate
  34. *
  35. * Mimics an RC low-pass filter:
  36. *
  37. * ---/\/\/\/\----------->
  38. * |
  39. * --- C
  40. * ---
  41. * |
  42. * |
  43. * V
  44. *
  45. * high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
  46. * X = exp(-2.0 * pi * Fc)
  47. * A0 = (1 + X) / 2
  48. * A1 = -(1 + X) / 2
  49. * B1 = X
  50. * Fc = cutoff freq / sample rate
  51. *
  52. * Mimics an RC high-pass filter:
  53. *
  54. * || C
  55. * ----||--------->
  56. * || |
  57. * <
  58. * > R
  59. * <
  60. * |
  61. * V
  62. */
  63. #include "libavutil/avassert.h"
  64. #include "libavutil/ffmath.h"
  65. #include "libavutil/opt.h"
  66. #include "audio.h"
  67. #include "avfilter.h"
  68. #include "internal.h"
  69. enum FilterType {
  70. biquad,
  71. equalizer,
  72. bass,
  73. treble,
  74. bandpass,
  75. bandreject,
  76. allpass,
  77. highpass,
  78. lowpass,
  79. lowshelf,
  80. highshelf,
  81. };
  82. enum WidthType {
  83. NONE,
  84. HERTZ,
  85. OCTAVE,
  86. QFACTOR,
  87. SLOPE,
  88. KHERTZ,
  89. NB_WTYPE,
  90. };
  91. enum TransformType {
  92. DI,
  93. DII,
  94. TDII,
  95. LATT,
  96. NB_TTYPE,
  97. };
  98. typedef struct ChanCache {
  99. double i1, i2;
  100. double o1, o2;
  101. int clippings;
  102. } ChanCache;
  103. typedef struct BiquadsContext {
  104. const AVClass *class;
  105. enum FilterType filter_type;
  106. int width_type;
  107. int poles;
  108. int csg;
  109. int transform_type;
  110. int precision;
  111. int bypass;
  112. double gain;
  113. double frequency;
  114. double width;
  115. double mix;
  116. uint64_t channels;
  117. int normalize;
  118. int order;
  119. double a0, a1, a2;
  120. double b0, b1, b2;
  121. double oa0, oa1, oa2;
  122. double ob0, ob1, ob2;
  123. ChanCache *cache;
  124. int block_align;
  125. void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
  126. double *i1, double *i2, double *o1, double *o2,
  127. double b0, double b1, double b2, double a1, double a2, int *clippings,
  128. int disabled);
  129. } BiquadsContext;
  130. static int query_formats(AVFilterContext *ctx)
  131. {
  132. BiquadsContext *s = ctx->priv;
  133. AVFilterFormats *formats;
  134. AVFilterChannelLayouts *layouts;
  135. static const enum AVSampleFormat auto_sample_fmts[] = {
  136. AV_SAMPLE_FMT_S16P,
  137. AV_SAMPLE_FMT_S32P,
  138. AV_SAMPLE_FMT_FLTP,
  139. AV_SAMPLE_FMT_DBLP,
  140. AV_SAMPLE_FMT_NONE
  141. };
  142. enum AVSampleFormat sample_fmts[] = {
  143. AV_SAMPLE_FMT_S16P,
  144. AV_SAMPLE_FMT_NONE
  145. };
  146. int ret;
  147. layouts = ff_all_channel_counts();
  148. if (!layouts)
  149. return AVERROR(ENOMEM);
  150. ret = ff_set_common_channel_layouts(ctx, layouts);
  151. if (ret < 0)
  152. return ret;
  153. switch (s->precision) {
  154. case 0:
  155. sample_fmts[0] = AV_SAMPLE_FMT_S16P;
  156. formats = ff_make_format_list(sample_fmts);
  157. break;
  158. case 1:
  159. sample_fmts[0] = AV_SAMPLE_FMT_S32P;
  160. formats = ff_make_format_list(sample_fmts);
  161. break;
  162. case 2:
  163. sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
  164. formats = ff_make_format_list(sample_fmts);
  165. break;
  166. case 3:
  167. sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
  168. formats = ff_make_format_list(sample_fmts);
  169. break;
  170. default:
  171. formats = ff_make_format_list(auto_sample_fmts);
  172. break;
  173. }
  174. if (!formats)
  175. return AVERROR(ENOMEM);
  176. ret = ff_set_common_formats(ctx, formats);
  177. if (ret < 0)
  178. return ret;
  179. formats = ff_all_samplerates();
  180. if (!formats)
  181. return AVERROR(ENOMEM);
  182. return ff_set_common_samplerates(ctx, formats);
  183. }
  184. #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
  185. static void biquad_## name (BiquadsContext *s, \
  186. const void *input, void *output, int len, \
  187. double *in1, double *in2, \
  188. double *out1, double *out2, \
  189. double b0, double b1, double b2, \
  190. double a1, double a2, int *clippings, \
  191. int disabled) \
  192. { \
  193. const type *ibuf = input; \
  194. type *obuf = output; \
  195. double i1 = *in1; \
  196. double i2 = *in2; \
  197. double o1 = *out1; \
  198. double o2 = *out2; \
  199. double wet = s->mix; \
  200. double dry = 1. - wet; \
  201. double out; \
  202. int i; \
  203. a1 = -a1; \
  204. a2 = -a2; \
  205. \
  206. for (i = 0; i+1 < len; i++) { \
  207. o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
  208. i2 = ibuf[i]; \
  209. out = o2 * wet + i2 * dry; \
  210. if (disabled) { \
  211. obuf[i] = i2; \
  212. } else if (need_clipping && out < min) { \
  213. (*clippings)++; \
  214. obuf[i] = min; \
  215. } else if (need_clipping && out > max) { \
  216. (*clippings)++; \
  217. obuf[i] = max; \
  218. } else { \
  219. obuf[i] = out; \
  220. } \
  221. i++; \
  222. o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
  223. i1 = ibuf[i]; \
  224. out = o1 * wet + i1 * dry; \
  225. if (disabled) { \
  226. obuf[i] = i1; \
  227. } else if (need_clipping && out < min) { \
  228. (*clippings)++; \
  229. obuf[i] = min; \
  230. } else if (need_clipping && out > max) { \
  231. (*clippings)++; \
  232. obuf[i] = max; \
  233. } else { \
  234. obuf[i] = out; \
  235. } \
  236. } \
  237. if (i < len) { \
  238. double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
  239. i2 = i1; \
  240. i1 = ibuf[i]; \
  241. o2 = o1; \
  242. o1 = o0; \
  243. out = o0 * wet + i1 * dry; \
  244. if (disabled) { \
  245. obuf[i] = i1; \
  246. } else if (need_clipping && out < min) { \
  247. (*clippings)++; \
  248. obuf[i] = min; \
  249. } else if (need_clipping && out > max) { \
  250. (*clippings)++; \
  251. obuf[i] = max; \
  252. } else { \
  253. obuf[i] = out; \
  254. } \
  255. } \
  256. *in1 = i1; \
  257. *in2 = i2; \
  258. *out1 = o1; \
  259. *out2 = o2; \
  260. }
  261. BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  262. BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  263. BIQUAD_FILTER(flt, float, -1., 1., 0)
  264. BIQUAD_FILTER(dbl, double, -1., 1., 0)
  265. #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \
  266. static void biquad_dii_## name (BiquadsContext *s, \
  267. const void *input, void *output, int len, \
  268. double *z1, double *z2, \
  269. double *unused1, double *unused2, \
  270. double b0, double b1, double b2, \
  271. double a1, double a2, int *clippings, \
  272. int disabled) \
  273. { \
  274. const type *ibuf = input; \
  275. type *obuf = output; \
  276. double w1 = *z1; \
  277. double w2 = *z2; \
  278. double wet = s->mix; \
  279. double dry = 1. - wet; \
  280. double in, out, w0; \
  281. \
  282. a1 = -a1; \
  283. a2 = -a2; \
  284. \
  285. for (int i = 0; i < len; i++) { \
  286. in = ibuf[i]; \
  287. w0 = in + a1 * w1 + a2 * w2; \
  288. out = b0 * w0 + b1 * w1 + b2 * w2; \
  289. w2 = w1; \
  290. w1 = w0; \
  291. out = out * wet + in * dry; \
  292. if (disabled) { \
  293. obuf[i] = in; \
  294. } else if (need_clipping && out < min) { \
  295. (*clippings)++; \
  296. obuf[i] = min; \
  297. } else if (need_clipping && out > max) { \
  298. (*clippings)++; \
  299. obuf[i] = max; \
  300. } else { \
  301. obuf[i] = out; \
  302. } \
  303. } \
  304. *z1 = w1; \
  305. *z2 = w2; \
  306. }
  307. BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  308. BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  309. BIQUAD_DII_FILTER(flt, float, -1., 1., 0)
  310. BIQUAD_DII_FILTER(dbl, double, -1., 1., 0)
  311. #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \
  312. static void biquad_tdii_## name (BiquadsContext *s, \
  313. const void *input, void *output, int len, \
  314. double *z1, double *z2, \
  315. double *unused1, double *unused2, \
  316. double b0, double b1, double b2, \
  317. double a1, double a2, int *clippings, \
  318. int disabled) \
  319. { \
  320. const type *ibuf = input; \
  321. type *obuf = output; \
  322. double w1 = *z1; \
  323. double w2 = *z2; \
  324. double wet = s->mix; \
  325. double dry = 1. - wet; \
  326. double in, out; \
  327. \
  328. a1 = -a1; \
  329. a2 = -a2; \
  330. \
  331. for (int i = 0; i < len; i++) { \
  332. in = ibuf[i]; \
  333. out = b0 * in + w1; \
  334. w1 = b1 * in + w2 + a1 * out; \
  335. w2 = b2 * in + a2 * out; \
  336. out = out * wet + in * dry; \
  337. if (disabled) { \
  338. obuf[i] = in; \
  339. } else if (need_clipping && out < min) { \
  340. (*clippings)++; \
  341. obuf[i] = min; \
  342. } else if (need_clipping && out > max) { \
  343. (*clippings)++; \
  344. obuf[i] = max; \
  345. } else { \
  346. obuf[i] = out; \
  347. } \
  348. } \
  349. *z1 = w1; \
  350. *z2 = w2; \
  351. }
  352. BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  353. BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  354. BIQUAD_TDII_FILTER(flt, float, -1., 1., 0)
  355. BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0)
  356. #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \
  357. static void biquad_latt_## name (BiquadsContext *s, \
  358. const void *input, void *output, int len, \
  359. double *z1, double *z2, \
  360. double *unused1, double *unused2, \
  361. double v0, double v1, double v2, \
  362. double k0, double k1, int *clippings, \
  363. int disabled) \
  364. { \
  365. const type *ibuf = input; \
  366. type *obuf = output; \
  367. double s0 = *z1; \
  368. double s1 = *z2; \
  369. double wet = s->mix; \
  370. double dry = 1. - wet; \
  371. double in, out; \
  372. double t0, t1; \
  373. \
  374. for (int i = 0; i < len; i++) { \
  375. out = 0.; \
  376. in = ibuf[i]; \
  377. t0 = in - k1 * s0; \
  378. t1 = t0 * k1 + s0; \
  379. out += t1 * v2; \
  380. \
  381. t0 = t0 - k0 * s1; \
  382. t1 = t0 * k0 + s1; \
  383. out += t1 * v1; \
  384. \
  385. out += t0 * v0; \
  386. s0 = t1; \
  387. s1 = t0; \
  388. \
  389. out = out * wet + in * dry; \
  390. if (disabled) { \
  391. obuf[i] = in; \
  392. } else if (need_clipping && out < min) { \
  393. (*clippings)++; \
  394. obuf[i] = min; \
  395. } else if (need_clipping && out > max) { \
  396. (*clippings)++; \
  397. obuf[i] = max; \
  398. } else { \
  399. obuf[i] = out; \
  400. } \
  401. } \
  402. *z1 = s0; \
  403. *z2 = s1; \
  404. }
  405. BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  406. BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  407. BIQUAD_LATT_FILTER(flt, float, -1., 1., 0)
  408. BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0)
  409. static void convert_dir2latt(BiquadsContext *s)
  410. {
  411. double k0, k1, v0, v1, v2;
  412. k1 = s->a2;
  413. k0 = s->a1 / (1. + k1);
  414. v2 = s->b2;
  415. v1 = s->b1 - v2 * s->a1;
  416. v0 = s->b0 - v1 * k0 - v2 * k1;
  417. s->a1 = k0;
  418. s->a2 = k1;
  419. s->b0 = v0;
  420. s->b1 = v1;
  421. s->b2 = v2;
  422. }
  423. static int config_filter(AVFilterLink *outlink, int reset)
  424. {
  425. AVFilterContext *ctx = outlink->src;
  426. BiquadsContext *s = ctx->priv;
  427. AVFilterLink *inlink = ctx->inputs[0];
  428. double A = ff_exp10(s->gain / 40);
  429. double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
  430. double K = tan(w0 / 2.);
  431. double alpha, beta;
  432. s->bypass = (((w0 > M_PI || w0 <= 0.) && reset) || (s->width <= 0.)) && (s->filter_type != biquad);
  433. if (s->bypass) {
  434. av_log(ctx, AV_LOG_WARNING, "Invalid frequency and/or width!\n");
  435. return 0;
  436. }
  437. if ((w0 > M_PI || w0 <= 0.) && (s->filter_type != biquad))
  438. return AVERROR(EINVAL);
  439. switch (s->width_type) {
  440. case NONE:
  441. alpha = 0.0;
  442. break;
  443. case HERTZ:
  444. alpha = sin(w0) / (2 * s->frequency / s->width);
  445. break;
  446. case KHERTZ:
  447. alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
  448. break;
  449. case OCTAVE:
  450. alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
  451. break;
  452. case QFACTOR:
  453. alpha = sin(w0) / (2 * s->width);
  454. break;
  455. case SLOPE:
  456. alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
  457. break;
  458. default:
  459. av_assert0(0);
  460. }
  461. beta = 2 * sqrt(A);
  462. switch (s->filter_type) {
  463. case biquad:
  464. s->a0 = s->oa0;
  465. s->a1 = s->oa1;
  466. s->a2 = s->oa2;
  467. s->b0 = s->ob0;
  468. s->b1 = s->ob1;
  469. s->b2 = s->ob2;
  470. break;
  471. case equalizer:
  472. s->a0 = 1 + alpha / A;
  473. s->a1 = -2 * cos(w0);
  474. s->a2 = 1 - alpha / A;
  475. s->b0 = 1 + alpha * A;
  476. s->b1 = -2 * cos(w0);
  477. s->b2 = 1 - alpha * A;
  478. break;
  479. case bass:
  480. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  481. case lowshelf:
  482. if (s->poles == 1) {
  483. double A = ff_exp10(s->gain / 20);
  484. double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
  485. double n = (A + 1) / (A - 1);
  486. double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
  487. double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
  488. double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
  489. s->a0 = 1 + ro * alpha1;
  490. s->a1 = -ro - alpha1;
  491. s->a2 = 0;
  492. s->b0 = beta0 + ro * beta1;
  493. s->b1 = -beta1 - ro * beta0;
  494. s->b2 = 0;
  495. } else {
  496. s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
  497. s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
  498. s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
  499. s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
  500. s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
  501. s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
  502. }
  503. break;
  504. case treble:
  505. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  506. case highshelf:
  507. if (s->poles == 1) {
  508. double A = ff_exp10(s->gain / 20);
  509. double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
  510. double n = (A + 1) / (A - 1);
  511. double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
  512. double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
  513. double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
  514. s->a0 = 1 + ro * alpha1;
  515. s->a1 = ro + alpha1;
  516. s->a2 = 0;
  517. s->b0 = beta0 + ro * beta1;
  518. s->b1 = beta1 + ro * beta0;
  519. s->b2 = 0;
  520. } else {
  521. s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
  522. s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
  523. s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
  524. s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
  525. s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
  526. s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
  527. }
  528. break;
  529. case bandpass:
  530. if (s->csg) {
  531. s->a0 = 1 + alpha;
  532. s->a1 = -2 * cos(w0);
  533. s->a2 = 1 - alpha;
  534. s->b0 = sin(w0) / 2;
  535. s->b1 = 0;
  536. s->b2 = -sin(w0) / 2;
  537. } else {
  538. s->a0 = 1 + alpha;
  539. s->a1 = -2 * cos(w0);
  540. s->a2 = 1 - alpha;
  541. s->b0 = alpha;
  542. s->b1 = 0;
  543. s->b2 = -alpha;
  544. }
  545. break;
  546. case bandreject:
  547. s->a0 = 1 + alpha;
  548. s->a1 = -2 * cos(w0);
  549. s->a2 = 1 - alpha;
  550. s->b0 = 1;
  551. s->b1 = -2 * cos(w0);
  552. s->b2 = 1;
  553. break;
  554. case lowpass:
  555. if (s->poles == 1) {
  556. s->a0 = 1;
  557. s->a1 = -exp(-w0);
  558. s->a2 = 0;
  559. s->b0 = 1 + s->a1;
  560. s->b1 = 0;
  561. s->b2 = 0;
  562. } else {
  563. s->a0 = 1 + alpha;
  564. s->a1 = -2 * cos(w0);
  565. s->a2 = 1 - alpha;
  566. s->b0 = (1 - cos(w0)) / 2;
  567. s->b1 = 1 - cos(w0);
  568. s->b2 = (1 - cos(w0)) / 2;
  569. }
  570. break;
  571. case highpass:
  572. if (s->poles == 1) {
  573. s->a0 = 1;
  574. s->a1 = -exp(-w0);
  575. s->a2 = 0;
  576. s->b0 = (1 - s->a1) / 2;
  577. s->b1 = -s->b0;
  578. s->b2 = 0;
  579. } else {
  580. s->a0 = 1 + alpha;
  581. s->a1 = -2 * cos(w0);
  582. s->a2 = 1 - alpha;
  583. s->b0 = (1 + cos(w0)) / 2;
  584. s->b1 = -(1 + cos(w0));
  585. s->b2 = (1 + cos(w0)) / 2;
  586. }
  587. break;
  588. case allpass:
  589. switch (s->order) {
  590. case 1:
  591. s->a0 = 1.;
  592. s->a1 = -(1. - K) / (1. + K);
  593. s->a2 = 0.;
  594. s->b0 = s->a1;
  595. s->b1 = s->a0;
  596. s->b2 = 0.;
  597. break;
  598. case 2:
  599. s->a0 = 1 + alpha;
  600. s->a1 = -2 * cos(w0);
  601. s->a2 = 1 - alpha;
  602. s->b0 = 1 - alpha;
  603. s->b1 = -2 * cos(w0);
  604. s->b2 = 1 + alpha;
  605. break;
  606. }
  607. break;
  608. default:
  609. av_assert0(0);
  610. }
  611. 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);
  612. s->a1 /= s->a0;
  613. s->a2 /= s->a0;
  614. s->b0 /= s->a0;
  615. s->b1 /= s->a0;
  616. s->b2 /= s->a0;
  617. s->a0 /= s->a0;
  618. if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) {
  619. double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2);
  620. s->b0 *= factor;
  621. s->b1 *= factor;
  622. s->b2 *= factor;
  623. }
  624. s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
  625. if (!s->cache)
  626. return AVERROR(ENOMEM);
  627. if (reset)
  628. memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
  629. switch (s->transform_type) {
  630. case DI:
  631. switch (inlink->format) {
  632. case AV_SAMPLE_FMT_S16P:
  633. s->filter = biquad_s16;
  634. break;
  635. case AV_SAMPLE_FMT_S32P:
  636. s->filter = biquad_s32;
  637. break;
  638. case AV_SAMPLE_FMT_FLTP:
  639. s->filter = biquad_flt;
  640. break;
  641. case AV_SAMPLE_FMT_DBLP:
  642. s->filter = biquad_dbl;
  643. break;
  644. default: av_assert0(0);
  645. }
  646. break;
  647. case DII:
  648. switch (inlink->format) {
  649. case AV_SAMPLE_FMT_S16P:
  650. s->filter = biquad_dii_s16;
  651. break;
  652. case AV_SAMPLE_FMT_S32P:
  653. s->filter = biquad_dii_s32;
  654. break;
  655. case AV_SAMPLE_FMT_FLTP:
  656. s->filter = biquad_dii_flt;
  657. break;
  658. case AV_SAMPLE_FMT_DBLP:
  659. s->filter = biquad_dii_dbl;
  660. break;
  661. default: av_assert0(0);
  662. }
  663. break;
  664. case TDII:
  665. switch (inlink->format) {
  666. case AV_SAMPLE_FMT_S16P:
  667. s->filter = biquad_tdii_s16;
  668. break;
  669. case AV_SAMPLE_FMT_S32P:
  670. s->filter = biquad_tdii_s32;
  671. break;
  672. case AV_SAMPLE_FMT_FLTP:
  673. s->filter = biquad_tdii_flt;
  674. break;
  675. case AV_SAMPLE_FMT_DBLP:
  676. s->filter = biquad_tdii_dbl;
  677. break;
  678. default: av_assert0(0);
  679. }
  680. break;
  681. case LATT:
  682. switch (inlink->format) {
  683. case AV_SAMPLE_FMT_S16P:
  684. s->filter = biquad_latt_s16;
  685. break;
  686. case AV_SAMPLE_FMT_S32P:
  687. s->filter = biquad_latt_s32;
  688. break;
  689. case AV_SAMPLE_FMT_FLTP:
  690. s->filter = biquad_latt_flt;
  691. break;
  692. case AV_SAMPLE_FMT_DBLP:
  693. s->filter = biquad_latt_dbl;
  694. break;
  695. default: av_assert0(0);
  696. }
  697. break;
  698. default:
  699. av_assert0(0);
  700. }
  701. s->block_align = av_get_bytes_per_sample(inlink->format);
  702. if (s->transform_type == LATT)
  703. convert_dir2latt(s);
  704. return 0;
  705. }
  706. static int config_output(AVFilterLink *outlink)
  707. {
  708. return config_filter(outlink, 1);
  709. }
  710. typedef struct ThreadData {
  711. AVFrame *in, *out;
  712. } ThreadData;
  713. static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  714. {
  715. AVFilterLink *inlink = ctx->inputs[0];
  716. ThreadData *td = arg;
  717. AVFrame *buf = td->in;
  718. AVFrame *out_buf = td->out;
  719. BiquadsContext *s = ctx->priv;
  720. const int start = (buf->channels * jobnr) / nb_jobs;
  721. const int end = (buf->channels * (jobnr+1)) / nb_jobs;
  722. int ch;
  723. for (ch = start; ch < end; ch++) {
  724. if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
  725. if (buf != out_buf)
  726. memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
  727. buf->nb_samples * s->block_align);
  728. continue;
  729. }
  730. s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
  731. &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
  732. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  733. }
  734. return 0;
  735. }
  736. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  737. {
  738. AVFilterContext *ctx = inlink->dst;
  739. BiquadsContext *s = ctx->priv;
  740. AVFilterLink *outlink = ctx->outputs[0];
  741. AVFrame *out_buf;
  742. ThreadData td;
  743. int ch;
  744. if (s->bypass)
  745. return ff_filter_frame(outlink, buf);
  746. if (av_frame_is_writable(buf)) {
  747. out_buf = buf;
  748. } else {
  749. out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
  750. if (!out_buf) {
  751. av_frame_free(&buf);
  752. return AVERROR(ENOMEM);
  753. }
  754. av_frame_copy_props(out_buf, buf);
  755. }
  756. td.in = buf;
  757. td.out = out_buf;
  758. ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
  759. for (ch = 0; ch < outlink->channels; ch++) {
  760. if (s->cache[ch].clippings > 0)
  761. av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
  762. ch, s->cache[ch].clippings);
  763. s->cache[ch].clippings = 0;
  764. }
  765. if (buf != out_buf)
  766. av_frame_free(&buf);
  767. return ff_filter_frame(outlink, out_buf);
  768. }
  769. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  770. char *res, int res_len, int flags)
  771. {
  772. AVFilterLink *outlink = ctx->outputs[0];
  773. int ret;
  774. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  775. if (ret < 0)
  776. return ret;
  777. return config_filter(outlink, 0);
  778. }
  779. static av_cold void uninit(AVFilterContext *ctx)
  780. {
  781. BiquadsContext *s = ctx->priv;
  782. av_freep(&s->cache);
  783. }
  784. static const AVFilterPad inputs[] = {
  785. {
  786. .name = "default",
  787. .type = AVMEDIA_TYPE_AUDIO,
  788. .filter_frame = filter_frame,
  789. },
  790. { NULL }
  791. };
  792. static const AVFilterPad outputs[] = {
  793. {
  794. .name = "default",
  795. .type = AVMEDIA_TYPE_AUDIO,
  796. .config_props = config_output,
  797. },
  798. { NULL }
  799. };
  800. #define OFFSET(x) offsetof(BiquadsContext, x)
  801. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  802. #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  803. #define DEFINE_BIQUAD_FILTER(name_, description_) \
  804. AVFILTER_DEFINE_CLASS(name_); \
  805. static av_cold int name_##_init(AVFilterContext *ctx) \
  806. { \
  807. BiquadsContext *s = ctx->priv; \
  808. s->filter_type = name_; \
  809. return 0; \
  810. } \
  811. \
  812. AVFilter ff_af_##name_ = { \
  813. .name = #name_, \
  814. .description = NULL_IF_CONFIG_SMALL(description_), \
  815. .priv_size = sizeof(BiquadsContext), \
  816. .init = name_##_init, \
  817. .uninit = uninit, \
  818. .query_formats = query_formats, \
  819. .inputs = inputs, \
  820. .outputs = outputs, \
  821. .priv_class = &name_##_class, \
  822. .process_command = process_command, \
  823. .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
  824. }
  825. #if CONFIG_EQUALIZER_FILTER
  826. static const AVOption equalizer_options[] = {
  827. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  828. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  829. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  830. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  831. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  832. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  833. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  834. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  835. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  836. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  837. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  838. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  839. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  840. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  841. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  842. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  843. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  844. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  845. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  846. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  847. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  848. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  849. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  850. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  851. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  852. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  853. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  854. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  855. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  856. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  857. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  858. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  859. {NULL}
  860. };
  861. DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
  862. #endif /* CONFIG_EQUALIZER_FILTER */
  863. #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER
  864. static const AVOption bass_lowshelf_options[] = {
  865. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  866. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  867. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  868. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  869. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  870. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  871. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  872. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  873. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  874. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  875. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  876. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  877. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  878. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  879. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  880. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  881. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  882. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  883. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  884. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  885. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  886. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  887. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  888. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  889. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  890. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  891. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  892. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  893. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  894. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  895. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  896. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  897. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  898. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  899. {NULL}
  900. };
  901. #if CONFIG_BASS_FILTER
  902. #define bass_options bass_lowshelf_options
  903. DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
  904. #endif /* CONFIG_BASS_FILTER */
  905. #if CONFIG_LOWSHELF_FILTER
  906. #define lowshelf_options bass_lowshelf_options
  907. DEFINE_BIQUAD_FILTER(lowshelf, "Apply a low shelf filter.");
  908. #endif /* CONFIG_LOWSHELF_FILTER */
  909. #endif /* CONFIG_BASS_FILTER || CONFIG LOWSHELF_FILTER */
  910. #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER
  911. static const AVOption treble_highshelf_options[] = {
  912. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  913. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  914. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  915. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  916. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  917. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  918. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  919. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  920. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  921. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  922. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  923. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  924. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  925. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  926. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  927. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  928. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  929. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  930. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  931. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  932. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  933. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  934. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  935. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  936. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  937. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  938. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  939. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  940. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  941. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  942. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  943. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  944. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  945. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  946. {NULL}
  947. };
  948. #if CONFIG_TREBLE_FILTER
  949. #define treble_options treble_highshelf_options
  950. DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
  951. #endif /* CONFIG_TREBLE_FILTER */
  952. #if CONFIG_HIGHSHELF_FILTER
  953. #define highshelf_options treble_highshelf_options
  954. DEFINE_BIQUAD_FILTER(highshelf, "Apply a high shelf filter.");
  955. #endif /* CONFIG_HIGHSHELF_FILTER */
  956. #endif /* CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER */
  957. #if CONFIG_BANDPASS_FILTER
  958. static const AVOption bandpass_options[] = {
  959. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  960. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  961. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  962. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  963. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  964. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  965. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  966. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  967. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  968. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  969. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  970. {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  971. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  972. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  973. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  974. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  975. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  976. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  977. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  978. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  979. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  980. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  981. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  982. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  983. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  984. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  985. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  986. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  987. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  988. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  989. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  990. {NULL}
  991. };
  992. DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
  993. #endif /* CONFIG_BANDPASS_FILTER */
  994. #if CONFIG_BANDREJECT_FILTER
  995. static const AVOption bandreject_options[] = {
  996. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  997. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  998. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  999. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1000. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1001. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1002. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1003. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1004. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1005. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1006. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1007. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1008. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1009. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1010. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1011. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1012. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1013. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1014. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1015. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1016. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1017. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1018. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1019. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1020. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1021. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1022. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1023. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1024. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1025. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1026. {NULL}
  1027. };
  1028. DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
  1029. #endif /* CONFIG_BANDREJECT_FILTER */
  1030. #if CONFIG_LOWPASS_FILTER
  1031. static const AVOption lowpass_options[] = {
  1032. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  1033. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  1034. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1035. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1036. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1037. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1038. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1039. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1040. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1041. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1042. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1043. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1044. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1045. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1046. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1047. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1048. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1049. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1050. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1051. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1052. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1053. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1054. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1055. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1056. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1057. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1058. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1059. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1060. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1061. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1062. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1063. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1064. {NULL}
  1065. };
  1066. DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
  1067. #endif /* CONFIG_LOWPASS_FILTER */
  1068. #if CONFIG_HIGHPASS_FILTER
  1069. static const AVOption highpass_options[] = {
  1070. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1071. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1072. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1073. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1074. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1075. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1076. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1077. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1078. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1079. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1080. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1081. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1082. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1083. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1084. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1085. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1086. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1087. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1088. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1089. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1090. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1091. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1092. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1093. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1094. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1095. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1096. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1097. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1098. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1099. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1100. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1101. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1102. {NULL}
  1103. };
  1104. DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
  1105. #endif /* CONFIG_HIGHPASS_FILTER */
  1106. #if CONFIG_ALLPASS_FILTER
  1107. static const AVOption allpass_options[] = {
  1108. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1109. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1110. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1111. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1112. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1113. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1114. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1115. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1116. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1117. {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  1118. {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  1119. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1120. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1121. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1122. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1123. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1124. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1125. {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1126. {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1127. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1128. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1129. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1130. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1131. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1132. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1133. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1134. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1135. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1136. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1137. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1138. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1139. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1140. {NULL}
  1141. };
  1142. DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
  1143. #endif /* CONFIG_ALLPASS_FILTER */
  1144. #if CONFIG_BIQUAD_FILTER
  1145. static const AVOption biquad_options[] = {
  1146. {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
  1147. {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1148. {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1149. {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1150. {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1151. {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1152. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1153. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1154. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1155. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1156. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1157. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1158. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1159. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1160. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1161. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1162. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1163. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1164. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1165. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1166. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1167. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1168. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1169. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1170. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1171. {NULL}
  1172. };
  1173. DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
  1174. #endif /* CONFIG_BIQUAD_FILTER */