af_firequalizer.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. /*
  2. * Copyright (c) 2016 Muhammad Faiz <mfcc64@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/opt.h"
  21. #include "libavutil/eval.h"
  22. #include "libavutil/avassert.h"
  23. #include "libavcodec/avfft.h"
  24. #include "avfilter.h"
  25. #include "internal.h"
  26. #include "audio.h"
  27. #define RDFT_BITS_MIN 4
  28. #define RDFT_BITS_MAX 16
  29. enum WindowFunc {
  30. WFUNC_RECTANGULAR,
  31. WFUNC_HANN,
  32. WFUNC_HAMMING,
  33. WFUNC_BLACKMAN,
  34. WFUNC_NUTTALL3,
  35. WFUNC_MNUTTALL3,
  36. WFUNC_NUTTALL,
  37. WFUNC_BNUTTALL,
  38. WFUNC_BHARRIS,
  39. WFUNC_TUKEY,
  40. NB_WFUNC
  41. };
  42. enum Scale {
  43. SCALE_LINLIN,
  44. SCALE_LINLOG,
  45. SCALE_LOGLIN,
  46. SCALE_LOGLOG,
  47. NB_SCALE
  48. };
  49. #define NB_GAIN_ENTRY_MAX 4096
  50. typedef struct GainEntry {
  51. double freq;
  52. double gain;
  53. } GainEntry;
  54. typedef struct OverlapIndex {
  55. int buf_idx;
  56. int overlap_idx;
  57. } OverlapIndex;
  58. typedef struct FIREqualizerContext {
  59. const AVClass *class;
  60. RDFTContext *analysis_rdft;
  61. RDFTContext *analysis_irdft;
  62. RDFTContext *rdft;
  63. RDFTContext *irdft;
  64. FFTContext *fft_ctx;
  65. RDFTContext *cepstrum_rdft;
  66. RDFTContext *cepstrum_irdft;
  67. int analysis_rdft_len;
  68. int rdft_len;
  69. int cepstrum_len;
  70. float *analysis_buf;
  71. float *dump_buf;
  72. float *kernel_tmp_buf;
  73. float *kernel_buf;
  74. float *cepstrum_buf;
  75. float *conv_buf;
  76. OverlapIndex *conv_idx;
  77. int fir_len;
  78. int nsamples_max;
  79. int64_t next_pts;
  80. int frame_nsamples_max;
  81. int remaining;
  82. char *gain_cmd;
  83. char *gain_entry_cmd;
  84. const char *gain;
  85. const char *gain_entry;
  86. double delay;
  87. double accuracy;
  88. int wfunc;
  89. int fixed;
  90. int multi;
  91. int zero_phase;
  92. int scale;
  93. char *dumpfile;
  94. int dumpscale;
  95. int fft2;
  96. int min_phase;
  97. int nb_gain_entry;
  98. int gain_entry_err;
  99. GainEntry gain_entry_tbl[NB_GAIN_ENTRY_MAX];
  100. } FIREqualizerContext;
  101. #define OFFSET(x) offsetof(FIREqualizerContext, x)
  102. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  103. static const AVOption firequalizer_options[] = {
  104. { "gain", "set gain curve", OFFSET(gain), AV_OPT_TYPE_STRING, { .str = "gain_interpolate(f)" }, 0, 0, FLAGS },
  105. { "gain_entry", "set gain entry", OFFSET(gain_entry), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
  106. { "delay", "set delay", OFFSET(delay), AV_OPT_TYPE_DOUBLE, { .dbl = 0.01 }, 0.0, 1e10, FLAGS },
  107. { "accuracy", "set accuracy", OFFSET(accuracy), AV_OPT_TYPE_DOUBLE, { .dbl = 5.0 }, 0.0, 1e10, FLAGS },
  108. { "wfunc", "set window function", OFFSET(wfunc), AV_OPT_TYPE_INT, { .i64 = WFUNC_HANN }, 0, NB_WFUNC-1, FLAGS, "wfunc" },
  109. { "rectangular", "rectangular window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_RECTANGULAR }, 0, 0, FLAGS, "wfunc" },
  110. { "hann", "hann window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HANN }, 0, 0, FLAGS, "wfunc" },
  111. { "hamming", "hamming window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HAMMING }, 0, 0, FLAGS, "wfunc" },
  112. { "blackman", "blackman window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BLACKMAN }, 0, 0, FLAGS, "wfunc" },
  113. { "nuttall3", "3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL3 }, 0, 0, FLAGS, "wfunc" },
  114. { "mnuttall3", "minimum 3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_MNUTTALL3 }, 0, 0, FLAGS, "wfunc" },
  115. { "nuttall", "nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL }, 0, 0, FLAGS, "wfunc" },
  116. { "bnuttall", "blackman-nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BNUTTALL }, 0, 0, FLAGS, "wfunc" },
  117. { "bharris", "blackman-harris window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BHARRIS }, 0, 0, FLAGS, "wfunc" },
  118. { "tukey", "tukey window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_TUKEY }, 0, 0, FLAGS, "wfunc" },
  119. { "fixed", "set fixed frame samples", OFFSET(fixed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  120. { "multi", "set multi channels mode", OFFSET(multi), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  121. { "zero_phase", "set zero phase mode", OFFSET(zero_phase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  122. { "scale", "set gain scale", OFFSET(scale), AV_OPT_TYPE_INT, { .i64 = SCALE_LINLOG }, 0, NB_SCALE-1, FLAGS, "scale" },
  123. { "linlin", "linear-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLIN }, 0, 0, FLAGS, "scale" },
  124. { "linlog", "linear-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLOG }, 0, 0, FLAGS, "scale" },
  125. { "loglin", "logarithmic-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLIN }, 0, 0, FLAGS, "scale" },
  126. { "loglog", "logarithmic-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLOG }, 0, 0, FLAGS, "scale" },
  127. { "dumpfile", "set dump file", OFFSET(dumpfile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
  128. { "dumpscale", "set dump scale", OFFSET(dumpscale), AV_OPT_TYPE_INT, { .i64 = SCALE_LINLOG }, 0, NB_SCALE-1, FLAGS, "scale" },
  129. { "fft2", "set 2-channels fft", OFFSET(fft2), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  130. { "min_phase", "set minimum phase mode", OFFSET(min_phase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  131. { NULL }
  132. };
  133. AVFILTER_DEFINE_CLASS(firequalizer);
  134. static void common_uninit(FIREqualizerContext *s)
  135. {
  136. av_rdft_end(s->analysis_rdft);
  137. av_rdft_end(s->analysis_irdft);
  138. av_rdft_end(s->rdft);
  139. av_rdft_end(s->irdft);
  140. av_fft_end(s->fft_ctx);
  141. av_rdft_end(s->cepstrum_rdft);
  142. av_rdft_end(s->cepstrum_irdft);
  143. s->analysis_rdft = s->analysis_irdft = s->rdft = s->irdft = NULL;
  144. s->fft_ctx = NULL;
  145. s->cepstrum_rdft = NULL;
  146. s->cepstrum_irdft = NULL;
  147. av_freep(&s->analysis_buf);
  148. av_freep(&s->dump_buf);
  149. av_freep(&s->kernel_tmp_buf);
  150. av_freep(&s->kernel_buf);
  151. av_freep(&s->cepstrum_buf);
  152. av_freep(&s->conv_buf);
  153. av_freep(&s->conv_idx);
  154. }
  155. static av_cold void uninit(AVFilterContext *ctx)
  156. {
  157. FIREqualizerContext *s = ctx->priv;
  158. common_uninit(s);
  159. av_freep(&s->gain_cmd);
  160. av_freep(&s->gain_entry_cmd);
  161. }
  162. static int query_formats(AVFilterContext *ctx)
  163. {
  164. AVFilterChannelLayouts *layouts;
  165. AVFilterFormats *formats;
  166. static const enum AVSampleFormat sample_fmts[] = {
  167. AV_SAMPLE_FMT_FLTP,
  168. AV_SAMPLE_FMT_NONE
  169. };
  170. int ret;
  171. layouts = ff_all_channel_counts();
  172. if (!layouts)
  173. return AVERROR(ENOMEM);
  174. ret = ff_set_common_channel_layouts(ctx, layouts);
  175. if (ret < 0)
  176. return ret;
  177. formats = ff_make_format_list(sample_fmts);
  178. if (!formats)
  179. return AVERROR(ENOMEM);
  180. ret = ff_set_common_formats(ctx, formats);
  181. if (ret < 0)
  182. return ret;
  183. formats = ff_all_samplerates();
  184. if (!formats)
  185. return AVERROR(ENOMEM);
  186. return ff_set_common_samplerates(ctx, formats);
  187. }
  188. static void fast_convolute(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, float *av_restrict conv_buf,
  189. OverlapIndex *av_restrict idx, float *av_restrict data, int nsamples)
  190. {
  191. if (nsamples <= s->nsamples_max) {
  192. float *buf = conv_buf + idx->buf_idx * s->rdft_len;
  193. float *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
  194. int center = s->fir_len/2;
  195. int k;
  196. memset(buf, 0, center * sizeof(*data));
  197. memcpy(buf + center, data, nsamples * sizeof(*data));
  198. memset(buf + center + nsamples, 0, (s->rdft_len - nsamples - center) * sizeof(*data));
  199. av_rdft_calc(s->rdft, buf);
  200. buf[0] *= kernel_buf[0];
  201. buf[1] *= kernel_buf[s->rdft_len/2];
  202. for (k = 1; k < s->rdft_len/2; k++) {
  203. buf[2*k] *= kernel_buf[k];
  204. buf[2*k+1] *= kernel_buf[k];
  205. }
  206. av_rdft_calc(s->irdft, buf);
  207. for (k = 0; k < s->rdft_len - idx->overlap_idx; k++)
  208. buf[k] += obuf[k];
  209. memcpy(data, buf, nsamples * sizeof(*data));
  210. idx->buf_idx = !idx->buf_idx;
  211. idx->overlap_idx = nsamples;
  212. } else {
  213. while (nsamples > s->nsamples_max * 2) {
  214. fast_convolute(s, kernel_buf, conv_buf, idx, data, s->nsamples_max);
  215. data += s->nsamples_max;
  216. nsamples -= s->nsamples_max;
  217. }
  218. fast_convolute(s, kernel_buf, conv_buf, idx, data, nsamples/2);
  219. fast_convolute(s, kernel_buf, conv_buf, idx, data + nsamples/2, nsamples - nsamples/2);
  220. }
  221. }
  222. static void fast_convolute_nonlinear(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf,
  223. float *av_restrict conv_buf, OverlapIndex *av_restrict idx,
  224. float *av_restrict data, int nsamples)
  225. {
  226. if (nsamples <= s->nsamples_max) {
  227. float *buf = conv_buf + idx->buf_idx * s->rdft_len;
  228. float *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
  229. int k;
  230. memcpy(buf, data, nsamples * sizeof(*data));
  231. memset(buf + nsamples, 0, (s->rdft_len - nsamples) * sizeof(*data));
  232. av_rdft_calc(s->rdft, buf);
  233. buf[0] *= kernel_buf[0];
  234. buf[1] *= kernel_buf[1];
  235. for (k = 2; k < s->rdft_len; k += 2) {
  236. float re, im;
  237. re = buf[k] * kernel_buf[k] - buf[k+1] * kernel_buf[k+1];
  238. im = buf[k] * kernel_buf[k+1] + buf[k+1] * kernel_buf[k];
  239. buf[k] = re;
  240. buf[k+1] = im;
  241. }
  242. av_rdft_calc(s->irdft, buf);
  243. for (k = 0; k < s->rdft_len - idx->overlap_idx; k++)
  244. buf[k] += obuf[k];
  245. memcpy(data, buf, nsamples * sizeof(*data));
  246. idx->buf_idx = !idx->buf_idx;
  247. idx->overlap_idx = nsamples;
  248. } else {
  249. while (nsamples > s->nsamples_max * 2) {
  250. fast_convolute_nonlinear(s, kernel_buf, conv_buf, idx, data, s->nsamples_max);
  251. data += s->nsamples_max;
  252. nsamples -= s->nsamples_max;
  253. }
  254. fast_convolute_nonlinear(s, kernel_buf, conv_buf, idx, data, nsamples/2);
  255. fast_convolute_nonlinear(s, kernel_buf, conv_buf, idx, data + nsamples/2, nsamples - nsamples/2);
  256. }
  257. }
  258. static void fast_convolute2(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, FFTComplex *av_restrict conv_buf,
  259. OverlapIndex *av_restrict idx, float *av_restrict data0, float *av_restrict data1, int nsamples)
  260. {
  261. if (nsamples <= s->nsamples_max) {
  262. FFTComplex *buf = conv_buf + idx->buf_idx * s->rdft_len;
  263. FFTComplex *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
  264. int center = s->fir_len/2;
  265. int k;
  266. float tmp;
  267. memset(buf, 0, center * sizeof(*buf));
  268. for (k = 0; k < nsamples; k++) {
  269. buf[center+k].re = data0[k];
  270. buf[center+k].im = data1[k];
  271. }
  272. memset(buf + center + nsamples, 0, (s->rdft_len - nsamples - center) * sizeof(*buf));
  273. av_fft_permute(s->fft_ctx, buf);
  274. av_fft_calc(s->fft_ctx, buf);
  275. /* swap re <-> im, do backward fft using forward fft_ctx */
  276. /* normalize with 0.5f */
  277. tmp = buf[0].re;
  278. buf[0].re = 0.5f * kernel_buf[0] * buf[0].im;
  279. buf[0].im = 0.5f * kernel_buf[0] * tmp;
  280. for (k = 1; k < s->rdft_len/2; k++) {
  281. int m = s->rdft_len - k;
  282. tmp = buf[k].re;
  283. buf[k].re = 0.5f * kernel_buf[k] * buf[k].im;
  284. buf[k].im = 0.5f * kernel_buf[k] * tmp;
  285. tmp = buf[m].re;
  286. buf[m].re = 0.5f * kernel_buf[k] * buf[m].im;
  287. buf[m].im = 0.5f * kernel_buf[k] * tmp;
  288. }
  289. tmp = buf[k].re;
  290. buf[k].re = 0.5f * kernel_buf[k] * buf[k].im;
  291. buf[k].im = 0.5f * kernel_buf[k] * tmp;
  292. av_fft_permute(s->fft_ctx, buf);
  293. av_fft_calc(s->fft_ctx, buf);
  294. for (k = 0; k < s->rdft_len - idx->overlap_idx; k++) {
  295. buf[k].re += obuf[k].re;
  296. buf[k].im += obuf[k].im;
  297. }
  298. /* swapped re <-> im */
  299. for (k = 0; k < nsamples; k++) {
  300. data0[k] = buf[k].im;
  301. data1[k] = buf[k].re;
  302. }
  303. idx->buf_idx = !idx->buf_idx;
  304. idx->overlap_idx = nsamples;
  305. } else {
  306. while (nsamples > s->nsamples_max * 2) {
  307. fast_convolute2(s, kernel_buf, conv_buf, idx, data0, data1, s->nsamples_max);
  308. data0 += s->nsamples_max;
  309. data1 += s->nsamples_max;
  310. nsamples -= s->nsamples_max;
  311. }
  312. fast_convolute2(s, kernel_buf, conv_buf, idx, data0, data1, nsamples/2);
  313. fast_convolute2(s, kernel_buf, conv_buf, idx, data0 + nsamples/2, data1 + nsamples/2, nsamples - nsamples/2);
  314. }
  315. }
  316. static void dump_fir(AVFilterContext *ctx, FILE *fp, int ch)
  317. {
  318. FIREqualizerContext *s = ctx->priv;
  319. int rate = ctx->inputs[0]->sample_rate;
  320. int xlog = s->dumpscale == SCALE_LOGLIN || s->dumpscale == SCALE_LOGLOG;
  321. int ylog = s->dumpscale == SCALE_LINLOG || s->dumpscale == SCALE_LOGLOG;
  322. int x;
  323. int center = s->fir_len / 2;
  324. double delay = s->zero_phase ? 0.0 : (double) center / rate;
  325. double vx, ya, yb;
  326. if (!s->min_phase) {
  327. s->analysis_buf[0] *= s->rdft_len/2;
  328. for (x = 1; x <= center; x++) {
  329. s->analysis_buf[x] *= s->rdft_len/2;
  330. s->analysis_buf[s->analysis_rdft_len - x] *= s->rdft_len/2;
  331. }
  332. } else {
  333. for (x = 0; x < s->fir_len; x++)
  334. s->analysis_buf[x] *= s->rdft_len/2;
  335. }
  336. if (ch)
  337. fprintf(fp, "\n\n");
  338. fprintf(fp, "# time[%d] (time amplitude)\n", ch);
  339. if (!s->min_phase) {
  340. for (x = center; x > 0; x--)
  341. fprintf(fp, "%15.10f %15.10f\n", delay - (double) x / rate, (double) s->analysis_buf[s->analysis_rdft_len - x]);
  342. for (x = 0; x <= center; x++)
  343. fprintf(fp, "%15.10f %15.10f\n", delay + (double)x / rate , (double) s->analysis_buf[x]);
  344. } else {
  345. for (x = 0; x < s->fir_len; x++)
  346. fprintf(fp, "%15.10f %15.10f\n", (double)x / rate, (double) s->analysis_buf[x]);
  347. }
  348. av_rdft_calc(s->analysis_rdft, s->analysis_buf);
  349. fprintf(fp, "\n\n# freq[%d] (frequency desired_gain actual_gain)\n", ch);
  350. for (x = 0; x <= s->analysis_rdft_len/2; x++) {
  351. int i = (x == s->analysis_rdft_len/2) ? 1 : 2 * x;
  352. vx = (double)x * rate / s->analysis_rdft_len;
  353. if (xlog)
  354. vx = log2(0.05*vx);
  355. ya = s->dump_buf[i];
  356. yb = s->min_phase && (i > 1) ? hypotf(s->analysis_buf[i], s->analysis_buf[i+1]) : s->analysis_buf[i];
  357. if (s->min_phase)
  358. yb = fabs(yb);
  359. if (ylog) {
  360. ya = 20.0 * log10(fabs(ya));
  361. yb = 20.0 * log10(fabs(yb));
  362. }
  363. fprintf(fp, "%17.10f %17.10f %17.10f\n", vx, ya, yb);
  364. }
  365. }
  366. static double entry_func(void *p, double freq, double gain)
  367. {
  368. AVFilterContext *ctx = p;
  369. FIREqualizerContext *s = ctx->priv;
  370. if (s->nb_gain_entry >= NB_GAIN_ENTRY_MAX) {
  371. av_log(ctx, AV_LOG_ERROR, "entry table overflow.\n");
  372. s->gain_entry_err = AVERROR(EINVAL);
  373. return 0;
  374. }
  375. if (isnan(freq)) {
  376. av_log(ctx, AV_LOG_ERROR, "nan frequency (%g, %g).\n", freq, gain);
  377. s->gain_entry_err = AVERROR(EINVAL);
  378. return 0;
  379. }
  380. if (s->nb_gain_entry > 0 && freq <= s->gain_entry_tbl[s->nb_gain_entry - 1].freq) {
  381. av_log(ctx, AV_LOG_ERROR, "unsorted frequency (%g, %g).\n", freq, gain);
  382. s->gain_entry_err = AVERROR(EINVAL);
  383. return 0;
  384. }
  385. s->gain_entry_tbl[s->nb_gain_entry].freq = freq;
  386. s->gain_entry_tbl[s->nb_gain_entry].gain = gain;
  387. s->nb_gain_entry++;
  388. return 0;
  389. }
  390. static int gain_entry_compare(const void *key, const void *memb)
  391. {
  392. const double *freq = key;
  393. const GainEntry *entry = memb;
  394. if (*freq < entry[0].freq)
  395. return -1;
  396. if (*freq > entry[1].freq)
  397. return 1;
  398. return 0;
  399. }
  400. static double gain_interpolate_func(void *p, double freq)
  401. {
  402. AVFilterContext *ctx = p;
  403. FIREqualizerContext *s = ctx->priv;
  404. GainEntry *res;
  405. double d0, d1, d;
  406. if (isnan(freq))
  407. return freq;
  408. if (!s->nb_gain_entry)
  409. return 0;
  410. if (freq <= s->gain_entry_tbl[0].freq)
  411. return s->gain_entry_tbl[0].gain;
  412. if (freq >= s->gain_entry_tbl[s->nb_gain_entry-1].freq)
  413. return s->gain_entry_tbl[s->nb_gain_entry-1].gain;
  414. res = bsearch(&freq, &s->gain_entry_tbl, s->nb_gain_entry - 1, sizeof(*res), gain_entry_compare);
  415. av_assert0(res);
  416. d = res[1].freq - res[0].freq;
  417. d0 = freq - res[0].freq;
  418. d1 = res[1].freq - freq;
  419. if (d0 && d1)
  420. return (d0 * res[1].gain + d1 * res[0].gain) / d;
  421. if (d0)
  422. return res[1].gain;
  423. return res[0].gain;
  424. }
  425. static double cubic_interpolate_func(void *p, double freq)
  426. {
  427. AVFilterContext *ctx = p;
  428. FIREqualizerContext *s = ctx->priv;
  429. GainEntry *res;
  430. double x, x2, x3;
  431. double a, b, c, d;
  432. double m0, m1, m2, msum, unit;
  433. if (!s->nb_gain_entry)
  434. return 0;
  435. if (freq <= s->gain_entry_tbl[0].freq)
  436. return s->gain_entry_tbl[0].gain;
  437. if (freq >= s->gain_entry_tbl[s->nb_gain_entry-1].freq)
  438. return s->gain_entry_tbl[s->nb_gain_entry-1].gain;
  439. res = bsearch(&freq, &s->gain_entry_tbl, s->nb_gain_entry - 1, sizeof(*res), gain_entry_compare);
  440. av_assert0(res);
  441. unit = res[1].freq - res[0].freq;
  442. m0 = res != s->gain_entry_tbl ?
  443. unit * (res[0].gain - res[-1].gain) / (res[0].freq - res[-1].freq) : 0;
  444. m1 = res[1].gain - res[0].gain;
  445. m2 = res != s->gain_entry_tbl + s->nb_gain_entry - 2 ?
  446. unit * (res[2].gain - res[1].gain) / (res[2].freq - res[1].freq) : 0;
  447. msum = fabs(m0) + fabs(m1);
  448. m0 = msum > 0 ? (fabs(m0) * m1 + fabs(m1) * m0) / msum : 0;
  449. msum = fabs(m1) + fabs(m2);
  450. m1 = msum > 0 ? (fabs(m1) * m2 + fabs(m2) * m1) / msum : 0;
  451. d = res[0].gain;
  452. c = m0;
  453. b = 3 * res[1].gain - m1 - 2 * c - 3 * d;
  454. a = res[1].gain - b - c - d;
  455. x = (freq - res[0].freq) / unit;
  456. x2 = x * x;
  457. x3 = x2 * x;
  458. return a * x3 + b * x2 + c * x + d;
  459. }
  460. static const char *const var_names[] = {
  461. "f",
  462. "sr",
  463. "ch",
  464. "chid",
  465. "chs",
  466. "chlayout",
  467. NULL
  468. };
  469. enum VarOffset {
  470. VAR_F,
  471. VAR_SR,
  472. VAR_CH,
  473. VAR_CHID,
  474. VAR_CHS,
  475. VAR_CHLAYOUT,
  476. VAR_NB
  477. };
  478. static void generate_min_phase_kernel(FIREqualizerContext *s, float *rdft_buf)
  479. {
  480. int k, cepstrum_len = s->cepstrum_len, rdft_len = s->rdft_len;
  481. double norm = 2.0 / cepstrum_len;
  482. double minval = 1e-7 / rdft_len;
  483. memset(s->cepstrum_buf, 0, cepstrum_len * sizeof(*s->cepstrum_buf));
  484. memcpy(s->cepstrum_buf, rdft_buf, rdft_len/2 * sizeof(*rdft_buf));
  485. memcpy(s->cepstrum_buf + cepstrum_len - rdft_len/2, rdft_buf + rdft_len/2, rdft_len/2 * sizeof(*rdft_buf));
  486. av_rdft_calc(s->cepstrum_rdft, s->cepstrum_buf);
  487. s->cepstrum_buf[0] = log(FFMAX(s->cepstrum_buf[0], minval));
  488. s->cepstrum_buf[1] = log(FFMAX(s->cepstrum_buf[1], minval));
  489. for (k = 2; k < cepstrum_len; k += 2) {
  490. s->cepstrum_buf[k] = log(FFMAX(s->cepstrum_buf[k], minval));
  491. s->cepstrum_buf[k+1] = 0;
  492. }
  493. av_rdft_calc(s->cepstrum_irdft, s->cepstrum_buf);
  494. memset(s->cepstrum_buf + cepstrum_len/2 + 1, 0, (cepstrum_len/2 - 1) * sizeof(*s->cepstrum_buf));
  495. for (k = 1; k < cepstrum_len/2; k++)
  496. s->cepstrum_buf[k] *= 2;
  497. av_rdft_calc(s->cepstrum_rdft, s->cepstrum_buf);
  498. s->cepstrum_buf[0] = exp(s->cepstrum_buf[0] * norm) * norm;
  499. s->cepstrum_buf[1] = exp(s->cepstrum_buf[1] * norm) * norm;
  500. for (k = 2; k < cepstrum_len; k += 2) {
  501. double mag = exp(s->cepstrum_buf[k] * norm) * norm;
  502. double ph = s->cepstrum_buf[k+1] * norm;
  503. s->cepstrum_buf[k] = mag * cos(ph);
  504. s->cepstrum_buf[k+1] = mag * sin(ph);
  505. }
  506. av_rdft_calc(s->cepstrum_irdft, s->cepstrum_buf);
  507. memset(rdft_buf, 0, s->rdft_len * sizeof(*rdft_buf));
  508. memcpy(rdft_buf, s->cepstrum_buf, s->fir_len * sizeof(*rdft_buf));
  509. if (s->dumpfile) {
  510. memset(s->analysis_buf, 0, s->analysis_rdft_len * sizeof(*s->analysis_buf));
  511. memcpy(s->analysis_buf, s->cepstrum_buf, s->fir_len * sizeof(*s->analysis_buf));
  512. }
  513. }
  514. static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *gain_entry)
  515. {
  516. FIREqualizerContext *s = ctx->priv;
  517. AVFilterLink *inlink = ctx->inputs[0];
  518. const char *gain_entry_func_names[] = { "entry", NULL };
  519. const char *gain_func_names[] = { "gain_interpolate", "cubic_interpolate", NULL };
  520. double (*gain_entry_funcs[])(void *, double, double) = { entry_func, NULL };
  521. double (*gain_funcs[])(void *, double) = { gain_interpolate_func, cubic_interpolate_func, NULL };
  522. double vars[VAR_NB];
  523. AVExpr *gain_expr;
  524. int ret, k, center, ch;
  525. int xlog = s->scale == SCALE_LOGLIN || s->scale == SCALE_LOGLOG;
  526. int ylog = s->scale == SCALE_LINLOG || s->scale == SCALE_LOGLOG;
  527. FILE *dump_fp = NULL;
  528. s->nb_gain_entry = 0;
  529. s->gain_entry_err = 0;
  530. if (gain_entry) {
  531. double result = 0.0;
  532. ret = av_expr_parse_and_eval(&result, gain_entry, NULL, NULL, NULL, NULL,
  533. gain_entry_func_names, gain_entry_funcs, ctx, 0, ctx);
  534. if (ret < 0)
  535. return ret;
  536. if (s->gain_entry_err < 0)
  537. return s->gain_entry_err;
  538. }
  539. av_log(ctx, AV_LOG_DEBUG, "nb_gain_entry = %d.\n", s->nb_gain_entry);
  540. ret = av_expr_parse(&gain_expr, gain, var_names,
  541. gain_func_names, gain_funcs, NULL, NULL, 0, ctx);
  542. if (ret < 0)
  543. return ret;
  544. if (s->dumpfile && (!s->dump_buf || !s->analysis_rdft || !(dump_fp = fopen(s->dumpfile, "w"))))
  545. av_log(ctx, AV_LOG_WARNING, "dumping failed.\n");
  546. vars[VAR_CHS] = inlink->channels;
  547. vars[VAR_CHLAYOUT] = inlink->channel_layout;
  548. vars[VAR_SR] = inlink->sample_rate;
  549. for (ch = 0; ch < inlink->channels; ch++) {
  550. float *rdft_buf = s->kernel_tmp_buf + ch * s->rdft_len;
  551. double result;
  552. vars[VAR_CH] = ch;
  553. vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch);
  554. vars[VAR_F] = 0.0;
  555. if (xlog)
  556. vars[VAR_F] = log2(0.05 * vars[VAR_F]);
  557. result = av_expr_eval(gain_expr, vars, ctx);
  558. s->analysis_buf[0] = ylog ? pow(10.0, 0.05 * result) : result;
  559. vars[VAR_F] = 0.5 * inlink->sample_rate;
  560. if (xlog)
  561. vars[VAR_F] = log2(0.05 * vars[VAR_F]);
  562. result = av_expr_eval(gain_expr, vars, ctx);
  563. s->analysis_buf[1] = ylog ? pow(10.0, 0.05 * result) : result;
  564. for (k = 1; k < s->analysis_rdft_len/2; k++) {
  565. vars[VAR_F] = k * ((double)inlink->sample_rate /(double)s->analysis_rdft_len);
  566. if (xlog)
  567. vars[VAR_F] = log2(0.05 * vars[VAR_F]);
  568. result = av_expr_eval(gain_expr, vars, ctx);
  569. s->analysis_buf[2*k] = ylog ? pow(10.0, 0.05 * result) : s->min_phase ? fabs(result) : result;
  570. s->analysis_buf[2*k+1] = 0.0;
  571. }
  572. if (s->dump_buf)
  573. memcpy(s->dump_buf, s->analysis_buf, s->analysis_rdft_len * sizeof(*s->analysis_buf));
  574. av_rdft_calc(s->analysis_irdft, s->analysis_buf);
  575. center = s->fir_len / 2;
  576. for (k = 0; k <= center; k++) {
  577. double u = k * (M_PI/center);
  578. double win;
  579. switch (s->wfunc) {
  580. case WFUNC_RECTANGULAR:
  581. win = 1.0;
  582. break;
  583. case WFUNC_HANN:
  584. win = 0.5 + 0.5 * cos(u);
  585. break;
  586. case WFUNC_HAMMING:
  587. win = 0.53836 + 0.46164 * cos(u);
  588. break;
  589. case WFUNC_BLACKMAN:
  590. win = 0.42 + 0.5 * cos(u) + 0.08 * cos(2*u);
  591. break;
  592. case WFUNC_NUTTALL3:
  593. win = 0.40897 + 0.5 * cos(u) + 0.09103 * cos(2*u);
  594. break;
  595. case WFUNC_MNUTTALL3:
  596. win = 0.4243801 + 0.4973406 * cos(u) + 0.0782793 * cos(2*u);
  597. break;
  598. case WFUNC_NUTTALL:
  599. win = 0.355768 + 0.487396 * cos(u) + 0.144232 * cos(2*u) + 0.012604 * cos(3*u);
  600. break;
  601. case WFUNC_BNUTTALL:
  602. win = 0.3635819 + 0.4891775 * cos(u) + 0.1365995 * cos(2*u) + 0.0106411 * cos(3*u);
  603. break;
  604. case WFUNC_BHARRIS:
  605. win = 0.35875 + 0.48829 * cos(u) + 0.14128 * cos(2*u) + 0.01168 * cos(3*u);
  606. break;
  607. case WFUNC_TUKEY:
  608. win = (u <= 0.5 * M_PI) ? 1.0 : (0.5 + 0.5 * cos(2*u - M_PI));
  609. break;
  610. default:
  611. av_assert0(0);
  612. }
  613. s->analysis_buf[k] *= (2.0/s->analysis_rdft_len) * (2.0/s->rdft_len) * win;
  614. if (k)
  615. s->analysis_buf[s->analysis_rdft_len - k] = s->analysis_buf[k];
  616. }
  617. memset(s->analysis_buf + center + 1, 0, (s->analysis_rdft_len - s->fir_len) * sizeof(*s->analysis_buf));
  618. memcpy(rdft_buf, s->analysis_buf, s->rdft_len/2 * sizeof(*s->analysis_buf));
  619. memcpy(rdft_buf + s->rdft_len/2, s->analysis_buf + s->analysis_rdft_len - s->rdft_len/2, s->rdft_len/2 * sizeof(*s->analysis_buf));
  620. if (s->min_phase)
  621. generate_min_phase_kernel(s, rdft_buf);
  622. av_rdft_calc(s->rdft, rdft_buf);
  623. for (k = 0; k < s->rdft_len; k++) {
  624. if (isnan(rdft_buf[k]) || isinf(rdft_buf[k])) {
  625. av_log(ctx, AV_LOG_ERROR, "filter kernel contains nan or infinity.\n");
  626. av_expr_free(gain_expr);
  627. if (dump_fp)
  628. fclose(dump_fp);
  629. return AVERROR(EINVAL);
  630. }
  631. }
  632. if (!s->min_phase) {
  633. rdft_buf[s->rdft_len-1] = rdft_buf[1];
  634. for (k = 0; k < s->rdft_len/2; k++)
  635. rdft_buf[k] = rdft_buf[2*k];
  636. rdft_buf[s->rdft_len/2] = rdft_buf[s->rdft_len-1];
  637. }
  638. if (dump_fp)
  639. dump_fir(ctx, dump_fp, ch);
  640. if (!s->multi)
  641. break;
  642. }
  643. memcpy(s->kernel_buf, s->kernel_tmp_buf, (s->multi ? inlink->channels : 1) * s->rdft_len * sizeof(*s->kernel_buf));
  644. av_expr_free(gain_expr);
  645. if (dump_fp)
  646. fclose(dump_fp);
  647. return 0;
  648. }
  649. #define SELECT_GAIN(s) (s->gain_cmd ? s->gain_cmd : s->gain)
  650. #define SELECT_GAIN_ENTRY(s) (s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry)
  651. static int config_input(AVFilterLink *inlink)
  652. {
  653. AVFilterContext *ctx = inlink->dst;
  654. FIREqualizerContext *s = ctx->priv;
  655. int rdft_bits;
  656. common_uninit(s);
  657. s->next_pts = 0;
  658. s->frame_nsamples_max = 0;
  659. s->fir_len = FFMAX(2 * (int)(inlink->sample_rate * s->delay) + 1, 3);
  660. s->remaining = s->fir_len - 1;
  661. for (rdft_bits = RDFT_BITS_MIN; rdft_bits <= RDFT_BITS_MAX; rdft_bits++) {
  662. s->rdft_len = 1 << rdft_bits;
  663. s->nsamples_max = s->rdft_len - s->fir_len + 1;
  664. if (s->nsamples_max * 2 >= s->fir_len)
  665. break;
  666. }
  667. if (rdft_bits > RDFT_BITS_MAX) {
  668. av_log(ctx, AV_LOG_ERROR, "too large delay, please decrease it.\n");
  669. return AVERROR(EINVAL);
  670. }
  671. if (!(s->rdft = av_rdft_init(rdft_bits, DFT_R2C)) || !(s->irdft = av_rdft_init(rdft_bits, IDFT_C2R)))
  672. return AVERROR(ENOMEM);
  673. if (s->fft2 && !s->multi && inlink->channels > 1 && !(s->fft_ctx = av_fft_init(rdft_bits, 0)))
  674. return AVERROR(ENOMEM);
  675. if (s->min_phase) {
  676. int cepstrum_bits = rdft_bits + 2;
  677. if (cepstrum_bits > RDFT_BITS_MAX) {
  678. av_log(ctx, AV_LOG_ERROR, "too large delay, please decrease it.\n");
  679. return AVERROR(EINVAL);
  680. }
  681. cepstrum_bits = FFMIN(RDFT_BITS_MAX, cepstrum_bits + 1);
  682. s->cepstrum_rdft = av_rdft_init(cepstrum_bits, DFT_R2C);
  683. s->cepstrum_irdft = av_rdft_init(cepstrum_bits, IDFT_C2R);
  684. if (!s->cepstrum_rdft || !s->cepstrum_irdft)
  685. return AVERROR(ENOMEM);
  686. s->cepstrum_len = 1 << cepstrum_bits;
  687. s->cepstrum_buf = av_malloc_array(s->cepstrum_len, sizeof(*s->cepstrum_buf));
  688. if (!s->cepstrum_buf)
  689. return AVERROR(ENOMEM);
  690. }
  691. for ( ; rdft_bits <= RDFT_BITS_MAX; rdft_bits++) {
  692. s->analysis_rdft_len = 1 << rdft_bits;
  693. if (inlink->sample_rate <= s->accuracy * s->analysis_rdft_len)
  694. break;
  695. }
  696. if (rdft_bits > RDFT_BITS_MAX) {
  697. av_log(ctx, AV_LOG_ERROR, "too small accuracy, please increase it.\n");
  698. return AVERROR(EINVAL);
  699. }
  700. if (!(s->analysis_irdft = av_rdft_init(rdft_bits, IDFT_C2R)))
  701. return AVERROR(ENOMEM);
  702. if (s->dumpfile) {
  703. s->analysis_rdft = av_rdft_init(rdft_bits, DFT_R2C);
  704. s->dump_buf = av_malloc_array(s->analysis_rdft_len, sizeof(*s->dump_buf));
  705. }
  706. s->analysis_buf = av_malloc_array(s->analysis_rdft_len, sizeof(*s->analysis_buf));
  707. s->kernel_tmp_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_tmp_buf));
  708. s->kernel_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_buf));
  709. s->conv_buf = av_calloc(2 * s->rdft_len * inlink->channels, sizeof(*s->conv_buf));
  710. s->conv_idx = av_calloc(inlink->channels, sizeof(*s->conv_idx));
  711. if (!s->analysis_buf || !s->kernel_tmp_buf || !s->kernel_buf || !s->conv_buf || !s->conv_idx)
  712. return AVERROR(ENOMEM);
  713. av_log(ctx, AV_LOG_DEBUG, "sample_rate = %d, channels = %d, analysis_rdft_len = %d, rdft_len = %d, fir_len = %d, nsamples_max = %d.\n",
  714. inlink->sample_rate, inlink->channels, s->analysis_rdft_len, s->rdft_len, s->fir_len, s->nsamples_max);
  715. if (s->fixed)
  716. inlink->min_samples = inlink->max_samples = inlink->partial_buf_size = s->nsamples_max;
  717. return generate_kernel(ctx, SELECT_GAIN(s), SELECT_GAIN_ENTRY(s));
  718. }
  719. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  720. {
  721. AVFilterContext *ctx = inlink->dst;
  722. FIREqualizerContext *s = ctx->priv;
  723. int ch;
  724. if (!s->min_phase) {
  725. for (ch = 0; ch + 1 < inlink->channels && s->fft_ctx; ch += 2) {
  726. fast_convolute2(s, s->kernel_buf, (FFTComplex *)(s->conv_buf + 2 * ch * s->rdft_len),
  727. s->conv_idx + ch, (float *) frame->extended_data[ch],
  728. (float *) frame->extended_data[ch+1], frame->nb_samples);
  729. }
  730. for ( ; ch < inlink->channels; ch++) {
  731. fast_convolute(s, s->kernel_buf + (s->multi ? ch * s->rdft_len : 0),
  732. s->conv_buf + 2 * ch * s->rdft_len, s->conv_idx + ch,
  733. (float *) frame->extended_data[ch], frame->nb_samples);
  734. }
  735. } else {
  736. for (ch = 0; ch < inlink->channels; ch++) {
  737. fast_convolute_nonlinear(s, s->kernel_buf + (s->multi ? ch * s->rdft_len : 0),
  738. s->conv_buf + 2 * ch * s->rdft_len, s->conv_idx + ch,
  739. (float *) frame->extended_data[ch], frame->nb_samples);
  740. }
  741. }
  742. s->next_pts = AV_NOPTS_VALUE;
  743. if (frame->pts != AV_NOPTS_VALUE) {
  744. s->next_pts = frame->pts + av_rescale_q(frame->nb_samples, av_make_q(1, inlink->sample_rate), inlink->time_base);
  745. if (s->zero_phase && !s->min_phase)
  746. frame->pts -= av_rescale_q(s->fir_len/2, av_make_q(1, inlink->sample_rate), inlink->time_base);
  747. }
  748. s->frame_nsamples_max = FFMAX(s->frame_nsamples_max, frame->nb_samples);
  749. return ff_filter_frame(ctx->outputs[0], frame);
  750. }
  751. static int request_frame(AVFilterLink *outlink)
  752. {
  753. AVFilterContext *ctx = outlink->src;
  754. FIREqualizerContext *s= ctx->priv;
  755. int ret;
  756. ret = ff_request_frame(ctx->inputs[0]);
  757. if (ret == AVERROR_EOF && s->remaining > 0 && s->frame_nsamples_max > 0) {
  758. AVFrame *frame = ff_get_audio_buffer(outlink, FFMIN(s->remaining, s->frame_nsamples_max));
  759. if (!frame)
  760. return AVERROR(ENOMEM);
  761. av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->channels, frame->format);
  762. frame->pts = s->next_pts;
  763. s->remaining -= frame->nb_samples;
  764. ret = filter_frame(ctx->inputs[0], frame);
  765. }
  766. return ret;
  767. }
  768. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  769. char *res, int res_len, int flags)
  770. {
  771. FIREqualizerContext *s = ctx->priv;
  772. int ret = AVERROR(ENOSYS);
  773. if (!strcmp(cmd, "gain")) {
  774. char *gain_cmd;
  775. if (SELECT_GAIN(s) && !strcmp(SELECT_GAIN(s), args)) {
  776. av_log(ctx, AV_LOG_DEBUG, "equal gain, do not rebuild.\n");
  777. return 0;
  778. }
  779. gain_cmd = av_strdup(args);
  780. if (!gain_cmd)
  781. return AVERROR(ENOMEM);
  782. ret = generate_kernel(ctx, gain_cmd, SELECT_GAIN_ENTRY(s));
  783. if (ret >= 0) {
  784. av_freep(&s->gain_cmd);
  785. s->gain_cmd = gain_cmd;
  786. } else {
  787. av_freep(&gain_cmd);
  788. }
  789. } else if (!strcmp(cmd, "gain_entry")) {
  790. char *gain_entry_cmd;
  791. if (SELECT_GAIN_ENTRY(s) && !strcmp(SELECT_GAIN_ENTRY(s), args)) {
  792. av_log(ctx, AV_LOG_DEBUG, "equal gain_entry, do not rebuild.\n");
  793. return 0;
  794. }
  795. gain_entry_cmd = av_strdup(args);
  796. if (!gain_entry_cmd)
  797. return AVERROR(ENOMEM);
  798. ret = generate_kernel(ctx, SELECT_GAIN(s), gain_entry_cmd);
  799. if (ret >= 0) {
  800. av_freep(&s->gain_entry_cmd);
  801. s->gain_entry_cmd = gain_entry_cmd;
  802. } else {
  803. av_freep(&gain_entry_cmd);
  804. }
  805. }
  806. return ret;
  807. }
  808. static const AVFilterPad firequalizer_inputs[] = {
  809. {
  810. .name = "default",
  811. .config_props = config_input,
  812. .filter_frame = filter_frame,
  813. .type = AVMEDIA_TYPE_AUDIO,
  814. .needs_writable = 1,
  815. },
  816. { NULL }
  817. };
  818. static const AVFilterPad firequalizer_outputs[] = {
  819. {
  820. .name = "default",
  821. .request_frame = request_frame,
  822. .type = AVMEDIA_TYPE_AUDIO,
  823. },
  824. { NULL }
  825. };
  826. AVFilter ff_af_firequalizer = {
  827. .name = "firequalizer",
  828. .description = NULL_IF_CONFIG_SMALL("Finite Impulse Response Equalizer."),
  829. .uninit = uninit,
  830. .query_formats = query_formats,
  831. .process_command = process_command,
  832. .priv_size = sizeof(FIREqualizerContext),
  833. .inputs = firequalizer_inputs,
  834. .outputs = firequalizer_outputs,
  835. .priv_class = &firequalizer_class,
  836. };