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.

889 lines
40KB

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