af_biquads.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  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 "config_components.h"
  64. #include "libavutil/avassert.h"
  65. #include "libavutil/channel_layout.h"
  66. #include "libavutil/ffmath.h"
  67. #include "libavutil/opt.h"
  68. #include "audio.h"
  69. #include "avfilter.h"
  70. #include "filters.h"
  71. #include "internal.h"
  72. enum FilterType {
  73. biquad,
  74. equalizer,
  75. bass,
  76. treble,
  77. bandpass,
  78. bandreject,
  79. allpass,
  80. highpass,
  81. lowpass,
  82. lowshelf,
  83. highshelf,
  84. };
  85. enum WidthType {
  86. NONE,
  87. HERTZ,
  88. OCTAVE,
  89. QFACTOR,
  90. SLOPE,
  91. KHERTZ,
  92. NB_WTYPE,
  93. };
  94. enum TransformType {
  95. DI,
  96. DII,
  97. TDI,
  98. TDII,
  99. LATT,
  100. SVF,
  101. NB_TTYPE,
  102. };
  103. typedef struct ChanCache {
  104. double i1, i2;
  105. double o1, o2;
  106. double ri1, ri2;
  107. double ro1, ro2;
  108. int clippings;
  109. } ChanCache;
  110. typedef struct BiquadsContext {
  111. const AVClass *class;
  112. enum FilterType filter_type;
  113. int width_type;
  114. int poles;
  115. int csg;
  116. int transform_type;
  117. int precision;
  118. int block_samples;
  119. int bypass;
  120. double gain;
  121. double frequency;
  122. double width;
  123. double mix;
  124. char *ch_layout_str;
  125. AVChannelLayout ch_layout;
  126. int normalize;
  127. int order;
  128. double a0, a1, a2;
  129. double b0, b1, b2;
  130. double oa0, oa1, oa2;
  131. double ob0, ob1, ob2;
  132. AVFrame *block[3];
  133. ChanCache *cache;
  134. int block_align;
  135. void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
  136. double *i1, double *i2, double *o1, double *o2,
  137. double b0, double b1, double b2, double a1, double a2, int *clippings,
  138. int disabled);
  139. } BiquadsContext;
  140. static int query_formats(AVFilterContext *ctx)
  141. {
  142. BiquadsContext *s = ctx->priv;
  143. static const enum AVSampleFormat auto_sample_fmts[] = {
  144. AV_SAMPLE_FMT_S16P,
  145. AV_SAMPLE_FMT_S32P,
  146. AV_SAMPLE_FMT_FLTP,
  147. AV_SAMPLE_FMT_DBLP,
  148. AV_SAMPLE_FMT_NONE
  149. };
  150. enum AVSampleFormat sample_fmts[] = {
  151. AV_SAMPLE_FMT_S16P,
  152. AV_SAMPLE_FMT_NONE
  153. };
  154. const enum AVSampleFormat *sample_fmts_list = sample_fmts;
  155. int ret = ff_set_common_all_channel_counts(ctx);
  156. if (ret < 0)
  157. return ret;
  158. switch (s->precision) {
  159. case 0:
  160. sample_fmts[0] = AV_SAMPLE_FMT_S16P;
  161. break;
  162. case 1:
  163. sample_fmts[0] = AV_SAMPLE_FMT_S32P;
  164. break;
  165. case 2:
  166. sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
  167. break;
  168. case 3:
  169. sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
  170. break;
  171. default:
  172. sample_fmts_list = auto_sample_fmts;
  173. break;
  174. }
  175. ret = ff_set_common_formats_from_list(ctx, sample_fmts_list);
  176. if (ret < 0)
  177. return ret;
  178. return ff_set_common_all_samplerates(ctx);
  179. }
  180. #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
  181. static void biquad_## name (BiquadsContext *s, \
  182. const void *input, void *output, int len, \
  183. double *in1, double *in2, \
  184. double *out1, double *out2, \
  185. double b0, double b1, double b2, \
  186. double a1, double a2, int *clippings, \
  187. int disabled) \
  188. { \
  189. const type *ibuf = input; \
  190. type *obuf = output; \
  191. double i1 = *in1; \
  192. double i2 = *in2; \
  193. double o1 = *out1; \
  194. double o2 = *out2; \
  195. double wet = s->mix; \
  196. double dry = 1. - wet; \
  197. double out; \
  198. int i; \
  199. a1 = -a1; \
  200. a2 = -a2; \
  201. \
  202. for (i = 0; i+1 < len; i++) { \
  203. o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
  204. i2 = ibuf[i]; \
  205. out = o2 * wet + i2 * dry; \
  206. if (disabled) { \
  207. obuf[i] = i2; \
  208. } else if (need_clipping && out < min) { \
  209. (*clippings)++; \
  210. obuf[i] = min; \
  211. } else if (need_clipping && out > max) { \
  212. (*clippings)++; \
  213. obuf[i] = max; \
  214. } else { \
  215. obuf[i] = out; \
  216. } \
  217. i++; \
  218. o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
  219. i1 = ibuf[i]; \
  220. out = o1 * wet + i1 * dry; \
  221. if (disabled) { \
  222. obuf[i] = i1; \
  223. } else if (need_clipping && out < min) { \
  224. (*clippings)++; \
  225. obuf[i] = min; \
  226. } else if (need_clipping && out > max) { \
  227. (*clippings)++; \
  228. obuf[i] = max; \
  229. } else { \
  230. obuf[i] = out; \
  231. } \
  232. } \
  233. if (i < len) { \
  234. double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
  235. i2 = i1; \
  236. i1 = ibuf[i]; \
  237. o2 = o1; \
  238. o1 = o0; \
  239. out = o0 * wet + i1 * dry; \
  240. if (disabled) { \
  241. obuf[i] = i1; \
  242. } else if (need_clipping && out < min) { \
  243. (*clippings)++; \
  244. obuf[i] = min; \
  245. } else if (need_clipping && out > max) { \
  246. (*clippings)++; \
  247. obuf[i] = max; \
  248. } else { \
  249. obuf[i] = out; \
  250. } \
  251. } \
  252. *in1 = i1; \
  253. *in2 = i2; \
  254. *out1 = o1; \
  255. *out2 = o2; \
  256. }
  257. BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  258. BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  259. BIQUAD_FILTER(flt, float, -1., 1., 0)
  260. BIQUAD_FILTER(dbl, double, -1., 1., 0)
  261. #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \
  262. static void biquad_dii_## name (BiquadsContext *s, \
  263. const void *input, void *output, int len, \
  264. double *z1, double *z2, \
  265. double *unused1, double *unused2, \
  266. double b0, double b1, double b2, \
  267. double a1, double a2, int *clippings, \
  268. int disabled) \
  269. { \
  270. const type *ibuf = input; \
  271. type *obuf = output; \
  272. double w1 = *z1; \
  273. double w2 = *z2; \
  274. double wet = s->mix; \
  275. double dry = 1. - wet; \
  276. double in, out, w0; \
  277. \
  278. a1 = -a1; \
  279. a2 = -a2; \
  280. \
  281. for (int i = 0; i < len; i++) { \
  282. in = ibuf[i]; \
  283. w0 = in + a1 * w1 + a2 * w2; \
  284. out = b0 * w0 + b1 * w1 + b2 * w2; \
  285. w2 = w1; \
  286. w1 = w0; \
  287. out = out * wet + in * dry; \
  288. if (disabled) { \
  289. obuf[i] = in; \
  290. } else if (need_clipping && out < min) { \
  291. (*clippings)++; \
  292. obuf[i] = min; \
  293. } else if (need_clipping && out > max) { \
  294. (*clippings)++; \
  295. obuf[i] = max; \
  296. } else { \
  297. obuf[i] = out; \
  298. } \
  299. } \
  300. *z1 = w1; \
  301. *z2 = w2; \
  302. }
  303. BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  304. BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  305. BIQUAD_DII_FILTER(flt, float, -1., 1., 0)
  306. BIQUAD_DII_FILTER(dbl, double, -1., 1., 0)
  307. #define BIQUAD_TDI_FILTER(name, type, min, max, need_clipping) \
  308. static void biquad_tdi_## name (BiquadsContext *s, \
  309. const void *input, void *output, int len, \
  310. double *z1, double *z2, \
  311. double *z3, double *z4, \
  312. double b0, double b1, double b2, \
  313. double a1, double a2, int *clippings, \
  314. int disabled) \
  315. { \
  316. const type *ibuf = input; \
  317. type *obuf = output; \
  318. double s1 = *z1; \
  319. double s2 = *z2; \
  320. double s3 = *z3; \
  321. double s4 = *z4; \
  322. double wet = s->mix; \
  323. double dry = 1. - wet; \
  324. double in, out; \
  325. \
  326. a1 = -a1; \
  327. a2 = -a2; \
  328. \
  329. for (int i = 0; i < len; i++) { \
  330. double t1, t2, t3, t4; \
  331. in = ibuf[i] + s1; \
  332. t1 = in * a1 + s2; \
  333. t2 = in * a2; \
  334. t3 = in * b1 + s4; \
  335. t4 = in * b2; \
  336. out = b0 * in + s3; \
  337. out = out * wet + in * dry; \
  338. s1 = t1; s2 = t2; s3 = t3; s4 = t4; \
  339. if (disabled) { \
  340. obuf[i] = in; \
  341. } else if (need_clipping && out < min) { \
  342. (*clippings)++; \
  343. obuf[i] = min; \
  344. } else if (need_clipping && out > max) { \
  345. (*clippings)++; \
  346. obuf[i] = max; \
  347. } else { \
  348. obuf[i] = out; \
  349. } \
  350. } \
  351. \
  352. *z1 = s1; \
  353. *z2 = s2; \
  354. *z3 = s3; \
  355. *z4 = s4; \
  356. }
  357. BIQUAD_TDI_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  358. BIQUAD_TDI_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  359. BIQUAD_TDI_FILTER(flt, float, -1., 1., 0)
  360. BIQUAD_TDI_FILTER(dbl, double, -1., 1., 0)
  361. #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \
  362. static void biquad_tdii_## name (BiquadsContext *s, \
  363. const void *input, void *output, int len, \
  364. double *z1, double *z2, \
  365. double *unused1, double *unused2, \
  366. double b0, double b1, double b2, \
  367. double a1, double a2, int *clippings, \
  368. int disabled) \
  369. { \
  370. const type *ibuf = input; \
  371. type *obuf = output; \
  372. double w1 = *z1; \
  373. double w2 = *z2; \
  374. double wet = s->mix; \
  375. double dry = 1. - wet; \
  376. double in, out; \
  377. \
  378. a1 = -a1; \
  379. a2 = -a2; \
  380. \
  381. for (int i = 0; i < len; i++) { \
  382. in = ibuf[i]; \
  383. out = b0 * in + w1; \
  384. w1 = b1 * in + w2 + a1 * out; \
  385. w2 = b2 * in + a2 * out; \
  386. out = out * wet + in * dry; \
  387. if (disabled) { \
  388. obuf[i] = in; \
  389. } else if (need_clipping && out < min) { \
  390. (*clippings)++; \
  391. obuf[i] = min; \
  392. } else if (need_clipping && out > max) { \
  393. (*clippings)++; \
  394. obuf[i] = max; \
  395. } else { \
  396. obuf[i] = out; \
  397. } \
  398. } \
  399. *z1 = w1; \
  400. *z2 = w2; \
  401. }
  402. BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  403. BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  404. BIQUAD_TDII_FILTER(flt, float, -1., 1., 0)
  405. BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0)
  406. #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \
  407. static void biquad_latt_## name (BiquadsContext *s, \
  408. const void *input, void *output, int len, \
  409. double *z1, double *z2, \
  410. double *unused1, double *unused2, \
  411. double v0, double v1, double v2, \
  412. double k0, double k1, int *clippings, \
  413. int disabled) \
  414. { \
  415. const type *ibuf = input; \
  416. type *obuf = output; \
  417. double s0 = *z1; \
  418. double s1 = *z2; \
  419. double wet = s->mix; \
  420. double dry = 1. - wet; \
  421. double in, out; \
  422. double t0, t1; \
  423. \
  424. for (int i = 0; i < len; i++) { \
  425. out = 0.; \
  426. in = ibuf[i]; \
  427. t0 = in - k1 * s0; \
  428. t1 = t0 * k1 + s0; \
  429. out += t1 * v2; \
  430. \
  431. t0 = t0 - k0 * s1; \
  432. t1 = t0 * k0 + s1; \
  433. out += t1 * v1; \
  434. \
  435. out += t0 * v0; \
  436. s0 = t1; \
  437. s1 = t0; \
  438. \
  439. out = out * wet + in * dry; \
  440. if (disabled) { \
  441. obuf[i] = in; \
  442. } else if (need_clipping && out < min) { \
  443. (*clippings)++; \
  444. obuf[i] = min; \
  445. } else if (need_clipping && out > max) { \
  446. (*clippings)++; \
  447. obuf[i] = max; \
  448. } else { \
  449. obuf[i] = out; \
  450. } \
  451. } \
  452. *z1 = s0; \
  453. *z2 = s1; \
  454. }
  455. BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  456. BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  457. BIQUAD_LATT_FILTER(flt, float, -1., 1., 0)
  458. BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0)
  459. #define BIQUAD_SVF_FILTER(name, type, min, max, need_clipping) \
  460. static void biquad_svf_## name (BiquadsContext *s, \
  461. const void *input, void *output, int len, \
  462. double *y0, double *y1, \
  463. double *unused1, double *unused2, \
  464. double b0, double b1, double b2, \
  465. double a1, double a2, int *clippings, \
  466. int disabled) \
  467. { \
  468. const type *ibuf = input; \
  469. type *obuf = output; \
  470. double s0 = *y0; \
  471. double s1 = *y1; \
  472. double wet = s->mix; \
  473. double dry = 1. - wet; \
  474. double in, out; \
  475. double t0, t1; \
  476. \
  477. for (int i = 0; i < len; i++) { \
  478. in = ibuf[i]; \
  479. out = b2 * in + s0; \
  480. t0 = b0 * in + a1 * s0 + s1; \
  481. t1 = b1 * in + a2 * s0; \
  482. s0 = t0; \
  483. s1 = t1; \
  484. \
  485. out = out * wet + in * dry; \
  486. if (disabled) { \
  487. obuf[i] = in; \
  488. } else if (need_clipping && out < min) { \
  489. (*clippings)++; \
  490. obuf[i] = min; \
  491. } else if (need_clipping && out > max) { \
  492. (*clippings)++; \
  493. obuf[i] = max; \
  494. } else { \
  495. obuf[i] = out; \
  496. } \
  497. } \
  498. *y0 = s0; \
  499. *y1 = s1; \
  500. }
  501. BIQUAD_SVF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
  502. BIQUAD_SVF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
  503. BIQUAD_SVF_FILTER(flt, float, -1., 1., 0)
  504. BIQUAD_SVF_FILTER(dbl, double, -1., 1., 0)
  505. static void convert_dir2latt(BiquadsContext *s)
  506. {
  507. double k0, k1, v0, v1, v2;
  508. k1 = s->a2;
  509. k0 = s->a1 / (1. + k1);
  510. v2 = s->b2;
  511. v1 = s->b1 - v2 * s->a1;
  512. v0 = s->b0 - v1 * k0 - v2 * k1;
  513. s->a1 = k0;
  514. s->a2 = k1;
  515. s->b0 = v0;
  516. s->b1 = v1;
  517. s->b2 = v2;
  518. }
  519. static void convert_dir2svf(BiquadsContext *s)
  520. {
  521. double a[2];
  522. double b[3];
  523. a[0] = -s->a1;
  524. a[1] = -s->a2;
  525. b[0] = s->b1 - s->a1 * s->b0;
  526. b[1] = s->b2 - s->a2 * s->b0;
  527. b[2] = s->b0;
  528. s->a1 = a[0];
  529. s->a2 = a[1];
  530. s->b0 = b[0];
  531. s->b1 = b[1];
  532. s->b2 = b[2];
  533. }
  534. static int config_filter(AVFilterLink *outlink, int reset)
  535. {
  536. AVFilterContext *ctx = outlink->src;
  537. BiquadsContext *s = ctx->priv;
  538. AVFilterLink *inlink = ctx->inputs[0];
  539. double A = ff_exp10(s->gain / 40);
  540. double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
  541. double K = tan(w0 / 2.);
  542. double alpha, beta;
  543. s->bypass = (((w0 > M_PI || w0 <= 0.) && reset) || (s->width <= 0.)) && (s->filter_type != biquad);
  544. if (s->bypass) {
  545. av_log(ctx, AV_LOG_WARNING, "Invalid frequency and/or width!\n");
  546. return 0;
  547. }
  548. if ((w0 > M_PI || w0 <= 0.) && (s->filter_type != biquad))
  549. return AVERROR(EINVAL);
  550. switch (s->width_type) {
  551. case NONE:
  552. alpha = 0.0;
  553. break;
  554. case HERTZ:
  555. alpha = sin(w0) / (2 * s->frequency / s->width);
  556. break;
  557. case KHERTZ:
  558. alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
  559. break;
  560. case OCTAVE:
  561. alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
  562. break;
  563. case QFACTOR:
  564. alpha = sin(w0) / (2 * s->width);
  565. break;
  566. case SLOPE:
  567. alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
  568. break;
  569. default:
  570. av_assert0(0);
  571. }
  572. beta = 2 * sqrt(A);
  573. switch (s->filter_type) {
  574. case biquad:
  575. s->a0 = s->oa0;
  576. s->a1 = s->oa1;
  577. s->a2 = s->oa2;
  578. s->b0 = s->ob0;
  579. s->b1 = s->ob1;
  580. s->b2 = s->ob2;
  581. break;
  582. case equalizer:
  583. s->a0 = 1 + alpha / A;
  584. s->a1 = -2 * cos(w0);
  585. s->a2 = 1 - alpha / A;
  586. s->b0 = 1 + alpha * A;
  587. s->b1 = -2 * cos(w0);
  588. s->b2 = 1 - alpha * A;
  589. break;
  590. case bass:
  591. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  592. case lowshelf:
  593. if (s->poles == 1) {
  594. double A = ff_exp10(s->gain / 20);
  595. double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
  596. double n = (A + 1) / (A - 1);
  597. double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
  598. double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
  599. double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
  600. s->a0 = 1 + ro * alpha1;
  601. s->a1 = -ro - alpha1;
  602. s->a2 = 0;
  603. s->b0 = beta0 + ro * beta1;
  604. s->b1 = -beta1 - ro * beta0;
  605. s->b2 = 0;
  606. } else {
  607. s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
  608. s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
  609. s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
  610. s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
  611. s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
  612. s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
  613. }
  614. break;
  615. case treble:
  616. beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
  617. case highshelf:
  618. if (s->poles == 1) {
  619. double A = ff_exp10(s->gain / 20);
  620. double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
  621. double n = (A + 1) / (A - 1);
  622. double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
  623. double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
  624. double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
  625. s->a0 = 1 + ro * alpha1;
  626. s->a1 = ro + alpha1;
  627. s->a2 = 0;
  628. s->b0 = beta0 + ro * beta1;
  629. s->b1 = beta1 + ro * beta0;
  630. s->b2 = 0;
  631. } else {
  632. s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
  633. s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
  634. s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
  635. s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
  636. s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
  637. s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
  638. }
  639. break;
  640. case bandpass:
  641. if (s->csg) {
  642. s->a0 = 1 + alpha;
  643. s->a1 = -2 * cos(w0);
  644. s->a2 = 1 - alpha;
  645. s->b0 = sin(w0) / 2;
  646. s->b1 = 0;
  647. s->b2 = -sin(w0) / 2;
  648. } else {
  649. s->a0 = 1 + alpha;
  650. s->a1 = -2 * cos(w0);
  651. s->a2 = 1 - alpha;
  652. s->b0 = alpha;
  653. s->b1 = 0;
  654. s->b2 = -alpha;
  655. }
  656. break;
  657. case bandreject:
  658. s->a0 = 1 + alpha;
  659. s->a1 = -2 * cos(w0);
  660. s->a2 = 1 - alpha;
  661. s->b0 = 1;
  662. s->b1 = -2 * cos(w0);
  663. s->b2 = 1;
  664. break;
  665. case lowpass:
  666. if (s->poles == 1) {
  667. s->a0 = 1;
  668. s->a1 = -exp(-w0);
  669. s->a2 = 0;
  670. s->b0 = 1 + s->a1;
  671. s->b1 = 0;
  672. s->b2 = 0;
  673. } else {
  674. s->a0 = 1 + alpha;
  675. s->a1 = -2 * cos(w0);
  676. s->a2 = 1 - alpha;
  677. s->b0 = (1 - cos(w0)) / 2;
  678. s->b1 = 1 - cos(w0);
  679. s->b2 = (1 - cos(w0)) / 2;
  680. }
  681. break;
  682. case highpass:
  683. if (s->poles == 1) {
  684. s->a0 = 1;
  685. s->a1 = -exp(-w0);
  686. s->a2 = 0;
  687. s->b0 = (1 - s->a1) / 2;
  688. s->b1 = -s->b0;
  689. s->b2 = 0;
  690. } else {
  691. s->a0 = 1 + alpha;
  692. s->a1 = -2 * cos(w0);
  693. s->a2 = 1 - alpha;
  694. s->b0 = (1 + cos(w0)) / 2;
  695. s->b1 = -(1 + cos(w0));
  696. s->b2 = (1 + cos(w0)) / 2;
  697. }
  698. break;
  699. case allpass:
  700. switch (s->order) {
  701. case 1:
  702. s->a0 = 1.;
  703. s->a1 = -(1. - K) / (1. + K);
  704. s->a2 = 0.;
  705. s->b0 = s->a1;
  706. s->b1 = s->a0;
  707. s->b2 = 0.;
  708. break;
  709. case 2:
  710. s->a0 = 1 + alpha;
  711. s->a1 = -2 * cos(w0);
  712. s->a2 = 1 - alpha;
  713. s->b0 = 1 - alpha;
  714. s->b1 = -2 * cos(w0);
  715. s->b2 = 1 + alpha;
  716. break;
  717. }
  718. break;
  719. default:
  720. av_assert0(0);
  721. }
  722. 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);
  723. s->a1 /= s->a0;
  724. s->a2 /= s->a0;
  725. s->b0 /= s->a0;
  726. s->b1 /= s->a0;
  727. s->b2 /= s->a0;
  728. s->a0 /= s->a0;
  729. if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) {
  730. double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2);
  731. s->b0 *= factor;
  732. s->b1 *= factor;
  733. s->b2 *= factor;
  734. }
  735. s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->ch_layout.nb_channels);
  736. if (!s->cache)
  737. return AVERROR(ENOMEM);
  738. if (reset)
  739. memset(s->cache, 0, sizeof(ChanCache) * inlink->ch_layout.nb_channels);
  740. if (reset && s->block_samples > 0) {
  741. for (int i = 0; i < 3; i++) {
  742. s->block[i] = ff_get_audio_buffer(outlink, s->block_samples * 2);
  743. if (!s->block[i])
  744. return AVERROR(ENOMEM);
  745. av_samples_set_silence(s->block[i]->extended_data, 0, s->block_samples * 2,
  746. s->block[i]->ch_layout.nb_channels, s->block[i]->format);
  747. }
  748. }
  749. switch (s->transform_type) {
  750. case DI:
  751. switch (inlink->format) {
  752. case AV_SAMPLE_FMT_S16P:
  753. s->filter = biquad_s16;
  754. break;
  755. case AV_SAMPLE_FMT_S32P:
  756. s->filter = biquad_s32;
  757. break;
  758. case AV_SAMPLE_FMT_FLTP:
  759. s->filter = biquad_flt;
  760. break;
  761. case AV_SAMPLE_FMT_DBLP:
  762. s->filter = biquad_dbl;
  763. break;
  764. default: av_assert0(0);
  765. }
  766. break;
  767. case DII:
  768. switch (inlink->format) {
  769. case AV_SAMPLE_FMT_S16P:
  770. s->filter = biquad_dii_s16;
  771. break;
  772. case AV_SAMPLE_FMT_S32P:
  773. s->filter = biquad_dii_s32;
  774. break;
  775. case AV_SAMPLE_FMT_FLTP:
  776. s->filter = biquad_dii_flt;
  777. break;
  778. case AV_SAMPLE_FMT_DBLP:
  779. s->filter = biquad_dii_dbl;
  780. break;
  781. default: av_assert0(0);
  782. }
  783. break;
  784. case TDI:
  785. switch (inlink->format) {
  786. case AV_SAMPLE_FMT_S16P:
  787. s->filter = biquad_tdi_s16;
  788. break;
  789. case AV_SAMPLE_FMT_S32P:
  790. s->filter = biquad_tdi_s32;
  791. break;
  792. case AV_SAMPLE_FMT_FLTP:
  793. s->filter = biquad_tdi_flt;
  794. break;
  795. case AV_SAMPLE_FMT_DBLP:
  796. s->filter = biquad_tdi_dbl;
  797. break;
  798. default: av_assert0(0);
  799. }
  800. break;
  801. case TDII:
  802. switch (inlink->format) {
  803. case AV_SAMPLE_FMT_S16P:
  804. s->filter = biquad_tdii_s16;
  805. break;
  806. case AV_SAMPLE_FMT_S32P:
  807. s->filter = biquad_tdii_s32;
  808. break;
  809. case AV_SAMPLE_FMT_FLTP:
  810. s->filter = biquad_tdii_flt;
  811. break;
  812. case AV_SAMPLE_FMT_DBLP:
  813. s->filter = biquad_tdii_dbl;
  814. break;
  815. default: av_assert0(0);
  816. }
  817. break;
  818. case LATT:
  819. switch (inlink->format) {
  820. case AV_SAMPLE_FMT_S16P:
  821. s->filter = biquad_latt_s16;
  822. break;
  823. case AV_SAMPLE_FMT_S32P:
  824. s->filter = biquad_latt_s32;
  825. break;
  826. case AV_SAMPLE_FMT_FLTP:
  827. s->filter = biquad_latt_flt;
  828. break;
  829. case AV_SAMPLE_FMT_DBLP:
  830. s->filter = biquad_latt_dbl;
  831. break;
  832. default: av_assert0(0);
  833. }
  834. break;
  835. case SVF:
  836. switch (inlink->format) {
  837. case AV_SAMPLE_FMT_S16P:
  838. s->filter = biquad_svf_s16;
  839. break;
  840. case AV_SAMPLE_FMT_S32P:
  841. s->filter = biquad_svf_s32;
  842. break;
  843. case AV_SAMPLE_FMT_FLTP:
  844. s->filter = biquad_svf_flt;
  845. break;
  846. case AV_SAMPLE_FMT_DBLP:
  847. s->filter = biquad_svf_dbl;
  848. break;
  849. default: av_assert0(0);
  850. }
  851. break;
  852. default:
  853. av_assert0(0);
  854. }
  855. s->block_align = av_get_bytes_per_sample(inlink->format);
  856. if (s->transform_type == LATT)
  857. convert_dir2latt(s);
  858. else if (s->transform_type == SVF)
  859. convert_dir2svf(s);
  860. return 0;
  861. }
  862. static int config_output(AVFilterLink *outlink)
  863. {
  864. return config_filter(outlink, 1);
  865. }
  866. typedef struct ThreadData {
  867. AVFrame *in, *out;
  868. } ThreadData;
  869. static void reverse_samples(AVFrame *out, AVFrame *in, int p,
  870. int oo, int io, int nb_samples)
  871. {
  872. switch (out->format) {
  873. case AV_SAMPLE_FMT_S16P: {
  874. const int16_t *src = ((const int16_t *)in->extended_data[p]) + io;
  875. int16_t *dst = ((int16_t *)out->extended_data[p]) + oo;
  876. for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
  877. dst[i] = src[j];
  878. }
  879. break;
  880. case AV_SAMPLE_FMT_S32P: {
  881. const int32_t *src = ((const int32_t *)in->extended_data[p]) + io;
  882. int32_t *dst = ((int32_t *)out->extended_data[p]) + oo;
  883. for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
  884. dst[i] = src[j];
  885. }
  886. break;
  887. case AV_SAMPLE_FMT_FLTP: {
  888. const float *src = ((const float *)in->extended_data[p]) + io;
  889. float *dst = ((float *)out->extended_data[p]) + oo;
  890. for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
  891. dst[i] = src[j];
  892. }
  893. break;
  894. case AV_SAMPLE_FMT_DBLP: {
  895. const double *src = ((const double *)in->extended_data[p]) + io;
  896. double *dst = ((double *)out->extended_data[p]) + oo;
  897. for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
  898. dst[i] = src[j];
  899. }
  900. break;
  901. }
  902. }
  903. static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  904. {
  905. AVFilterLink *inlink = ctx->inputs[0];
  906. ThreadData *td = arg;
  907. AVFrame *buf = td->in;
  908. AVFrame *out_buf = td->out;
  909. BiquadsContext *s = ctx->priv;
  910. const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
  911. const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
  912. int ch;
  913. for (ch = start; ch < end; ch++) {
  914. enum AVChannel channel = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
  915. if (av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0) {
  916. if (buf != out_buf)
  917. memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
  918. buf->nb_samples * s->block_align);
  919. continue;
  920. }
  921. if (!s->block_samples) {
  922. s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
  923. &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
  924. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  925. } else {
  926. memcpy(s->block[0]->extended_data[ch] + s->block_align * s->block_samples, buf->extended_data[ch],
  927. buf->nb_samples * s->block_align);
  928. s->filter(s, s->block[0]->extended_data[ch], s->block[1]->extended_data[ch], s->block_samples,
  929. &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
  930. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  931. s->cache[ch].ri1 = s->cache[ch].i1;
  932. s->cache[ch].ri2 = s->cache[ch].i2;
  933. s->cache[ch].ro1 = s->cache[ch].o1;
  934. s->cache[ch].ro2 = s->cache[ch].o2;
  935. s->filter(s, s->block[0]->extended_data[ch] + s->block_samples * s->block_align,
  936. s->block[1]->extended_data[ch] + s->block_samples * s->block_align,
  937. s->block_samples,
  938. &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2,
  939. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  940. reverse_samples(s->block[2], s->block[1], ch, 0, 0, s->block_samples * 2);
  941. s->cache[ch].ri1 = 0.;
  942. s->cache[ch].ri2 = 0.;
  943. s->cache[ch].ro1 = 0.;
  944. s->cache[ch].ro2 = 0.;
  945. s->filter(s, s->block[2]->extended_data[ch], s->block[2]->extended_data[ch], s->block[2]->nb_samples,
  946. &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2,
  947. s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
  948. reverse_samples(out_buf, s->block[2], ch, 0, s->block_samples, out_buf->nb_samples);
  949. memmove(s->block[0]->extended_data[ch], s->block[0]->extended_data[ch] + s->block_align * s->block_samples,
  950. s->block_samples * s->block_align);
  951. }
  952. }
  953. return 0;
  954. }
  955. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  956. {
  957. AVFilterContext *ctx = inlink->dst;
  958. BiquadsContext *s = ctx->priv;
  959. AVFilterLink *outlink = ctx->outputs[0];
  960. AVFrame *out_buf;
  961. ThreadData td;
  962. int ch, ret;
  963. if (s->bypass)
  964. return ff_filter_frame(outlink, buf);
  965. ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout);
  966. if (ret < 0) {
  967. av_frame_free(&buf);
  968. return ret;
  969. }
  970. if (strcmp(s->ch_layout_str, "all"))
  971. av_channel_layout_from_string(&s->ch_layout,
  972. s->ch_layout_str);
  973. if (av_frame_is_writable(buf)) {
  974. out_buf = buf;
  975. } else {
  976. out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
  977. if (!out_buf) {
  978. av_frame_free(&buf);
  979. return AVERROR(ENOMEM);
  980. }
  981. av_frame_copy_props(out_buf, buf);
  982. }
  983. td.in = buf;
  984. td.out = out_buf;
  985. ff_filter_execute(ctx, filter_channel, &td, NULL,
  986. FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
  987. for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
  988. if (s->cache[ch].clippings > 0)
  989. av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
  990. ch, s->cache[ch].clippings);
  991. s->cache[ch].clippings = 0;
  992. }
  993. if (buf != out_buf)
  994. av_frame_free(&buf);
  995. return ff_filter_frame(outlink, out_buf);
  996. }
  997. static int activate(AVFilterContext *ctx)
  998. {
  999. AVFilterLink *inlink = ctx->inputs[0];
  1000. AVFilterLink *outlink = ctx->outputs[0];
  1001. BiquadsContext *s = ctx->priv;
  1002. AVFrame *in = NULL;
  1003. int ret;
  1004. FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
  1005. if (s->block_samples > 0) {
  1006. ret = ff_inlink_consume_samples(inlink, s->block_samples, s->block_samples, &in);
  1007. } else {
  1008. ret = ff_inlink_consume_frame(inlink, &in);
  1009. }
  1010. if (ret < 0)
  1011. return ret;
  1012. if (ret > 0)
  1013. return filter_frame(inlink, in);
  1014. if (s->block_samples > 0 && ff_inlink_queued_samples(inlink) >= s->block_samples) {
  1015. ff_filter_set_ready(ctx, 10);
  1016. return 0;
  1017. }
  1018. FF_FILTER_FORWARD_STATUS(inlink, outlink);
  1019. FF_FILTER_FORWARD_WANTED(outlink, inlink);
  1020. return FFERROR_NOT_READY;
  1021. }
  1022. static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  1023. char *res, int res_len, int flags)
  1024. {
  1025. AVFilterLink *outlink = ctx->outputs[0];
  1026. int ret;
  1027. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  1028. if (ret < 0)
  1029. return ret;
  1030. return config_filter(outlink, 0);
  1031. }
  1032. static av_cold void uninit(AVFilterContext *ctx)
  1033. {
  1034. BiquadsContext *s = ctx->priv;
  1035. for (int i = 0; i < 3; i++)
  1036. av_frame_free(&s->block[i]);
  1037. av_freep(&s->cache);
  1038. av_channel_layout_uninit(&s->ch_layout);
  1039. }
  1040. static const AVFilterPad inputs[] = {
  1041. {
  1042. .name = "default",
  1043. .type = AVMEDIA_TYPE_AUDIO,
  1044. },
  1045. };
  1046. static const AVFilterPad outputs[] = {
  1047. {
  1048. .name = "default",
  1049. .type = AVMEDIA_TYPE_AUDIO,
  1050. .config_props = config_output,
  1051. },
  1052. };
  1053. #define OFFSET(x) offsetof(BiquadsContext, x)
  1054. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  1055. #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  1056. #define DEFINE_BIQUAD_FILTER_2(name_, description_, priv_class_) \
  1057. static av_cold int name_##_init(AVFilterContext *ctx) \
  1058. { \
  1059. BiquadsContext *s = ctx->priv; \
  1060. s->filter_type = name_; \
  1061. return 0; \
  1062. } \
  1063. \
  1064. const AVFilter ff_af_##name_ = { \
  1065. .name = #name_, \
  1066. .description = NULL_IF_CONFIG_SMALL(description_), \
  1067. .priv_class = &priv_class_##_class, \
  1068. .priv_size = sizeof(BiquadsContext), \
  1069. .init = name_##_init, \
  1070. .activate = activate, \
  1071. .uninit = uninit, \
  1072. FILTER_INPUTS(inputs), \
  1073. FILTER_OUTPUTS(outputs), \
  1074. FILTER_QUERY_FUNC(query_formats), \
  1075. .process_command = process_command, \
  1076. .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
  1077. }
  1078. #define DEFINE_BIQUAD_FILTER(name, description) \
  1079. AVFILTER_DEFINE_CLASS(name); \
  1080. DEFINE_BIQUAD_FILTER_2(name, description, name)
  1081. #if CONFIG_EQUALIZER_FILTER
  1082. static const AVOption equalizer_options[] = {
  1083. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  1084. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
  1085. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1086. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1087. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1088. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1089. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1090. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1091. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1092. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  1093. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
  1094. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1095. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1096. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1097. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1098. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1099. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1100. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1101. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1102. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1103. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1104. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1105. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1106. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1107. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1108. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1109. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1110. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1111. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1112. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1113. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1114. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1115. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1116. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1117. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1118. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1119. {NULL}
  1120. };
  1121. DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
  1122. #endif /* CONFIG_EQUALIZER_FILTER */
  1123. #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER
  1124. static const AVOption bass_lowshelf_options[] = {
  1125. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  1126. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
  1127. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1128. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1129. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1130. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1131. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1132. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1133. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1134. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1135. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1136. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1137. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1138. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1139. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1140. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1141. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1142. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1143. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1144. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1145. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1146. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1147. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1148. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1149. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1150. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1151. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1152. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1153. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1154. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1155. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1156. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1157. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1158. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1159. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1160. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1161. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1162. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1163. {NULL}
  1164. };
  1165. AVFILTER_DEFINE_CLASS_EXT(bass_lowshelf, "bass/lowshelf", bass_lowshelf_options);
  1166. #if CONFIG_BASS_FILTER
  1167. DEFINE_BIQUAD_FILTER_2(bass, "Boost or cut lower frequencies.", bass_lowshelf);
  1168. #endif /* CONFIG_BASS_FILTER */
  1169. #if CONFIG_LOWSHELF_FILTER
  1170. DEFINE_BIQUAD_FILTER_2(lowshelf, "Apply a low shelf filter.", bass_lowshelf);
  1171. #endif /* CONFIG_LOWSHELF_FILTER */
  1172. #endif /* CONFIG_BASS_FILTER || CONFIG LOWSHELF_FILTER */
  1173. #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER
  1174. static const AVOption treble_highshelf_options[] = {
  1175. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1176. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1177. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1178. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1179. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1180. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1181. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1182. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1183. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1184. {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1185. {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1186. {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1187. {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
  1188. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1189. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1190. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1191. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1192. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1193. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1194. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1195. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1196. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1197. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1198. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1199. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1200. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1201. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1202. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1203. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1204. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1205. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1206. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1207. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1208. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1209. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1210. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1211. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1212. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1213. {NULL}
  1214. };
  1215. AVFILTER_DEFINE_CLASS_EXT(treble_highshelf, "treble/highshelf",
  1216. treble_highshelf_options);
  1217. #if CONFIG_TREBLE_FILTER
  1218. DEFINE_BIQUAD_FILTER_2(treble, "Boost or cut upper frequencies.", treble_highshelf);
  1219. #endif /* CONFIG_TREBLE_FILTER */
  1220. #if CONFIG_HIGHSHELF_FILTER
  1221. DEFINE_BIQUAD_FILTER_2(highshelf, "Apply a high shelf filter.", treble_highshelf);
  1222. #endif /* CONFIG_HIGHSHELF_FILTER */
  1223. #endif /* CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER */
  1224. #if CONFIG_BANDPASS_FILTER
  1225. static const AVOption bandpass_options[] = {
  1226. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1227. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1228. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1229. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1230. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1231. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1232. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1233. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1234. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1235. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1236. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1237. {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1238. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1239. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1240. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1241. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1242. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1243. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1244. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1245. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1246. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1247. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1248. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1249. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1250. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1251. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1252. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1253. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1254. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1255. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1256. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1257. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1258. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1259. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1260. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1261. {NULL}
  1262. };
  1263. DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
  1264. #endif /* CONFIG_BANDPASS_FILTER */
  1265. #if CONFIG_BANDREJECT_FILTER
  1266. static const AVOption bandreject_options[] = {
  1267. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1268. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1269. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1270. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1271. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1272. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1273. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1274. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1275. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1276. {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1277. {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
  1278. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1279. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1280. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1281. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1282. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1283. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1284. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1285. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1286. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1287. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1288. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1289. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1290. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1291. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1292. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1293. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1294. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1295. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1296. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1297. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1298. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1299. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1300. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1301. {NULL}
  1302. };
  1303. DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
  1304. #endif /* CONFIG_BANDREJECT_FILTER */
  1305. #if CONFIG_LOWPASS_FILTER
  1306. static const AVOption lowpass_options[] = {
  1307. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  1308. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
  1309. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1310. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1311. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1312. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1313. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1314. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1315. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1316. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1317. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1318. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1319. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1320. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1321. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1322. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1323. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1324. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1325. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1326. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1327. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1328. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1329. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1330. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1331. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1332. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1333. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1334. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1335. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1336. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1337. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1338. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1339. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1340. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1341. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1342. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1343. {NULL}
  1344. };
  1345. DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
  1346. #endif /* CONFIG_LOWPASS_FILTER */
  1347. #if CONFIG_HIGHPASS_FILTER
  1348. static const AVOption highpass_options[] = {
  1349. {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1350. {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1351. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1352. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1353. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1354. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1355. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1356. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1357. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1358. {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1359. {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
  1360. {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1361. {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
  1362. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1363. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1364. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1365. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1366. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1367. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1368. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1369. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1370. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1371. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1372. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1373. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1374. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1375. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1376. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1377. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1378. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1379. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1380. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1381. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1382. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1383. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1384. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1385. {NULL}
  1386. };
  1387. DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
  1388. #endif /* CONFIG_HIGHPASS_FILTER */
  1389. #if CONFIG_ALLPASS_FILTER
  1390. static const AVOption allpass_options[] = {
  1391. {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1392. {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
  1393. {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1394. {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
  1395. {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
  1396. {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
  1397. {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
  1398. {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
  1399. {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
  1400. {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  1401. {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
  1402. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1403. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1404. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1405. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1406. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1407. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1408. {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1409. {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
  1410. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1411. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1412. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1413. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1414. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1415. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1416. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1417. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1418. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1419. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1420. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1421. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1422. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1423. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1424. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1425. {NULL}
  1426. };
  1427. DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
  1428. #endif /* CONFIG_ALLPASS_FILTER */
  1429. #if CONFIG_BIQUAD_FILTER
  1430. static const AVOption biquad_options[] = {
  1431. {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
  1432. {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1433. {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1434. {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1435. {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1436. {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
  1437. {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1438. {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  1439. {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1440. {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS},
  1441. {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1442. {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
  1443. {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1444. {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
  1445. {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
  1446. {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
  1447. {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"},
  1448. {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
  1449. {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
  1450. {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
  1451. {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1452. {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
  1453. {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
  1454. {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
  1455. {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
  1456. {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
  1457. {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
  1458. {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1459. {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF},
  1460. {NULL}
  1461. };
  1462. DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
  1463. #endif /* CONFIG_BIQUAD_FILTER */