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.

1189 lines
62KB

  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. double gain;
  111. double frequency;
  112. double width;
  113. double mix;
  114. uint64_t channels;
  115. int normalize;
  116. int order;
  117. double a0, a1, a2;
  118. double b0, b1, b2;
  119. double oa0, oa1, oa2;
  120. double ob0, ob1, ob2;
  121. ChanCache *cache;
  122. int block_align;
  123. void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
  124. double *i1, double *i2, double *o1, double *o2,
  125. double b0, double b1, double b2, double a1, double a2, int *clippings,
  126. int disabled);
  127. } BiquadsContext;
  128. static av_cold int init(AVFilterContext *ctx)
  129. {
  130. BiquadsContext *s = ctx->priv;
  131. if (s->filter_type != biquad) {
  132. if (s->frequency <= 0 || s->width <= 0) {
  133. av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
  134. s->frequency, s->width);
  135. return AVERROR(EINVAL);
  136. }
  137. }
  138. return 0;
  139. }
  140. static int query_formats(AVFilterContext *ctx)
  141. {
  142. AVFilterFormats *formats;
  143. AVFilterChannelLayouts *layouts;
  144. static const enum AVSampleFormat sample_fmts[] = {
  145. AV_SAMPLE_FMT_S16P,
  146. AV_SAMPLE_FMT_S32P,
  147. AV_SAMPLE_FMT_FLTP,
  148. AV_SAMPLE_FMT_DBLP,
  149. AV_SAMPLE_FMT_NONE
  150. };
  151. int ret;
  152. layouts = ff_all_channel_counts();
  153. if (!layouts)
  154. return AVERROR(ENOMEM);
  155. ret = ff_set_common_channel_layouts(ctx, layouts);
  156. if (ret < 0)
  157. return ret;
  158. formats = ff_make_format_list(sample_fmts);
  159. if (!formats)
  160. return AVERROR(ENOMEM);
  161. ret = ff_set_common_formats(ctx, formats);
  162. if (ret < 0)
  163. return ret;
  164. formats = ff_all_samplerates();
  165. if (!formats)
  166. return AVERROR(ENOMEM);
  167. return ff_set_common_samplerates(ctx, formats);
  168. }
  169. #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
  170. static void biquad_## name (BiquadsContext *s, \
  171. const void *input, void *output, int len, \
  172. double *in1, double *in2, \
  173. double *out1, double *out2, \
  174. double b0, double b1, double b2, \
  175. double a1, double a2, int *clippings, \
  176. int disabled) \
  177. { \
  178. const type *ibuf = input; \
  179. type *obuf = output; \
  180. double i1 = *in1; \
  181. double i2 = *in2; \
  182. double o1 = *out1; \
  183. double o2 = *out2; \
  184. double wet = s->mix; \
  185. double dry = 1. - wet; \
  186. double out; \
  187. int i; \
  188. a1 = -a1; \
  189. a2 = -a2; \
  190. \
  191. for (i = 0; i+1 < len; i++) { \
  192. o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
  193. i2 = ibuf[i]; \
  194. out = o2 * wet + i2 * dry; \
  195. if (disabled) { \
  196. obuf[i] = i2; \
  197. } else if (need_clipping && out < min) { \
  198. (*clippings)++; \
  199. obuf[i] = min; \
  200. } else if (need_clipping && out > max) { \
  201. (*clippings)++; \
  202. obuf[i] = max; \
  203. } else { \
  204. obuf[i] = out; \
  205. } \
  206. i++; \
  207. o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
  208. i1 = ibuf[i]; \
  209. out = o1 * wet + i1 * dry; \
  210. if (disabled) { \
  211. obuf[i] = i1; \
  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. } \
  222. if (i < len) { \
  223. double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
  224. i2 = i1; \
  225. i1 = ibuf[i]; \
  226. o2 = o1; \
  227. o1 = o0; \
  228. out = o0 * wet + i1 * dry; \
  229. if (disabled) { \
  230. obuf[i] = i1; \
  231. } else if (need_clipping && out < min) { \
  232. (*clippings)++; \
  233. obuf[i] = min; \
  234. } else if (need_clipping && out > max) { \
  235. (*clippings)++; \
  236. obuf[i] = max; \
  237. } else { \
  238. obuf[i] = out; \
  239. } \
  240. } \
  241. *in1 = i1; \
  242. *in2 = i2; \
  243. *out1 = o1; \
  244. *out2 = o2; \
  245. }
  246. BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  247. BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  248. BIQUAD_FILTER(flt, float, -1., 1., 0)
  249. BIQUAD_FILTER(dbl, double, -1., 1., 0)
  250. #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \
  251. static void biquad_dii_## name (BiquadsContext *s, \
  252. const void *input, void *output, int len, \
  253. double *z1, double *z2, \
  254. double *unused1, double *unused2, \
  255. double b0, double b1, double b2, \
  256. double a1, double a2, int *clippings, \
  257. int disabled) \
  258. { \
  259. const type *ibuf = input; \
  260. type *obuf = output; \
  261. double w1 = *z1; \
  262. double w2 = *z2; \
  263. double wet = s->mix; \
  264. double dry = 1. - wet; \
  265. double in, out, w0; \
  266. \
  267. a1 = -a1; \
  268. a2 = -a2; \
  269. \
  270. for (int i = 0; i < len; i++) { \
  271. in = ibuf[i]; \
  272. w0 = in + a1 * w1 + a2 * w2; \
  273. out = b0 * w0 + b1 * w1 + b2 * w2; \
  274. w2 = w1; \
  275. w1 = w0; \
  276. out = out * wet + in * dry; \
  277. if (disabled) { \
  278. obuf[i] = in; \
  279. } else if (need_clipping && out < min) { \
  280. (*clippings)++; \
  281. obuf[i] = min; \
  282. } else if (need_clipping && out > max) { \
  283. (*clippings)++; \
  284. obuf[i] = max; \
  285. } else { \
  286. obuf[i] = out; \
  287. } \
  288. } \
  289. *z1 = w1; \
  290. *z2 = w2; \
  291. }
  292. BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  293. BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  294. BIQUAD_DII_FILTER(flt, float, -1., 1., 0)
  295. BIQUAD_DII_FILTER(dbl, double, -1., 1., 0)
  296. #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \
  297. static void biquad_tdii_## name (BiquadsContext *s, \
  298. const void *input, void *output, int len, \
  299. double *z1, double *z2, \
  300. double *unused1, double *unused2, \
  301. double b0, double b1, double b2, \
  302. double a1, double a2, int *clippings, \
  303. int disabled) \
  304. { \
  305. const type *ibuf = input; \
  306. type *obuf = output; \
  307. double w1 = *z1; \
  308. double w2 = *z2; \
  309. double wet = s->mix; \
  310. double dry = 1. - wet; \
  311. double in, out; \
  312. \
  313. a1 = -a1; \
  314. a2 = -a2; \
  315. \
  316. for (int i = 0; i < len; i++) { \
  317. in = ibuf[i]; \
  318. out = b0 * in + w1; \
  319. w1 = b1 * in + w2 + a1 * out; \
  320. w2 = b2 * in + a2 * out; \
  321. out = out * wet + in * dry; \
  322. if (disabled) { \
  323. obuf[i] = in; \
  324. } else if (need_clipping && out < min) { \
  325. (*clippings)++; \
  326. obuf[i] = min; \
  327. } else if (need_clipping && out > max) { \
  328. (*clippings)++; \
  329. obuf[i] = max; \
  330. } else { \
  331. obuf[i] = out; \
  332. } \
  333. } \
  334. *z1 = w1; \
  335. *z2 = w2; \
  336. }
  337. BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  338. BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  339. BIQUAD_TDII_FILTER(flt, float, -1., 1., 0)
  340. BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0)
  341. #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \
  342. static void biquad_latt_## name (BiquadsContext *s, \
  343. const void *input, void *output, int len, \
  344. double *z1, double *z2, \
  345. double *unused1, double *unused2, \
  346. double v0, double v1, double v2, \
  347. double k0, double k1, int *clippings, \
  348. int disabled) \
  349. { \
  350. const type *ibuf = input; \
  351. type *obuf = output; \
  352. double s0 = *z1; \
  353. double s1 = *z2; \
  354. double wet = s->mix; \
  355. double dry = 1. - wet; \
  356. double in, out; \
  357. double t0, t1; \
  358. \
  359. for (int i = 0; i < len; i++) { \
  360. out = 0.; \
  361. in = ibuf[i]; \
  362. t0 = in - k1 * s0; \
  363. t1 = t0 * k1 + s0; \
  364. s0 = t1; \
  365. out += t1 * v2; \
  366. \
  367. t0 = t0 - k0 * s1; \
  368. t1 = t0 * k0 + s1; \
  369. out += t1 * v1; \
  370. s1 = t1; \
  371. \
  372. out += t0 * v0; \
  373. s0 = s1; \
  374. s1 = t0; \
  375. \
  376. out = out * wet + in * dry; \
  377. if (disabled) { \
  378. obuf[i] = in; \
  379. } else if (need_clipping && out < min) { \
  380. (*clippings)++; \
  381. obuf[i] = min; \
  382. } else if (need_clipping && out > max) { \
  383. (*clippings)++; \
  384. obuf[i] = max; \
  385. } else { \
  386. obuf[i] = out; \
  387. } \
  388. } \
  389. *z1 = s0; \
  390. *z2 = s1; \
  391. }
  392. BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  393. BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  394. BIQUAD_LATT_FILTER(flt, float, -1., 1., 0)
  395. BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0)
  396. static void convert_dir2latt(BiquadsContext *s)
  397. {
  398. double k0, k1, v0, v1, v2;
  399. k1 = s->a2;
  400. k0 = s->a1 / (1. + k1);
  401. v2 = s->b2;
  402. v1 = s->b1 - v2 * s->a1;
  403. v0 = s->b0 - v1 * k0 - v2 * k1;
  404. s->a1 = k0;
  405. s->a2 = k1;
  406. s->b0 = v0;
  407. s->b1 = v1;
  408. s->b2 = v2;
  409. }
  410. static int config_filter(AVFilterLink *outlink, int reset)
  411. {
  412. AVFilterContext *ctx = outlink->src;
  413. BiquadsContext *s = ctx->priv;
  414. AVFilterLink *inlink = ctx->inputs[0];
  415. double A = ff_exp10(s->gain / 40);
  416. double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
  417. double K = tan(w0 / 2.);
  418. double alpha, beta;
  419. if (w0 > M_PI) {
  420. av_log(ctx, AV_LOG_ERROR,
  421. "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
  422. s->frequency, inlink->sample_rate);
  423. return AVERROR(EINVAL);
  424. }
  425. switch (s->width_type) {
  426. case NONE:
  427. alpha = 0.0;
  428. break;
  429. case HERTZ:
  430. alpha = sin(w0) / (2 * s->frequency / s->width);
  431. break;
  432. case KHERTZ:
  433. alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
  434. break;
  435. case OCTAVE:
  436. alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
  437. break;
  438. case QFACTOR:
  439. alpha = sin(w0) / (2 * s->width);
  440. break;
  441. case SLOPE:
  442. alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
  443. break;
  444. default:
  445. av_assert0(0);
  446. }
  447. beta = 2 * sqrt(A);
  448. switch (s->filter_type) {
  449. case biquad:
  450. s->a0 = s->oa0;
  451. s->a1 = s->oa1;
  452. s->a2 = s->oa2;
  453. s->b0 = s->ob0;
  454. s->b1 = s->ob1;
  455. s->b2 = s->ob2;
  456. break;
  457. case equalizer:
  458. s->a0 = 1 + alpha / A;
  459. s->a1 = -2 * cos(w0);
  460. s->a2 = 1 - alpha / A;
  461. s->b0 = 1 + alpha * A;
  462. s->b1 = -2 * cos(w0);
  463. s->b2 = 1 - alpha * A;
  464. break;
  465. case bass:
  466. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  467. case lowshelf:
  468. s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
  469. s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
  470. s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
  471. s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
  472. s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
  473. s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
  474. break;
  475. case treble:
  476. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  477. case highshelf:
  478. s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
  479. s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
  480. s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
  481. s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
  482. s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
  483. s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
  484. break;
  485. case bandpass:
  486. if (s->csg) {
  487. s->a0 = 1 + alpha;
  488. s->a1 = -2 * cos(w0);
  489. s->a2 = 1 - alpha;
  490. s->b0 = sin(w0) / 2;
  491. s->b1 = 0;
  492. s->b2 = -sin(w0) / 2;
  493. } else {
  494. s->a0 = 1 + alpha;
  495. s->a1 = -2 * cos(w0);
  496. s->a2 = 1 - alpha;
  497. s->b0 = alpha;
  498. s->b1 = 0;
  499. s->b2 = -alpha;
  500. }
  501. break;
  502. case bandreject:
  503. s->a0 = 1 + alpha;
  504. s->a1 = -2 * cos(w0);
  505. s->a2 = 1 - alpha;
  506. s->b0 = 1;
  507. s->b1 = -2 * cos(w0);
  508. s->b2 = 1;
  509. break;
  510. case lowpass:
  511. if (s->poles == 1) {
  512. s->a0 = 1;
  513. s->a1 = -exp(-w0);
  514. s->a2 = 0;
  515. s->b0 = 1 + s->a1;
  516. s->b1 = 0;
  517. s->b2 = 0;
  518. } else {
  519. s->a0 = 1 + alpha;
  520. s->a1 = -2 * cos(w0);
  521. s->a2 = 1 - alpha;
  522. s->b0 = (1 - cos(w0)) / 2;
  523. s->b1 = 1 - cos(w0);
  524. s->b2 = (1 - cos(w0)) / 2;
  525. }
  526. break;
  527. case highpass:
  528. if (s->poles == 1) {
  529. s->a0 = 1;
  530. s->a1 = -exp(-w0);
  531. s->a2 = 0;
  532. s->b0 = (1 - s->a1) / 2;
  533. s->b1 = -s->b0;
  534. s->b2 = 0;
  535. } else {
  536. s->a0 = 1 + alpha;
  537. s->a1 = -2 * cos(w0);
  538. s->a2 = 1 - alpha;
  539. s->b0 = (1 + cos(w0)) / 2;
  540. s->b1 = -(1 + cos(w0));
  541. s->b2 = (1 + cos(w0)) / 2;
  542. }
  543. break;
  544. case allpass:
  545. switch (s->order) {
  546. case 1:
  547. s->a0 = 1.;
  548. s->a1 = -(1. - K) / (1. + K);
  549. s->a2 = 0.;
  550. s->b0 = s->a1;
  551. s->b1 = s->a0;
  552. s->b2 = 0.;
  553. break;
  554. case 2:
  555. s->a0 = 1 + alpha;
  556. s->a1 = -2 * cos(w0);
  557. s->a2 = 1 - alpha;
  558. s->b0 = 1 - alpha;
  559. s->b1 = -2 * cos(w0);
  560. s->b2 = 1 + alpha;
  561. break;
  562. }
  563. break;
  564. default:
  565. av_assert0(0);
  566. }
  567. 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);
  568. s->a1 /= s->a0;
  569. s->a2 /= s->a0;
  570. s->b0 /= s->a0;
  571. s->b1 /= s->a0;
  572. s->b2 /= s->a0;
  573. s->a0 /= s->a0;
  574. if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) {
  575. double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2);
  576. s->b0 *= factor;
  577. s->b1 *= factor;
  578. s->b2 *= factor;
  579. }
  580. s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
  581. if (!s->cache)
  582. return AVERROR(ENOMEM);
  583. if (reset)
  584. memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
  585. switch (s->transform_type) {
  586. case DI:
  587. switch (inlink->format) {
  588. case AV_SAMPLE_FMT_S16P:
  589. s->filter = biquad_s16;
  590. break;
  591. case AV_SAMPLE_FMT_S32P:
  592. s->filter = biquad_s32;
  593. break;
  594. case AV_SAMPLE_FMT_FLTP:
  595. s->filter = biquad_flt;
  596. break;
  597. case AV_SAMPLE_FMT_DBLP:
  598. s->filter = biquad_dbl;
  599. break;
  600. default: av_assert0(0);
  601. }
  602. break;
  603. case DII:
  604. switch (inlink->format) {
  605. case AV_SAMPLE_FMT_S16P:
  606. s->filter = biquad_dii_s16;
  607. break;
  608. case AV_SAMPLE_FMT_S32P:
  609. s->filter = biquad_dii_s32;
  610. break;
  611. case AV_SAMPLE_FMT_FLTP:
  612. s->filter = biquad_dii_flt;
  613. break;
  614. case AV_SAMPLE_FMT_DBLP:
  615. s->filter = biquad_dii_dbl;
  616. break;
  617. default: av_assert0(0);
  618. }
  619. break;
  620. case TDII:
  621. switch (inlink->format) {
  622. case AV_SAMPLE_FMT_S16P:
  623. s->filter = biquad_tdii_s16;
  624. break;
  625. case AV_SAMPLE_FMT_S32P:
  626. s->filter = biquad_tdii_s32;
  627. break;
  628. case AV_SAMPLE_FMT_FLTP:
  629. s->filter = biquad_tdii_flt;
  630. break;
  631. case AV_SAMPLE_FMT_DBLP:
  632. s->filter = biquad_tdii_dbl;
  633. break;
  634. default: av_assert0(0);
  635. }
  636. break;
  637. case LATT:
  638. switch (inlink->format) {
  639. case AV_SAMPLE_FMT_S16P:
  640. s->filter = biquad_latt_s16;
  641. break;
  642. case AV_SAMPLE_FMT_S32P:
  643. s->filter = biquad_latt_s32;
  644. break;
  645. case AV_SAMPLE_FMT_FLTP:
  646. s->filter = biquad_latt_flt;
  647. break;
  648. case AV_SAMPLE_FMT_DBLP:
  649. s->filter = biquad_latt_dbl;
  650. break;
  651. default: av_assert0(0);
  652. }
  653. break;
  654. default:
  655. av_assert0(0);
  656. }
  657. s->block_align = av_get_bytes_per_sample(inlink->format);
  658. if (s->transform_type == LATT)
  659. convert_dir2latt(s);
  660. return 0;
  661. }
  662. static int config_output(AVFilterLink *outlink)
  663. {
  664. return config_filter(outlink, 1);
  665. }
  666. typedef struct ThreadData {
  667. AVFrame *in, *out;
  668. } ThreadData;
  669. static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  670. {
  671. AVFilterLink *inlink = ctx->inputs[0];
  672. ThreadData *td = arg;
  673. AVFrame *buf = td->in;
  674. AVFrame *out_buf = td->out;
  675. BiquadsContext *s = ctx->priv;
  676. const int start = (buf->channels * jobnr) / nb_jobs;
  677. const int end = (buf->channels * (jobnr+1)) / nb_jobs;
  678. int ch;
  679. for (ch = start; ch < end; ch++) {
  680. if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
  681. if (buf != out_buf)
  682. memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
  683. buf->nb_samples * s->block_align);
  684. continue;
  685. }
  686. s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
  687. &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
  688. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  689. }
  690. return 0;
  691. }
  692. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  693. {
  694. AVFilterContext *ctx = inlink->dst;
  695. BiquadsContext *s = ctx->priv;
  696. AVFilterLink *outlink = ctx->outputs[0];
  697. AVFrame *out_buf;
  698. ThreadData td;
  699. int ch;
  700. if (av_frame_is_writable(buf)) {
  701. out_buf = buf;
  702. } else {
  703. out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
  704. if (!out_buf) {
  705. av_frame_free(&buf);
  706. return AVERROR(ENOMEM);
  707. }
  708. av_frame_copy_props(out_buf, buf);
  709. }
  710. td.in = buf;
  711. td.out = out_buf;
  712. ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
  713. for (ch = 0; ch < outlink->channels; ch++) {
  714. if (s->cache[ch].clippings > 0)
  715. av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
  716. ch, s->cache[ch].clippings);
  717. s->cache[ch].clippings = 0;
  718. }
  719. if (buf != out_buf)
  720. av_frame_free(&buf);
  721. return ff_filter_frame(outlink, out_buf);
  722. }
  723. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  724. char *res, int res_len, int flags)
  725. {
  726. AVFilterLink *outlink = ctx->outputs[0];
  727. int ret;
  728. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  729. if (ret < 0)
  730. return ret;
  731. return config_filter(outlink, 0);
  732. }
  733. static av_cold void uninit(AVFilterContext *ctx)
  734. {
  735. BiquadsContext *s = ctx->priv;
  736. av_freep(&s->cache);
  737. }
  738. static const AVFilterPad inputs[] = {
  739. {
  740. .name = "default",
  741. .type = AVMEDIA_TYPE_AUDIO,
  742. .filter_frame = filter_frame,
  743. },
  744. { NULL }
  745. };
  746. static const AVFilterPad outputs[] = {
  747. {
  748. .name = "default",
  749. .type = AVMEDIA_TYPE_AUDIO,
  750. .config_props = config_output,
  751. },
  752. { NULL }
  753. };
  754. #define OFFSET(x) offsetof(BiquadsContext, x)
  755. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  756. #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  757. #define DEFINE_BIQUAD_FILTER(name_, description_) \
  758. AVFILTER_DEFINE_CLASS(name_); \
  759. static av_cold int name_##_init(AVFilterContext *ctx) \
  760. { \
  761. BiquadsContext *s = ctx->priv; \
  762. s->class = &name_##_class; \
  763. s->filter_type = name_; \
  764. return init(ctx); \
  765. } \
  766. \
  767. AVFilter ff_af_##name_ = { \
  768. .name = #name_, \
  769. .description = NULL_IF_CONFIG_SMALL(description_), \
  770. .priv_size = sizeof(BiquadsContext), \
  771. .init = name_##_init, \
  772. .uninit = uninit, \
  773. .query_formats = query_formats, \
  774. .inputs = inputs, \
  775. .outputs = outputs, \
  776. .priv_class = &name_##_class, \
  777. .process_command = process_command, \
  778. .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
  779. }
  780. #if CONFIG_EQUALIZER_FILTER
  781. static const AVOption equalizer_options[] = {
  782. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  783. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  784. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  785. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  786. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  787. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  788. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  789. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  790. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  791. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  792. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  793. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  794. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  795. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  796. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  797. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  798. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  799. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  800. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  801. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  802. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  803. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  804. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  805. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  806. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  807. {NULL}
  808. };
  809. DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
  810. #endif /* CONFIG_EQUALIZER_FILTER */
  811. #if CONFIG_BASS_FILTER
  812. static const AVOption bass_options[] = {
  813. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  814. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  815. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  816. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  817. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  818. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  819. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  820. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  821. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  822. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  823. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  824. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  825. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  826. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  827. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  828. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  829. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  830. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  831. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  832. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  833. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  834. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  835. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  836. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  837. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  838. {NULL}
  839. };
  840. DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
  841. #endif /* CONFIG_BASS_FILTER */
  842. #if CONFIG_TREBLE_FILTER
  843. static const AVOption treble_options[] = {
  844. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  845. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  846. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  847. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  848. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  849. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  850. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  851. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  852. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  853. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  854. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  855. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  856. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  857. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  858. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  859. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  860. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  861. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  862. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  863. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  864. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  865. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  866. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  867. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  868. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  869. {NULL}
  870. };
  871. DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
  872. #endif /* CONFIG_TREBLE_FILTER */
  873. #if CONFIG_BANDPASS_FILTER
  874. static const AVOption bandpass_options[] = {
  875. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  876. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  877. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  878. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  879. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  880. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  881. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  882. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  883. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  884. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  885. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  886. {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  887. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  888. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  889. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  890. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  891. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  892. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  893. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  894. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  895. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  896. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  897. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  898. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  899. {NULL}
  900. };
  901. DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
  902. #endif /* CONFIG_BANDPASS_FILTER */
  903. #if CONFIG_BANDREJECT_FILTER
  904. static const AVOption bandreject_options[] = {
  905. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  906. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  907. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  908. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  909. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  910. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  911. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  912. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  913. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  914. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  915. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  916. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  917. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  918. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  919. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  920. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  921. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  922. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  923. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  924. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  925. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  926. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  927. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  928. {NULL}
  929. };
  930. DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
  931. #endif /* CONFIG_BANDREJECT_FILTER */
  932. #if CONFIG_LOWPASS_FILTER
  933. static const AVOption lowpass_options[] = {
  934. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  935. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  936. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  937. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  938. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  939. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  940. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  941. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  942. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  943. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  944. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  945. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  946. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  947. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  948. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  949. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  950. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  951. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  952. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  953. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  954. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  955. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  956. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  957. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  958. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  959. {NULL}
  960. };
  961. DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
  962. #endif /* CONFIG_LOWPASS_FILTER */
  963. #if CONFIG_HIGHPASS_FILTER
  964. static const AVOption highpass_options[] = {
  965. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  966. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  967. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  968. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  969. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  970. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  971. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  972. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  973. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  974. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  975. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  976. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  977. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  978. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  979. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  980. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  981. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  982. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  983. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  984. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  985. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  986. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  987. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  988. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  989. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  990. {NULL}
  991. };
  992. DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
  993. #endif /* CONFIG_HIGHPASS_FILTER */
  994. #if CONFIG_ALLPASS_FILTER
  995. static const AVOption allpass_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=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  999. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, 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 filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  1006. {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 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. {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1014. {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1015. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1016. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1017. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1018. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1019. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1020. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1021. {NULL}
  1022. };
  1023. DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
  1024. #endif /* CONFIG_ALLPASS_FILTER */
  1025. #if CONFIG_LOWSHELF_FILTER
  1026. static const AVOption lowshelf_options[] = {
  1027. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  1028. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  1029. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1030. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1031. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1032. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1033. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1034. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1035. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1036. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1037. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1038. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1039. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1040. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1041. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1042. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1043. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1044. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1045. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1046. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1047. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1048. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1049. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1050. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1051. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1052. {NULL}
  1053. };
  1054. DEFINE_BIQUAD_FILTER(lowshelf, "Apply a low shelf filter.");
  1055. #endif /* CONFIG_LOWSHELF_FILTER */
  1056. #if CONFIG_HIGHSHELF_FILTER
  1057. static const AVOption highshelf_options[] = {
  1058. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1059. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1060. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1061. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1062. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1063. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1064. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1065. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1066. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1067. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1068. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1069. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1070. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1071. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1072. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1073. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1074. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1075. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1076. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1077. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1078. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1079. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1080. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1081. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1082. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1083. {NULL}
  1084. };
  1085. DEFINE_BIQUAD_FILTER(highshelf, "Apply a high shelf filter.");
  1086. #endif /* CONFIG_HIGHSHELF_FILTER */
  1087. #if CONFIG_BIQUAD_FILTER
  1088. static const AVOption biquad_options[] = {
  1089. {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
  1090. {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1091. {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1092. {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1093. {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1094. {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1095. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1096. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1097. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1098. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  1099. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1100. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1101. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1102. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1103. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1104. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1105. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1106. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1107. {NULL}
  1108. };
  1109. DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
  1110. #endif /* CONFIG_BIQUAD_FILTER */