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.

897 lines
41KB

  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. typedef struct ChanCache {
  92. double i1, i2;
  93. double o1, o2;
  94. int clippings;
  95. } ChanCache;
  96. typedef struct BiquadsContext {
  97. const AVClass *class;
  98. enum FilterType filter_type;
  99. int width_type;
  100. int poles;
  101. int csg;
  102. double gain;
  103. double frequency;
  104. double width;
  105. uint64_t channels;
  106. double a0, a1, a2;
  107. double b0, b1, b2;
  108. ChanCache *cache;
  109. int block_align;
  110. void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
  111. double *i1, double *i2, double *o1, double *o2,
  112. double b0, double b1, double b2, double a1, double a2, int *clippings,
  113. int disabled);
  114. } BiquadsContext;
  115. static av_cold int init(AVFilterContext *ctx)
  116. {
  117. BiquadsContext *s = ctx->priv;
  118. if (s->filter_type != biquad) {
  119. if (s->frequency <= 0 || s->width <= 0) {
  120. av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
  121. s->frequency, s->width);
  122. return AVERROR(EINVAL);
  123. }
  124. }
  125. return 0;
  126. }
  127. static int query_formats(AVFilterContext *ctx)
  128. {
  129. AVFilterFormats *formats;
  130. AVFilterChannelLayouts *layouts;
  131. static const enum AVSampleFormat sample_fmts[] = {
  132. AV_SAMPLE_FMT_S16P,
  133. AV_SAMPLE_FMT_S32P,
  134. AV_SAMPLE_FMT_FLTP,
  135. AV_SAMPLE_FMT_DBLP,
  136. AV_SAMPLE_FMT_NONE
  137. };
  138. int ret;
  139. layouts = ff_all_channel_counts();
  140. if (!layouts)
  141. return AVERROR(ENOMEM);
  142. ret = ff_set_common_channel_layouts(ctx, layouts);
  143. if (ret < 0)
  144. return ret;
  145. formats = ff_make_format_list(sample_fmts);
  146. if (!formats)
  147. return AVERROR(ENOMEM);
  148. ret = ff_set_common_formats(ctx, formats);
  149. if (ret < 0)
  150. return ret;
  151. formats = ff_all_samplerates();
  152. if (!formats)
  153. return AVERROR(ENOMEM);
  154. return ff_set_common_samplerates(ctx, formats);
  155. }
  156. #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
  157. static void biquad_## name (BiquadsContext *s, \
  158. const void *input, void *output, int len, \
  159. double *in1, double *in2, \
  160. double *out1, double *out2, \
  161. double b0, double b1, double b2, \
  162. double a1, double a2, int *clippings, \
  163. int disabled) \
  164. { \
  165. const type *ibuf = input; \
  166. type *obuf = output; \
  167. double i1 = *in1; \
  168. double i2 = *in2; \
  169. double o1 = *out1; \
  170. double o2 = *out2; \
  171. int i; \
  172. a1 = -a1; \
  173. a2 = -a2; \
  174. \
  175. for (i = 0; i+1 < len; i++) { \
  176. o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
  177. i2 = ibuf[i]; \
  178. if (disabled) { \
  179. obuf[i] = i2; \
  180. } else if (need_clipping && o2 < min) { \
  181. (*clippings)++; \
  182. obuf[i] = min; \
  183. } else if (need_clipping && o2 > max) { \
  184. (*clippings)++; \
  185. obuf[i] = max; \
  186. } else { \
  187. obuf[i] = o2; \
  188. } \
  189. i++; \
  190. o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
  191. i1 = ibuf[i]; \
  192. if (disabled) { \
  193. obuf[i] = i1; \
  194. } else if (need_clipping && o1 < min) { \
  195. (*clippings)++; \
  196. obuf[i] = min; \
  197. } else if (need_clipping && o1 > max) { \
  198. (*clippings)++; \
  199. obuf[i] = max; \
  200. } else { \
  201. obuf[i] = o1; \
  202. } \
  203. } \
  204. if (i < len) { \
  205. double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
  206. i2 = i1; \
  207. i1 = ibuf[i]; \
  208. o2 = o1; \
  209. o1 = o0; \
  210. if (disabled) { \
  211. obuf[i] = i1; \
  212. } else if (need_clipping && o0 < min) { \
  213. (*clippings)++; \
  214. obuf[i] = min; \
  215. } else if (need_clipping && o0 > max) { \
  216. (*clippings)++; \
  217. obuf[i] = max; \
  218. } else { \
  219. obuf[i] = o0; \
  220. } \
  221. } \
  222. *in1 = i1; \
  223. *in2 = i2; \
  224. *out1 = o1; \
  225. *out2 = o2; \
  226. }
  227. BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  228. BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  229. BIQUAD_FILTER(flt, float, -1., 1., 0)
  230. BIQUAD_FILTER(dbl, double, -1., 1., 0)
  231. static int config_filter(AVFilterLink *outlink, int reset)
  232. {
  233. AVFilterContext *ctx = outlink->src;
  234. BiquadsContext *s = ctx->priv;
  235. AVFilterLink *inlink = ctx->inputs[0];
  236. double A = ff_exp10(s->gain / 40);
  237. double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
  238. double alpha, beta;
  239. if (w0 > M_PI) {
  240. av_log(ctx, AV_LOG_ERROR,
  241. "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
  242. s->frequency, inlink->sample_rate);
  243. return AVERROR(EINVAL);
  244. }
  245. switch (s->width_type) {
  246. case NONE:
  247. alpha = 0.0;
  248. break;
  249. case HERTZ:
  250. alpha = sin(w0) / (2 * s->frequency / s->width);
  251. break;
  252. case KHERTZ:
  253. alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
  254. break;
  255. case OCTAVE:
  256. alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
  257. break;
  258. case QFACTOR:
  259. alpha = sin(w0) / (2 * s->width);
  260. break;
  261. case SLOPE:
  262. alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
  263. break;
  264. default:
  265. av_assert0(0);
  266. }
  267. beta = 2 * sqrt(A);
  268. switch (s->filter_type) {
  269. case biquad:
  270. break;
  271. case equalizer:
  272. s->a0 = 1 + alpha / A;
  273. s->a1 = -2 * cos(w0);
  274. s->a2 = 1 - alpha / A;
  275. s->b0 = 1 + alpha * A;
  276. s->b1 = -2 * cos(w0);
  277. s->b2 = 1 - alpha * A;
  278. break;
  279. case bass:
  280. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  281. case lowshelf:
  282. s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
  283. s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
  284. s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
  285. s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
  286. s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
  287. s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
  288. break;
  289. case treble:
  290. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  291. case highshelf:
  292. s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
  293. s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
  294. s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
  295. s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
  296. s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
  297. s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
  298. break;
  299. case bandpass:
  300. if (s->csg) {
  301. s->a0 = 1 + alpha;
  302. s->a1 = -2 * cos(w0);
  303. s->a2 = 1 - alpha;
  304. s->b0 = sin(w0) / 2;
  305. s->b1 = 0;
  306. s->b2 = -sin(w0) / 2;
  307. } else {
  308. s->a0 = 1 + alpha;
  309. s->a1 = -2 * cos(w0);
  310. s->a2 = 1 - alpha;
  311. s->b0 = alpha;
  312. s->b1 = 0;
  313. s->b2 = -alpha;
  314. }
  315. break;
  316. case bandreject:
  317. s->a0 = 1 + alpha;
  318. s->a1 = -2 * cos(w0);
  319. s->a2 = 1 - alpha;
  320. s->b0 = 1;
  321. s->b1 = -2 * cos(w0);
  322. s->b2 = 1;
  323. break;
  324. case lowpass:
  325. if (s->poles == 1) {
  326. s->a0 = 1;
  327. s->a1 = -exp(-w0);
  328. s->a2 = 0;
  329. s->b0 = 1 + s->a1;
  330. s->b1 = 0;
  331. s->b2 = 0;
  332. } else {
  333. s->a0 = 1 + alpha;
  334. s->a1 = -2 * cos(w0);
  335. s->a2 = 1 - alpha;
  336. s->b0 = (1 - cos(w0)) / 2;
  337. s->b1 = 1 - cos(w0);
  338. s->b2 = (1 - cos(w0)) / 2;
  339. }
  340. break;
  341. case highpass:
  342. if (s->poles == 1) {
  343. s->a0 = 1;
  344. s->a1 = -exp(-w0);
  345. s->a2 = 0;
  346. s->b0 = (1 - s->a1) / 2;
  347. s->b1 = -s->b0;
  348. s->b2 = 0;
  349. } else {
  350. s->a0 = 1 + alpha;
  351. s->a1 = -2 * cos(w0);
  352. s->a2 = 1 - alpha;
  353. s->b0 = (1 + cos(w0)) / 2;
  354. s->b1 = -(1 + cos(w0));
  355. s->b2 = (1 + cos(w0)) / 2;
  356. }
  357. break;
  358. case allpass:
  359. s->a0 = 1 + alpha;
  360. s->a1 = -2 * cos(w0);
  361. s->a2 = 1 - alpha;
  362. s->b0 = 1 - alpha;
  363. s->b1 = -2 * cos(w0);
  364. s->b2 = 1 + alpha;
  365. break;
  366. default:
  367. av_assert0(0);
  368. }
  369. 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);
  370. s->a1 /= s->a0;
  371. s->a2 /= s->a0;
  372. s->b0 /= s->a0;
  373. s->b1 /= s->a0;
  374. s->b2 /= s->a0;
  375. s->a0 /= s->a0;
  376. s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
  377. if (!s->cache)
  378. return AVERROR(ENOMEM);
  379. if (reset)
  380. memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
  381. switch (inlink->format) {
  382. case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
  383. case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
  384. case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
  385. case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
  386. default: av_assert0(0);
  387. }
  388. s->block_align = av_get_bytes_per_sample(inlink->format);
  389. return 0;
  390. }
  391. static int config_output(AVFilterLink *outlink)
  392. {
  393. return config_filter(outlink, 1);
  394. }
  395. typedef struct ThreadData {
  396. AVFrame *in, *out;
  397. } ThreadData;
  398. static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  399. {
  400. AVFilterLink *inlink = ctx->inputs[0];
  401. ThreadData *td = arg;
  402. AVFrame *buf = td->in;
  403. AVFrame *out_buf = td->out;
  404. BiquadsContext *s = ctx->priv;
  405. const int start = (buf->channels * jobnr) / nb_jobs;
  406. const int end = (buf->channels * (jobnr+1)) / nb_jobs;
  407. int ch;
  408. for (ch = start; ch < end; ch++) {
  409. if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
  410. if (buf != out_buf)
  411. memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
  412. buf->nb_samples * s->block_align);
  413. continue;
  414. }
  415. s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
  416. &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
  417. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  418. }
  419. return 0;
  420. }
  421. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  422. {
  423. AVFilterContext *ctx = inlink->dst;
  424. BiquadsContext *s = ctx->priv;
  425. AVFilterLink *outlink = ctx->outputs[0];
  426. AVFrame *out_buf;
  427. ThreadData td;
  428. int ch;
  429. if (av_frame_is_writable(buf)) {
  430. out_buf = buf;
  431. } else {
  432. out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
  433. if (!out_buf) {
  434. av_frame_free(&buf);
  435. return AVERROR(ENOMEM);
  436. }
  437. av_frame_copy_props(out_buf, buf);
  438. }
  439. td.in = buf;
  440. td.out = out_buf;
  441. ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
  442. for (ch = 0; ch < outlink->channels; ch++) {
  443. if (s->cache[ch].clippings > 0)
  444. av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
  445. ch, s->cache[ch].clippings);
  446. s->cache[ch].clippings = 0;
  447. }
  448. if (buf != out_buf)
  449. av_frame_free(&buf);
  450. return ff_filter_frame(outlink, out_buf);
  451. }
  452. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  453. char *res, int res_len, int flags)
  454. {
  455. BiquadsContext *s = ctx->priv;
  456. AVFilterLink *outlink = ctx->outputs[0];
  457. if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
  458. (s->filter_type == equalizer ||
  459. s->filter_type == lowshelf ||
  460. s->filter_type == highshelf ||
  461. s->filter_type == bass ||
  462. s->filter_type == treble ||
  463. s->filter_type == bandpass ||
  464. s->filter_type == bandreject||
  465. s->filter_type == lowpass ||
  466. s->filter_type == highpass ||
  467. s->filter_type == allpass)) {
  468. double freq;
  469. if (sscanf(args, "%lf", &freq) != 1) {
  470. av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
  471. return AVERROR(EINVAL);
  472. }
  473. s->frequency = freq;
  474. } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
  475. (s->filter_type == equalizer ||
  476. s->filter_type == lowshelf ||
  477. s->filter_type == highshelf ||
  478. s->filter_type == bass ||
  479. s->filter_type == treble)) {
  480. double gain;
  481. if (sscanf(args, "%lf", &gain) != 1) {
  482. av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
  483. return AVERROR(EINVAL);
  484. }
  485. s->gain = gain;
  486. } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
  487. (s->filter_type == equalizer ||
  488. s->filter_type == lowshelf ||
  489. s->filter_type == highshelf ||
  490. s->filter_type == bass ||
  491. s->filter_type == treble ||
  492. s->filter_type == bandpass ||
  493. s->filter_type == bandreject||
  494. s->filter_type == lowpass ||
  495. s->filter_type == highpass ||
  496. s->filter_type == allpass)) {
  497. double width;
  498. if (sscanf(args, "%lf", &width) != 1) {
  499. av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
  500. return AVERROR(EINVAL);
  501. }
  502. s->width = width;
  503. } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
  504. (s->filter_type == equalizer ||
  505. s->filter_type == lowshelf ||
  506. s->filter_type == highshelf ||
  507. s->filter_type == bass ||
  508. s->filter_type == treble ||
  509. s->filter_type == bandpass ||
  510. s->filter_type == bandreject||
  511. s->filter_type == lowpass ||
  512. s->filter_type == highpass ||
  513. s->filter_type == allpass)) {
  514. char width_type;
  515. if (sscanf(args, "%c", &width_type) != 1) {
  516. av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
  517. return AVERROR(EINVAL);
  518. }
  519. switch (width_type) {
  520. case 'h': width_type = HERTZ; break;
  521. case 'q': width_type = QFACTOR; break;
  522. case 'o': width_type = OCTAVE; break;
  523. case 's': width_type = SLOPE; break;
  524. case 'k': width_type = KHERTZ; break;
  525. default:
  526. av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
  527. return AVERROR(EINVAL);
  528. }
  529. s->width_type = width_type;
  530. } else if ((!strcmp(cmd, "a0") ||
  531. !strcmp(cmd, "a1") ||
  532. !strcmp(cmd, "a2") ||
  533. !strcmp(cmd, "b0") ||
  534. !strcmp(cmd, "b1") ||
  535. !strcmp(cmd, "b2")) &&
  536. s->filter_type == biquad) {
  537. double value;
  538. if (sscanf(args, "%lf", &value) != 1) {
  539. av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
  540. return AVERROR(EINVAL);
  541. }
  542. if (!strcmp(cmd, "a0"))
  543. s->a0 = value;
  544. else if (!strcmp(cmd, "a1"))
  545. s->a1 = value;
  546. else if (!strcmp(cmd, "a2"))
  547. s->a2 = value;
  548. else if (!strcmp(cmd, "b0"))
  549. s->b0 = value;
  550. else if (!strcmp(cmd, "b1"))
  551. s->b1 = value;
  552. else if (!strcmp(cmd, "b2"))
  553. s->b2 = value;
  554. }
  555. return config_filter(outlink, 0);
  556. }
  557. static av_cold void uninit(AVFilterContext *ctx)
  558. {
  559. BiquadsContext *s = ctx->priv;
  560. av_freep(&s->cache);
  561. }
  562. static const AVFilterPad inputs[] = {
  563. {
  564. .name = "default",
  565. .type = AVMEDIA_TYPE_AUDIO,
  566. .filter_frame = filter_frame,
  567. },
  568. { NULL }
  569. };
  570. static const AVFilterPad outputs[] = {
  571. {
  572. .name = "default",
  573. .type = AVMEDIA_TYPE_AUDIO,
  574. .config_props = config_output,
  575. },
  576. { NULL }
  577. };
  578. #define OFFSET(x) offsetof(BiquadsContext, x)
  579. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  580. #define DEFINE_BIQUAD_FILTER(name_, description_) \
  581. AVFILTER_DEFINE_CLASS(name_); \
  582. static av_cold int name_##_init(AVFilterContext *ctx) \
  583. { \
  584. BiquadsContext *s = ctx->priv; \
  585. s->class = &name_##_class; \
  586. s->filter_type = name_; \
  587. return init(ctx); \
  588. } \
  589. \
  590. AVFilter ff_af_##name_ = { \
  591. .name = #name_, \
  592. .description = NULL_IF_CONFIG_SMALL(description_), \
  593. .priv_size = sizeof(BiquadsContext), \
  594. .init = name_##_init, \
  595. .uninit = uninit, \
  596. .query_formats = query_formats, \
  597. .inputs = inputs, \
  598. .outputs = outputs, \
  599. .priv_class = &name_##_class, \
  600. .process_command = process_command, \
  601. .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
  602. }
  603. #if CONFIG_EQUALIZER_FILTER
  604. static const AVOption equalizer_options[] = {
  605. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  606. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  607. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  608. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  609. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  610. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  611. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  612. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  613. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  614. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  615. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  616. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  617. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  618. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  619. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  620. {NULL}
  621. };
  622. DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
  623. #endif /* CONFIG_EQUALIZER_FILTER */
  624. #if CONFIG_BASS_FILTER
  625. static const AVOption bass_options[] = {
  626. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  627. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  628. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  629. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  630. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  631. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  632. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  633. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  634. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  635. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  636. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  637. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  638. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  639. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  640. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  641. {NULL}
  642. };
  643. DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
  644. #endif /* CONFIG_BASS_FILTER */
  645. #if CONFIG_TREBLE_FILTER
  646. static const AVOption treble_options[] = {
  647. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  648. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  649. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  650. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  651. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  652. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  653. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  654. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  655. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  656. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  657. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  658. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  659. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  660. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  661. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  662. {NULL}
  663. };
  664. DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
  665. #endif /* CONFIG_TREBLE_FILTER */
  666. #if CONFIG_BANDPASS_FILTER
  667. static const AVOption bandpass_options[] = {
  668. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  669. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  670. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  671. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  672. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  673. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  674. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  675. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  676. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  677. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  678. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  679. {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  680. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  681. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  682. {NULL}
  683. };
  684. DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
  685. #endif /* CONFIG_BANDPASS_FILTER */
  686. #if CONFIG_BANDREJECT_FILTER
  687. static const AVOption bandreject_options[] = {
  688. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  689. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  690. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  691. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  692. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  693. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  694. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  695. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  696. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  697. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  698. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  699. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  700. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  701. {NULL}
  702. };
  703. DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
  704. #endif /* CONFIG_BANDREJECT_FILTER */
  705. #if CONFIG_LOWPASS_FILTER
  706. static const AVOption lowpass_options[] = {
  707. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  708. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  709. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  710. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  711. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  712. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  713. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  714. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  715. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  716. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  717. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  718. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  719. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  720. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  721. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  722. {NULL}
  723. };
  724. DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
  725. #endif /* CONFIG_LOWPASS_FILTER */
  726. #if CONFIG_HIGHPASS_FILTER
  727. static const AVOption highpass_options[] = {
  728. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  729. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  730. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  731. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  732. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  733. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  734. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  735. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  736. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  737. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  738. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  739. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  740. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  741. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  742. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  743. {NULL}
  744. };
  745. DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
  746. #endif /* CONFIG_HIGHPASS_FILTER */
  747. #if CONFIG_ALLPASS_FILTER
  748. static const AVOption allpass_options[] = {
  749. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  750. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  751. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  752. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  753. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  754. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  755. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  756. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  757. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  758. {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  759. {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  760. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  761. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  762. {NULL}
  763. };
  764. DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
  765. #endif /* CONFIG_ALLPASS_FILTER */
  766. #if CONFIG_LOWSHELF_FILTER
  767. static const AVOption lowshelf_options[] = {
  768. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  769. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  770. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  771. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  772. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  773. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  774. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  775. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  776. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  777. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  778. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  779. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  780. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  781. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  782. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  783. {NULL}
  784. };
  785. DEFINE_BIQUAD_FILTER(lowshelf, "Apply a low shelf filter.");
  786. #endif /* CONFIG_LOWSHELF_FILTER */
  787. #if CONFIG_HIGHSHELF_FILTER
  788. static const AVOption highshelf_options[] = {
  789. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  790. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  791. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  792. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  793. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  794. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  795. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  796. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  797. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  798. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  799. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  800. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  801. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  802. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  803. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  804. {NULL}
  805. };
  806. DEFINE_BIQUAD_FILTER(highshelf, "Apply a high shelf filter.");
  807. #endif /* CONFIG_HIGHSHELF_FILTER */
  808. #if CONFIG_BIQUAD_FILTER
  809. static const AVOption biquad_options[] = {
  810. {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
  811. {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  812. {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  813. {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  814. {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  815. {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  816. {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  817. {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
  818. {NULL}
  819. };
  820. DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
  821. #endif /* CONFIG_BIQUAD_FILTER */