You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1520 lines
54KB

  1. /*
  2. * Copyright (c) 2017 Paul B Mahol
  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/audio_fifo.h"
  21. #include "libavutil/channel_layout.h"
  22. #include "libavutil/opt.h"
  23. #include "libavcodec/avfft.h"
  24. #include "avfilter.h"
  25. #include "audio.h"
  26. #include "formats.h"
  27. #include "window_func.h"
  28. typedef struct AudioSurroundContext {
  29. const AVClass *class;
  30. char *out_channel_layout_str;
  31. char *in_channel_layout_str;
  32. float level_in;
  33. float level_out;
  34. float fc_in;
  35. float fc_out;
  36. float lfe_in;
  37. float lfe_out;
  38. int win_func;
  39. float overlap;
  40. float *input_levels;
  41. float *output_levels;
  42. int output_lfe;
  43. int lowcutf;
  44. int highcutf;
  45. float lowcut;
  46. float highcut;
  47. uint64_t out_channel_layout;
  48. uint64_t in_channel_layout;
  49. int nb_in_channels;
  50. int nb_out_channels;
  51. AVFrame *input;
  52. AVFrame *output;
  53. AVFrame *overlap_buffer;
  54. int buf_size;
  55. int hop_size;
  56. AVAudioFifo *fifo;
  57. RDFTContext **rdft, **irdft;
  58. float *window_func_lut;
  59. int64_t pts;
  60. void (*filter)(AVFilterContext *ctx);
  61. void (*upmix_stereo)(AVFilterContext *ctx,
  62. float l_phase,
  63. float r_phase,
  64. float c_phase,
  65. float mag_total,
  66. float x, float y,
  67. int n);
  68. void (*upmix_2_1)(AVFilterContext *ctx,
  69. float l_phase,
  70. float r_phase,
  71. float c_phase,
  72. float mag_total,
  73. float lfe_im,
  74. float lfe_re,
  75. float x, float y,
  76. int n);
  77. void (*upmix_3_0)(AVFilterContext *ctx,
  78. float l_phase,
  79. float r_phase,
  80. float c_mag,
  81. float c_phase,
  82. float mag_total,
  83. float x, float y,
  84. int n);
  85. void (*upmix_5_0)(AVFilterContext *ctx,
  86. float c_re, float c_im,
  87. float mag_totall, float mag_totalr,
  88. float fl_phase, float fr_phase,
  89. float bl_phase, float br_phase,
  90. float sl_phase, float sr_phase,
  91. float xl, float yl,
  92. float xr, float yr,
  93. int n);
  94. void (*upmix_5_1)(AVFilterContext *ctx,
  95. float c_re, float c_im,
  96. float lfe_re, float lfe_im,
  97. float mag_totall, float mag_totalr,
  98. float fl_phase, float fr_phase,
  99. float bl_phase, float br_phase,
  100. float sl_phase, float sr_phase,
  101. float xl, float yl,
  102. float xr, float yr,
  103. int n);
  104. } AudioSurroundContext;
  105. static int query_formats(AVFilterContext *ctx)
  106. {
  107. AudioSurroundContext *s = ctx->priv;
  108. AVFilterFormats *formats = NULL;
  109. AVFilterChannelLayouts *layouts = NULL;
  110. int ret;
  111. ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
  112. if (ret)
  113. return ret;
  114. ret = ff_set_common_formats(ctx, formats);
  115. if (ret)
  116. return ret;
  117. layouts = NULL;
  118. ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
  119. if (ret)
  120. return ret;
  121. ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
  122. if (ret)
  123. return ret;
  124. layouts = NULL;
  125. ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
  126. if (ret)
  127. return ret;
  128. ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
  129. if (ret)
  130. return ret;
  131. formats = ff_all_samplerates();
  132. if (!formats)
  133. return AVERROR(ENOMEM);
  134. return ff_set_common_samplerates(ctx, formats);
  135. }
  136. static int config_input(AVFilterLink *inlink)
  137. {
  138. AVFilterContext *ctx = inlink->dst;
  139. AudioSurroundContext *s = ctx->priv;
  140. int ch;
  141. s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
  142. if (!s->rdft)
  143. return AVERROR(ENOMEM);
  144. for (ch = 0; ch < inlink->channels; ch++) {
  145. s->rdft[ch] = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
  146. if (!s->rdft[ch])
  147. return AVERROR(ENOMEM);
  148. }
  149. s->nb_in_channels = inlink->channels;
  150. s->input_levels = av_malloc_array(s->nb_in_channels, sizeof(*s->input_levels));
  151. if (!s->input_levels)
  152. return AVERROR(ENOMEM);
  153. for (ch = 0; ch < s->nb_in_channels; ch++)
  154. s->input_levels[ch] = s->level_in;
  155. ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
  156. if (ch >= 0)
  157. s->input_levels[ch] *= s->fc_in;
  158. ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
  159. if (ch >= 0)
  160. s->input_levels[ch] *= s->lfe_in;
  161. s->input = ff_get_audio_buffer(inlink, s->buf_size * 2);
  162. if (!s->input)
  163. return AVERROR(ENOMEM);
  164. s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->buf_size);
  165. if (!s->fifo)
  166. return AVERROR(ENOMEM);
  167. s->lowcut = 1.f * s->lowcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
  168. s->highcut = 1.f * s->highcutf / (inlink->sample_rate * 0.5) * (s->buf_size / 2);
  169. return 0;
  170. }
  171. static int config_output(AVFilterLink *outlink)
  172. {
  173. AVFilterContext *ctx = outlink->src;
  174. AudioSurroundContext *s = ctx->priv;
  175. int ch;
  176. s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
  177. if (!s->irdft)
  178. return AVERROR(ENOMEM);
  179. for (ch = 0; ch < outlink->channels; ch++) {
  180. s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
  181. if (!s->irdft[ch])
  182. return AVERROR(ENOMEM);
  183. }
  184. s->nb_out_channels = outlink->channels;
  185. s->output_levels = av_malloc_array(s->nb_out_channels, sizeof(*s->output_levels));
  186. if (!s->output_levels)
  187. return AVERROR(ENOMEM);
  188. for (ch = 0; ch < s->nb_out_channels; ch++)
  189. s->output_levels[ch] = s->level_out;
  190. ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER);
  191. if (ch >= 0)
  192. s->output_levels[ch] *= s->fc_out;
  193. ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY);
  194. if (ch >= 0)
  195. s->output_levels[ch] *= s->lfe_out;
  196. s->output = ff_get_audio_buffer(outlink, s->buf_size * 2);
  197. s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
  198. if (!s->overlap_buffer || !s->output)
  199. return AVERROR(ENOMEM);
  200. return 0;
  201. }
  202. static void stereo_position(float a, float p, float *x, float *y)
  203. {
  204. *x = av_clipf(a+FFMAX(0, sinf(p-M_PI_2))*FFDIFFSIGN(a,0), -1, 1);
  205. *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1, -1, 1);
  206. }
  207. static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut,
  208. float *lfe_mag, float *mag_total)
  209. {
  210. if (output_lfe && n < highcut) {
  211. *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut)));
  212. *lfe_mag *= *mag_total;
  213. *mag_total -= *lfe_mag;
  214. } else {
  215. *lfe_mag = 0.f;
  216. }
  217. }
  218. static void upmix_1_0(AVFilterContext *ctx,
  219. float l_phase,
  220. float r_phase,
  221. float c_phase,
  222. float mag_total,
  223. float x, float y,
  224. int n)
  225. {
  226. AudioSurroundContext *s = ctx->priv;
  227. float mag, *dst;
  228. dst = (float *)s->output->extended_data[0];
  229. mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  230. dst[2 * n ] = mag * cosf(c_phase);
  231. dst[2 * n + 1] = mag * sinf(c_phase);
  232. }
  233. static void upmix_stereo(AVFilterContext *ctx,
  234. float l_phase,
  235. float r_phase,
  236. float c_phase,
  237. float mag_total,
  238. float x, float y,
  239. int n)
  240. {
  241. AudioSurroundContext *s = ctx->priv;
  242. float l_mag, r_mag, *dstl, *dstr;
  243. dstl = (float *)s->output->extended_data[0];
  244. dstr = (float *)s->output->extended_data[1];
  245. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  246. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  247. dstl[2 * n ] = l_mag * cosf(l_phase);
  248. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  249. dstr[2 * n ] = r_mag * cosf(r_phase);
  250. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  251. }
  252. static void upmix_2_1(AVFilterContext *ctx,
  253. float l_phase,
  254. float r_phase,
  255. float c_phase,
  256. float mag_total,
  257. float x, float y,
  258. int n)
  259. {
  260. AudioSurroundContext *s = ctx->priv;
  261. float lfe_mag, l_mag, r_mag, *dstl, *dstr, *dstlfe;
  262. dstl = (float *)s->output->extended_data[0];
  263. dstr = (float *)s->output->extended_data[1];
  264. dstlfe = (float *)s->output->extended_data[2];
  265. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  266. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  267. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  268. dstl[2 * n ] = l_mag * cosf(l_phase);
  269. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  270. dstr[2 * n ] = r_mag * cosf(r_phase);
  271. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  272. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  273. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  274. }
  275. static void upmix_3_0(AVFilterContext *ctx,
  276. float l_phase,
  277. float r_phase,
  278. float c_phase,
  279. float mag_total,
  280. float x, float y,
  281. int n)
  282. {
  283. AudioSurroundContext *s = ctx->priv;
  284. float l_mag, r_mag, c_mag, *dstc, *dstl, *dstr;
  285. dstl = (float *)s->output->extended_data[0];
  286. dstr = (float *)s->output->extended_data[1];
  287. dstc = (float *)s->output->extended_data[2];
  288. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  289. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  290. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  291. dstl[2 * n ] = l_mag * cosf(l_phase);
  292. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  293. dstr[2 * n ] = r_mag * cosf(r_phase);
  294. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  295. dstc[2 * n ] = c_mag * cosf(c_phase);
  296. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  297. }
  298. static void upmix_3_1(AVFilterContext *ctx,
  299. float l_phase,
  300. float r_phase,
  301. float c_phase,
  302. float mag_total,
  303. float x, float y,
  304. int n)
  305. {
  306. AudioSurroundContext *s = ctx->priv;
  307. float lfe_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstlfe;
  308. dstl = (float *)s->output->extended_data[0];
  309. dstr = (float *)s->output->extended_data[1];
  310. dstc = (float *)s->output->extended_data[2];
  311. dstlfe = (float *)s->output->extended_data[3];
  312. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  313. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  314. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  315. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  316. dstl[2 * n ] = l_mag * cosf(l_phase);
  317. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  318. dstr[2 * n ] = r_mag * cosf(r_phase);
  319. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  320. dstc[2 * n ] = c_mag * cosf(c_phase);
  321. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  322. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  323. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  324. }
  325. static void upmix_3_1_surround(AVFilterContext *ctx,
  326. float l_phase,
  327. float r_phase,
  328. float c_phase,
  329. float c_mag,
  330. float mag_total,
  331. float x, float y,
  332. int n)
  333. {
  334. AudioSurroundContext *s = ctx->priv;
  335. float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
  336. dstl = (float *)s->output->extended_data[0];
  337. dstr = (float *)s->output->extended_data[1];
  338. dstc = (float *)s->output->extended_data[2];
  339. dstlfe = (float *)s->output->extended_data[3];
  340. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag);
  341. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  342. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  343. dstl[2 * n ] = l_mag * cosf(l_phase);
  344. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  345. dstr[2 * n ] = r_mag * cosf(r_phase);
  346. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  347. dstc[2 * n ] = c_mag * cosf(c_phase);
  348. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  349. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  350. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  351. }
  352. static void upmix_4_0(AVFilterContext *ctx,
  353. float l_phase,
  354. float r_phase,
  355. float c_phase,
  356. float mag_total,
  357. float x, float y,
  358. int n)
  359. {
  360. float b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb;
  361. AudioSurroundContext *s = ctx->priv;
  362. dstl = (float *)s->output->extended_data[0];
  363. dstr = (float *)s->output->extended_data[1];
  364. dstc = (float *)s->output->extended_data[2];
  365. dstb = (float *)s->output->extended_data[3];
  366. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  367. b_mag = sqrtf(1.f - fabsf(x)) * ((1.f - y) * .5f) * mag_total;
  368. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  369. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  370. dstl[2 * n ] = l_mag * cosf(l_phase);
  371. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  372. dstr[2 * n ] = r_mag * cosf(r_phase);
  373. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  374. dstc[2 * n ] = c_mag * cosf(c_phase);
  375. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  376. dstb[2 * n ] = b_mag * cosf(c_phase);
  377. dstb[2 * n + 1] = b_mag * sinf(c_phase);
  378. }
  379. static void upmix_4_1(AVFilterContext *ctx,
  380. float l_phase,
  381. float r_phase,
  382. float c_phase,
  383. float mag_total,
  384. float x, float y,
  385. int n)
  386. {
  387. float lfe_mag, b_mag, l_mag, r_mag, c_mag, *dstc, *dstl, *dstr, *dstb, *dstlfe;
  388. AudioSurroundContext *s = ctx->priv;
  389. dstl = (float *)s->output->extended_data[0];
  390. dstr = (float *)s->output->extended_data[1];
  391. dstc = (float *)s->output->extended_data[2];
  392. dstlfe = (float *)s->output->extended_data[3];
  393. dstb = (float *)s->output->extended_data[4];
  394. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  395. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  396. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  397. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  398. b_mag = sqrtf(1.f - fabsf(x)) * ((1.f - y) * .5f) * mag_total;
  399. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  400. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  401. dstl[2 * n ] = l_mag * cosf(l_phase);
  402. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  403. dstr[2 * n ] = r_mag * cosf(r_phase);
  404. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  405. dstc[2 * n ] = c_mag * cosf(c_phase);
  406. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  407. dstb[2 * n ] = b_mag * cosf(c_phase);
  408. dstb[2 * n + 1] = b_mag * sinf(c_phase);
  409. }
  410. static void upmix_5_0_back(AVFilterContext *ctx,
  411. float l_phase,
  412. float r_phase,
  413. float c_phase,
  414. float mag_total,
  415. float x, float y,
  416. int n)
  417. {
  418. float l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs;
  419. AudioSurroundContext *s = ctx->priv;
  420. dstl = (float *)s->output->extended_data[0];
  421. dstr = (float *)s->output->extended_data[1];
  422. dstc = (float *)s->output->extended_data[2];
  423. dstls = (float *)s->output->extended_data[3];
  424. dstrs = (float *)s->output->extended_data[4];
  425. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  426. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  427. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  428. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  429. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  430. dstl[2 * n ] = l_mag * cosf(l_phase);
  431. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  432. dstr[2 * n ] = r_mag * cosf(r_phase);
  433. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  434. dstc[2 * n ] = c_mag * cosf(c_phase);
  435. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  436. dstls[2 * n ] = ls_mag * cosf(l_phase);
  437. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  438. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  439. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  440. }
  441. static void upmix_5_1_back(AVFilterContext *ctx,
  442. float l_phase,
  443. float r_phase,
  444. float c_phase,
  445. float mag_total,
  446. float x, float y,
  447. int n)
  448. {
  449. float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlfe;
  450. AudioSurroundContext *s = ctx->priv;
  451. dstl = (float *)s->output->extended_data[0];
  452. dstr = (float *)s->output->extended_data[1];
  453. dstc = (float *)s->output->extended_data[2];
  454. dstlfe = (float *)s->output->extended_data[3];
  455. dstls = (float *)s->output->extended_data[4];
  456. dstrs = (float *)s->output->extended_data[5];
  457. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  458. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  459. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  460. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  461. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  462. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  463. dstl[2 * n ] = l_mag * cosf(l_phase);
  464. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  465. dstr[2 * n ] = r_mag * cosf(r_phase);
  466. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  467. dstc[2 * n ] = c_mag * cosf(c_phase);
  468. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  469. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  470. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  471. dstls[2 * n ] = ls_mag * cosf(l_phase);
  472. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  473. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  474. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  475. }
  476. static void upmix_5_1_back_surround(AVFilterContext *ctx,
  477. float l_phase,
  478. float r_phase,
  479. float c_phase,
  480. float c_mag,
  481. float mag_total,
  482. float x, float y,
  483. int n)
  484. {
  485. AudioSurroundContext *s = ctx->priv;
  486. float lfe_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
  487. float ls_mag, rs_mag, *dstls, *dstrs;
  488. dstl = (float *)s->output->extended_data[0];
  489. dstr = (float *)s->output->extended_data[1];
  490. dstc = (float *)s->output->extended_data[2];
  491. dstlfe = (float *)s->output->extended_data[3];
  492. dstls = (float *)s->output->extended_data[4];
  493. dstrs = (float *)s->output->extended_data[5];
  494. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &c_mag);
  495. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  496. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  497. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  498. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  499. dstl[2 * n ] = l_mag * cosf(l_phase);
  500. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  501. dstr[2 * n ] = r_mag * cosf(r_phase);
  502. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  503. dstc[2 * n ] = c_mag * cosf(c_phase);
  504. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  505. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  506. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  507. dstls[2 * n ] = ls_mag * cosf(l_phase);
  508. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  509. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  510. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  511. }
  512. static void upmix_5_1_back_2_1(AVFilterContext *ctx,
  513. float l_phase,
  514. float r_phase,
  515. float c_phase,
  516. float mag_total,
  517. float lfe_re,
  518. float lfe_im,
  519. float x, float y,
  520. int n)
  521. {
  522. AudioSurroundContext *s = ctx->priv;
  523. float c_mag, l_mag, r_mag, *dstc, *dstl, *dstr, *dstlfe;
  524. float ls_mag, rs_mag, *dstls, *dstrs;
  525. dstl = (float *)s->output->extended_data[0];
  526. dstr = (float *)s->output->extended_data[1];
  527. dstc = (float *)s->output->extended_data[2];
  528. dstlfe = (float *)s->output->extended_data[3];
  529. dstls = (float *)s->output->extended_data[4];
  530. dstrs = (float *)s->output->extended_data[5];
  531. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  532. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  533. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  534. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  535. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  536. dstl[2 * n ] = l_mag * cosf(l_phase);
  537. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  538. dstr[2 * n ] = r_mag * cosf(r_phase);
  539. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  540. dstc[2 * n ] = c_mag * cosf(c_phase);
  541. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  542. dstlfe[2 * n ] = lfe_re;
  543. dstlfe[2 * n + 1] = lfe_im;
  544. dstls[2 * n ] = ls_mag * cosf(l_phase);
  545. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  546. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  547. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  548. }
  549. static void upmix_7_0(AVFilterContext *ctx,
  550. float l_phase,
  551. float r_phase,
  552. float c_phase,
  553. float mag_total,
  554. float x, float y,
  555. int n)
  556. {
  557. float l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
  558. float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb;
  559. AudioSurroundContext *s = ctx->priv;
  560. dstl = (float *)s->output->extended_data[0];
  561. dstr = (float *)s->output->extended_data[1];
  562. dstc = (float *)s->output->extended_data[2];
  563. dstlb = (float *)s->output->extended_data[3];
  564. dstrb = (float *)s->output->extended_data[4];
  565. dstls = (float *)s->output->extended_data[5];
  566. dstrs = (float *)s->output->extended_data[6];
  567. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  568. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  569. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  570. lb_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  571. rb_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  572. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - fabsf(y)) * mag_total;
  573. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - fabsf(y)) * mag_total;
  574. dstl[2 * n ] = l_mag * cosf(l_phase);
  575. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  576. dstr[2 * n ] = r_mag * cosf(r_phase);
  577. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  578. dstc[2 * n ] = c_mag * cosf(c_phase);
  579. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  580. dstlb[2 * n ] = lb_mag * cosf(l_phase);
  581. dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
  582. dstrb[2 * n ] = rb_mag * cosf(r_phase);
  583. dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
  584. dstls[2 * n ] = ls_mag * cosf(l_phase);
  585. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  586. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  587. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  588. }
  589. static void upmix_7_1(AVFilterContext *ctx,
  590. float l_phase,
  591. float r_phase,
  592. float c_phase,
  593. float mag_total,
  594. float x, float y,
  595. int n)
  596. {
  597. float lfe_mag, l_mag, r_mag, ls_mag, rs_mag, c_mag, lb_mag, rb_mag;
  598. float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
  599. AudioSurroundContext *s = ctx->priv;
  600. dstl = (float *)s->output->extended_data[0];
  601. dstr = (float *)s->output->extended_data[1];
  602. dstc = (float *)s->output->extended_data[2];
  603. dstlfe = (float *)s->output->extended_data[3];
  604. dstlb = (float *)s->output->extended_data[4];
  605. dstrb = (float *)s->output->extended_data[5];
  606. dstls = (float *)s->output->extended_data[6];
  607. dstrs = (float *)s->output->extended_data[7];
  608. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  609. c_mag = sqrtf(1.f - fabsf(x)) * ((y + 1.f) * .5f) * mag_total;
  610. l_mag = sqrtf(.5f * ( x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  611. r_mag = sqrtf(.5f * (-x + 1.f)) * ((y + 1.f) * .5f) * mag_total;
  612. lb_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  613. rb_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - ((y + 1.f) * .5f)) * mag_total;
  614. ls_mag = sqrtf(.5f * ( x + 1.f)) * (1.f - fabsf(y)) * mag_total;
  615. rs_mag = sqrtf(.5f * (-x + 1.f)) * (1.f - fabsf(y)) * mag_total;
  616. dstl[2 * n ] = l_mag * cosf(l_phase);
  617. dstl[2 * n + 1] = l_mag * sinf(l_phase);
  618. dstr[2 * n ] = r_mag * cosf(r_phase);
  619. dstr[2 * n + 1] = r_mag * sinf(r_phase);
  620. dstc[2 * n ] = c_mag * cosf(c_phase);
  621. dstc[2 * n + 1] = c_mag * sinf(c_phase);
  622. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  623. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  624. dstlb[2 * n ] = lb_mag * cosf(l_phase);
  625. dstlb[2 * n + 1] = lb_mag * sinf(l_phase);
  626. dstrb[2 * n ] = rb_mag * cosf(r_phase);
  627. dstrb[2 * n + 1] = rb_mag * sinf(r_phase);
  628. dstls[2 * n ] = ls_mag * cosf(l_phase);
  629. dstls[2 * n + 1] = ls_mag * sinf(l_phase);
  630. dstrs[2 * n ] = rs_mag * cosf(r_phase);
  631. dstrs[2 * n + 1] = rs_mag * sinf(r_phase);
  632. }
  633. static void upmix_7_1_5_0_side(AVFilterContext *ctx,
  634. float c_re, float c_im,
  635. float mag_totall, float mag_totalr,
  636. float fl_phase, float fr_phase,
  637. float bl_phase, float br_phase,
  638. float sl_phase, float sr_phase,
  639. float xl, float yl,
  640. float xr, float yr,
  641. int n)
  642. {
  643. float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
  644. float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
  645. float lfe_mag, c_phase, mag_total = (mag_totall + mag_totalr) * 0.5;
  646. AudioSurroundContext *s = ctx->priv;
  647. dstl = (float *)s->output->extended_data[0];
  648. dstr = (float *)s->output->extended_data[1];
  649. dstc = (float *)s->output->extended_data[2];
  650. dstlfe = (float *)s->output->extended_data[3];
  651. dstlb = (float *)s->output->extended_data[4];
  652. dstrb = (float *)s->output->extended_data[5];
  653. dstls = (float *)s->output->extended_data[6];
  654. dstrs = (float *)s->output->extended_data[7];
  655. c_phase = atan2f(c_im, c_re);
  656. get_lfe(s->output_lfe, n, s->lowcut, s->highcut, &lfe_mag, &mag_total);
  657. fl_mag = sqrtf(.5f * (xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
  658. fr_mag = sqrtf(.5f * (xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
  659. lb_mag = sqrtf(.5f * (-xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
  660. rb_mag = sqrtf(.5f * (-xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
  661. ls_mag = sqrtf(1.f - fabsf(xl)) * ((yl + 1.f) * .5f) * mag_totall;
  662. rs_mag = sqrtf(1.f - fabsf(xr)) * ((yr + 1.f) * .5f) * mag_totalr;
  663. dstl[2 * n ] = fl_mag * cosf(fl_phase);
  664. dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
  665. dstr[2 * n ] = fr_mag * cosf(fr_phase);
  666. dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
  667. dstc[2 * n ] = c_re;
  668. dstc[2 * n + 1] = c_im;
  669. dstlfe[2 * n ] = lfe_mag * cosf(c_phase);
  670. dstlfe[2 * n + 1] = lfe_mag * sinf(c_phase);
  671. dstlb[2 * n ] = lb_mag * cosf(bl_phase);
  672. dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
  673. dstrb[2 * n ] = rb_mag * cosf(br_phase);
  674. dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
  675. dstls[2 * n ] = ls_mag * cosf(sl_phase);
  676. dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
  677. dstrs[2 * n ] = rs_mag * cosf(sr_phase);
  678. dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
  679. }
  680. static void upmix_7_1_5_1(AVFilterContext *ctx,
  681. float c_re, float c_im,
  682. float lfe_re, float lfe_im,
  683. float mag_totall, float mag_totalr,
  684. float fl_phase, float fr_phase,
  685. float bl_phase, float br_phase,
  686. float sl_phase, float sr_phase,
  687. float xl, float yl,
  688. float xr, float yr,
  689. int n)
  690. {
  691. float fl_mag, fr_mag, ls_mag, rs_mag, lb_mag, rb_mag;
  692. float *dstc, *dstl, *dstr, *dstls, *dstrs, *dstlb, *dstrb, *dstlfe;
  693. AudioSurroundContext *s = ctx->priv;
  694. dstl = (float *)s->output->extended_data[0];
  695. dstr = (float *)s->output->extended_data[1];
  696. dstc = (float *)s->output->extended_data[2];
  697. dstlfe = (float *)s->output->extended_data[3];
  698. dstlb = (float *)s->output->extended_data[4];
  699. dstrb = (float *)s->output->extended_data[5];
  700. dstls = (float *)s->output->extended_data[6];
  701. dstrs = (float *)s->output->extended_data[7];
  702. fl_mag = sqrtf(.5f * (xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
  703. fr_mag = sqrtf(.5f * (xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
  704. lb_mag = sqrtf(.5f * (-xl + 1.f)) * ((yl + 1.f) * .5f) * mag_totall;
  705. rb_mag = sqrtf(.5f * (-xr + 1.f)) * ((yr + 1.f) * .5f) * mag_totalr;
  706. ls_mag = sqrtf(1.f - fabsf(xl)) * ((yl + 1.f) * .5f) * mag_totall;
  707. rs_mag = sqrtf(1.f - fabsf(xr)) * ((yr + 1.f) * .5f) * mag_totalr;
  708. dstl[2 * n ] = fl_mag * cosf(fl_phase);
  709. dstl[2 * n + 1] = fl_mag * sinf(fl_phase);
  710. dstr[2 * n ] = fr_mag * cosf(fr_phase);
  711. dstr[2 * n + 1] = fr_mag * sinf(fr_phase);
  712. dstc[2 * n ] = c_re;
  713. dstc[2 * n + 1] = c_im;
  714. dstlfe[2 * n ] = lfe_re;
  715. dstlfe[2 * n + 1] = lfe_im;
  716. dstlb[2 * n ] = lb_mag * cosf(bl_phase);
  717. dstlb[2 * n + 1] = lb_mag * sinf(bl_phase);
  718. dstrb[2 * n ] = rb_mag * cosf(br_phase);
  719. dstrb[2 * n + 1] = rb_mag * sinf(br_phase);
  720. dstls[2 * n ] = ls_mag * cosf(sl_phase);
  721. dstls[2 * n + 1] = ls_mag * sinf(sl_phase);
  722. dstrs[2 * n ] = rs_mag * cosf(sr_phase);
  723. dstrs[2 * n + 1] = rs_mag * sinf(sr_phase);
  724. }
  725. static void filter_stereo(AVFilterContext *ctx)
  726. {
  727. AudioSurroundContext *s = ctx->priv;
  728. float *srcl, *srcr;
  729. int n;
  730. srcl = (float *)s->input->extended_data[0];
  731. srcr = (float *)s->input->extended_data[1];
  732. for (n = 0; n < s->buf_size; n++) {
  733. float l_re = srcl[2 * n], r_re = srcr[2 * n];
  734. float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
  735. float c_phase = atan2f(l_im + r_im, l_re + r_re);
  736. float l_mag = hypotf(l_re, l_im);
  737. float r_mag = hypotf(r_re, r_im);
  738. float l_phase = atan2f(l_im, l_re);
  739. float r_phase = atan2f(r_im, r_re);
  740. float phase_dif = fabsf(l_phase - r_phase);
  741. float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
  742. float mag_total = hypotf(l_mag, r_mag);
  743. float x, y;
  744. if (phase_dif > M_PI)
  745. phase_dif = 2 * M_PI - phase_dif;
  746. stereo_position(mag_dif, phase_dif, &x, &y);
  747. s->upmix_stereo(ctx, l_phase, r_phase, c_phase, mag_total, x, y, n);
  748. }
  749. }
  750. static void filter_surround(AVFilterContext *ctx)
  751. {
  752. AudioSurroundContext *s = ctx->priv;
  753. float *srcl, *srcr, *srcc;
  754. int n;
  755. srcl = (float *)s->input->extended_data[0];
  756. srcr = (float *)s->input->extended_data[1];
  757. srcc = (float *)s->input->extended_data[2];
  758. for (n = 0; n < s->buf_size; n++) {
  759. float l_re = srcl[2 * n], r_re = srcr[2 * n];
  760. float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
  761. float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
  762. float c_mag = hypotf(c_re, c_im);
  763. float c_phase = atan2f(c_im, c_re);
  764. float l_mag = hypotf(l_re, l_im);
  765. float r_mag = hypotf(r_re, r_im);
  766. float l_phase = atan2f(l_im, l_re);
  767. float r_phase = atan2f(r_im, r_re);
  768. float phase_dif = fabsf(l_phase - r_phase);
  769. float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
  770. float mag_total = hypotf(l_mag, r_mag);
  771. float x, y;
  772. if (phase_dif > M_PI)
  773. phase_dif = 2 * M_PI - phase_dif;
  774. stereo_position(mag_dif, phase_dif, &x, &y);
  775. s->upmix_3_0(ctx, l_phase, r_phase, c_phase, c_mag, mag_total, x, y, n);
  776. }
  777. }
  778. static void filter_2_1(AVFilterContext *ctx)
  779. {
  780. AudioSurroundContext *s = ctx->priv;
  781. float *srcl, *srcr, *srclfe;
  782. int n;
  783. srcl = (float *)s->input->extended_data[0];
  784. srcr = (float *)s->input->extended_data[1];
  785. srclfe = (float *)s->input->extended_data[2];
  786. for (n = 0; n < s->buf_size; n++) {
  787. float l_re = srcl[2 * n], r_re = srcr[2 * n];
  788. float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
  789. float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
  790. float c_phase = atan2f(l_im + r_im, l_re + r_re);
  791. float l_mag = hypotf(l_re, l_im);
  792. float r_mag = hypotf(r_re, r_im);
  793. float l_phase = atan2f(l_im, l_re);
  794. float r_phase = atan2f(r_im, r_re);
  795. float phase_dif = fabsf(l_phase - r_phase);
  796. float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
  797. float mag_total = hypotf(l_mag, r_mag);
  798. float x, y;
  799. if (phase_dif > M_PI)
  800. phase_dif = 2 * M_PI - phase_dif;
  801. stereo_position(mag_dif, phase_dif, &x, &y);
  802. s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
  803. }
  804. }
  805. static void filter_5_0_side(AVFilterContext *ctx)
  806. {
  807. AudioSurroundContext *s = ctx->priv;
  808. float *srcl, *srcr, *srcc, *srcsl, *srcsr;
  809. int n;
  810. srcl = (float *)s->input->extended_data[0];
  811. srcr = (float *)s->input->extended_data[1];
  812. srcc = (float *)s->input->extended_data[2];
  813. srcsl = (float *)s->input->extended_data[3];
  814. srcsr = (float *)s->input->extended_data[4];
  815. for (n = 0; n < s->buf_size; n++) {
  816. float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
  817. float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
  818. float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
  819. float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
  820. float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
  821. float fl_mag = hypotf(fl_re, fl_im);
  822. float fr_mag = hypotf(fr_re, fr_im);
  823. float fl_phase = atan2f(fl_im, fl_re);
  824. float fr_phase = atan2f(fr_im, fr_re);
  825. float sl_mag = hypotf(sl_re, sl_im);
  826. float sr_mag = hypotf(sr_re, sr_im);
  827. float sl_phase = atan2f(sl_im, sl_re);
  828. float sr_phase = atan2f(sr_im, sr_re);
  829. float phase_difl = fabsf(fl_phase - sl_phase);
  830. float phase_difr = fabsf(fr_phase - sr_phase);
  831. float mag_difl = (fl_mag - sl_mag) / (fl_mag + sl_mag);
  832. float mag_difr = (fr_mag - sr_mag) / (fr_mag + sr_mag);
  833. float mag_totall = hypotf(fl_mag, sl_mag);
  834. float mag_totalr = hypotf(fr_mag, sr_mag);
  835. float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
  836. float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
  837. float xl, yl;
  838. float xr, yr;
  839. if (phase_difl > M_PI)
  840. phase_difl = 2 * M_PI - phase_difl;
  841. if (phase_difr > M_PI)
  842. phase_difr = 2 * M_PI - phase_difr;
  843. stereo_position(mag_difl, phase_difl, &xl, &yl);
  844. stereo_position(mag_difr, phase_difr, &xr, &yr);
  845. s->upmix_5_0(ctx, c_re, c_im,
  846. mag_totall, mag_totalr,
  847. fl_phase, fr_phase,
  848. bl_phase, br_phase,
  849. sl_phase, sr_phase,
  850. xl, yl, xr, yr, n);
  851. }
  852. }
  853. static void filter_5_1_side(AVFilterContext *ctx)
  854. {
  855. AudioSurroundContext *s = ctx->priv;
  856. float *srcl, *srcr, *srcc, *srclfe, *srcsl, *srcsr;
  857. int n;
  858. srcl = (float *)s->input->extended_data[0];
  859. srcr = (float *)s->input->extended_data[1];
  860. srcc = (float *)s->input->extended_data[2];
  861. srclfe = (float *)s->input->extended_data[3];
  862. srcsl = (float *)s->input->extended_data[4];
  863. srcsr = (float *)s->input->extended_data[5];
  864. for (n = 0; n < s->buf_size; n++) {
  865. float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
  866. float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
  867. float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
  868. float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
  869. float sl_re = srcsl[2 * n], sl_im = srcsl[2 * n + 1];
  870. float sr_re = srcsr[2 * n], sr_im = srcsr[2 * n + 1];
  871. float fl_mag = hypotf(fl_re, fl_im);
  872. float fr_mag = hypotf(fr_re, fr_im);
  873. float fl_phase = atan2f(fl_im, fl_re);
  874. float fr_phase = atan2f(fr_im, fr_re);
  875. float sl_mag = hypotf(sl_re, sl_im);
  876. float sr_mag = hypotf(sr_re, sr_im);
  877. float sl_phase = atan2f(sl_im, sl_re);
  878. float sr_phase = atan2f(sr_im, sr_re);
  879. float phase_difl = fabsf(fl_phase - sl_phase);
  880. float phase_difr = fabsf(fr_phase - sr_phase);
  881. float mag_difl = (fl_mag - sl_mag) / (fl_mag + sl_mag);
  882. float mag_difr = (fr_mag - sr_mag) / (fr_mag + sr_mag);
  883. float mag_totall = hypotf(fl_mag, sl_mag);
  884. float mag_totalr = hypotf(fr_mag, sr_mag);
  885. float bl_phase = atan2f(fl_im + sl_im, fl_re + sl_re);
  886. float br_phase = atan2f(fr_im + sr_im, fr_re + sr_re);
  887. float xl, yl;
  888. float xr, yr;
  889. if (phase_difl > M_PI)
  890. phase_difl = 2 * M_PI - phase_difl;
  891. if (phase_difr > M_PI)
  892. phase_difr = 2 * M_PI - phase_difr;
  893. stereo_position(mag_difl, phase_difl, &xl, &yl);
  894. stereo_position(mag_difr, phase_difr, &xr, &yr);
  895. s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
  896. mag_totall, mag_totalr,
  897. fl_phase, fr_phase,
  898. bl_phase, br_phase,
  899. sl_phase, sr_phase,
  900. xl, yl, xr, yr, n);
  901. }
  902. }
  903. static void filter_5_1_back(AVFilterContext *ctx)
  904. {
  905. AudioSurroundContext *s = ctx->priv;
  906. float *srcl, *srcr, *srcc, *srclfe, *srcbl, *srcbr;
  907. int n;
  908. srcl = (float *)s->input->extended_data[0];
  909. srcr = (float *)s->input->extended_data[1];
  910. srcc = (float *)s->input->extended_data[2];
  911. srclfe = (float *)s->input->extended_data[3];
  912. srcbl = (float *)s->input->extended_data[4];
  913. srcbr = (float *)s->input->extended_data[5];
  914. for (n = 0; n < s->buf_size; n++) {
  915. float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
  916. float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
  917. float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
  918. float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
  919. float bl_re = srcbl[2 * n], bl_im = srcbl[2 * n + 1];
  920. float br_re = srcbr[2 * n], br_im = srcbr[2 * n + 1];
  921. float fl_mag = hypotf(fl_re, fl_im);
  922. float fr_mag = hypotf(fr_re, fr_im);
  923. float fl_phase = atan2f(fl_im, fl_re);
  924. float fr_phase = atan2f(fr_im, fr_re);
  925. float bl_mag = hypotf(bl_re, bl_im);
  926. float br_mag = hypotf(br_re, br_im);
  927. float bl_phase = atan2f(bl_im, bl_re);
  928. float br_phase = atan2f(br_im, br_re);
  929. float phase_difl = fabsf(fl_phase - bl_phase);
  930. float phase_difr = fabsf(fr_phase - br_phase);
  931. float mag_difl = (fl_mag - bl_mag) / (fl_mag + bl_mag);
  932. float mag_difr = (fr_mag - br_mag) / (fr_mag + br_mag);
  933. float mag_totall = hypotf(fl_mag, bl_mag);
  934. float mag_totalr = hypotf(fr_mag, br_mag);
  935. float sl_phase = atan2f(fl_im + bl_im, fl_re + bl_re);
  936. float sr_phase = atan2f(fr_im + br_im, fr_re + br_re);
  937. float xl, yl;
  938. float xr, yr;
  939. if (phase_difl > M_PI)
  940. phase_difl = 2 * M_PI - phase_difl;
  941. if (phase_difr > M_PI)
  942. phase_difr = 2 * M_PI - phase_difr;
  943. stereo_position(mag_difl, phase_difl, &xl, &yl);
  944. stereo_position(mag_difr, phase_difr, &xr, &yr);
  945. s->upmix_5_1(ctx, c_re, c_im, lfe_re, lfe_im,
  946. mag_totall, mag_totalr,
  947. fl_phase, fr_phase,
  948. bl_phase, br_phase,
  949. sl_phase, sr_phase,
  950. xl, yl, xr, yr, n);
  951. }
  952. }
  953. static int init(AVFilterContext *ctx)
  954. {
  955. AudioSurroundContext *s = ctx->priv;
  956. float overlap;
  957. int i;
  958. if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
  959. av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
  960. s->out_channel_layout_str);
  961. return AVERROR(EINVAL);
  962. }
  963. if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
  964. av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
  965. s->in_channel_layout_str);
  966. return AVERROR(EINVAL);
  967. }
  968. if (s->lowcutf >= s->highcutf) {
  969. av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
  970. s->lowcutf, s->highcutf);
  971. return AVERROR(EINVAL);
  972. }
  973. switch (s->in_channel_layout) {
  974. case AV_CH_LAYOUT_STEREO:
  975. s->filter = filter_stereo;
  976. switch (s->out_channel_layout) {
  977. case AV_CH_LAYOUT_MONO:
  978. s->upmix_stereo = upmix_1_0;
  979. break;
  980. case AV_CH_LAYOUT_STEREO:
  981. s->upmix_stereo = upmix_stereo;
  982. break;
  983. case AV_CH_LAYOUT_2POINT1:
  984. s->upmix_stereo = upmix_2_1;
  985. break;
  986. case AV_CH_LAYOUT_SURROUND:
  987. s->upmix_stereo = upmix_3_0;
  988. break;
  989. case AV_CH_LAYOUT_3POINT1:
  990. s->upmix_stereo = upmix_3_1;
  991. break;
  992. case AV_CH_LAYOUT_4POINT0:
  993. s->upmix_stereo = upmix_4_0;
  994. break;
  995. case AV_CH_LAYOUT_4POINT1:
  996. s->upmix_stereo = upmix_4_1;
  997. break;
  998. case AV_CH_LAYOUT_5POINT0_BACK:
  999. s->upmix_stereo = upmix_5_0_back;
  1000. break;
  1001. case AV_CH_LAYOUT_5POINT1_BACK:
  1002. s->upmix_stereo = upmix_5_1_back;
  1003. break;
  1004. case AV_CH_LAYOUT_7POINT0:
  1005. s->upmix_stereo = upmix_7_0;
  1006. break;
  1007. case AV_CH_LAYOUT_7POINT1:
  1008. s->upmix_stereo = upmix_7_1;
  1009. break;
  1010. default:
  1011. goto fail;
  1012. }
  1013. break;
  1014. case AV_CH_LAYOUT_2POINT1:
  1015. s->filter = filter_2_1;
  1016. switch (s->out_channel_layout) {
  1017. case AV_CH_LAYOUT_5POINT1_BACK:
  1018. s->upmix_2_1 = upmix_5_1_back_2_1;
  1019. break;
  1020. default:
  1021. goto fail;
  1022. }
  1023. break;
  1024. case AV_CH_LAYOUT_SURROUND:
  1025. s->filter = filter_surround;
  1026. switch (s->out_channel_layout) {
  1027. case AV_CH_LAYOUT_3POINT1:
  1028. s->upmix_3_0 = upmix_3_1_surround;
  1029. break;
  1030. case AV_CH_LAYOUT_5POINT1_BACK:
  1031. s->upmix_3_0 = upmix_5_1_back_surround;
  1032. break;
  1033. default:
  1034. goto fail;
  1035. }
  1036. break;
  1037. case AV_CH_LAYOUT_5POINT0:
  1038. s->filter = filter_5_0_side;
  1039. switch (s->out_channel_layout) {
  1040. case AV_CH_LAYOUT_7POINT1:
  1041. s->upmix_5_0 = upmix_7_1_5_0_side;
  1042. break;
  1043. default:
  1044. goto fail;
  1045. }
  1046. break;
  1047. case AV_CH_LAYOUT_5POINT1:
  1048. s->filter = filter_5_1_side;
  1049. switch (s->out_channel_layout) {
  1050. case AV_CH_LAYOUT_7POINT1:
  1051. s->upmix_5_1 = upmix_7_1_5_1;
  1052. break;
  1053. default:
  1054. goto fail;
  1055. }
  1056. break;
  1057. case AV_CH_LAYOUT_5POINT1_BACK:
  1058. s->filter = filter_5_1_back;
  1059. switch (s->out_channel_layout) {
  1060. case AV_CH_LAYOUT_7POINT1:
  1061. s->upmix_5_1 = upmix_7_1_5_1;
  1062. break;
  1063. default:
  1064. goto fail;
  1065. }
  1066. break;
  1067. default:
  1068. fail:
  1069. av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
  1070. s->in_channel_layout_str, s->out_channel_layout_str);
  1071. return AVERROR(EINVAL);
  1072. }
  1073. s->buf_size = 4096;
  1074. s->pts = AV_NOPTS_VALUE;
  1075. s->window_func_lut = av_calloc(s->buf_size, sizeof(*s->window_func_lut));
  1076. if (!s->window_func_lut)
  1077. return AVERROR(ENOMEM);
  1078. generate_window_func(s->window_func_lut, s->buf_size, s->win_func, &overlap);
  1079. if (s->overlap == 1)
  1080. s->overlap = overlap;
  1081. for (i = 0; i < s->buf_size; i++)
  1082. s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->buf_size);
  1083. s->hop_size = s->buf_size * (1. - s->overlap);
  1084. if (s->hop_size <= 0)
  1085. return AVERROR(EINVAL);
  1086. return 0;
  1087. }
  1088. static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
  1089. {
  1090. AudioSurroundContext *s = ctx->priv;
  1091. const float level_in = s->input_levels[ch];
  1092. float *dst;
  1093. int n;
  1094. memset(s->input->extended_data[ch] + s->buf_size * sizeof(float), 0, s->buf_size * sizeof(float));
  1095. dst = (float *)s->input->extended_data[ch];
  1096. for (n = 0; n < s->buf_size; n++) {
  1097. dst[n] *= s->window_func_lut[n] * level_in;
  1098. }
  1099. av_rdft_calc(s->rdft[ch], (float *)s->input->extended_data[ch]);
  1100. return 0;
  1101. }
  1102. static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
  1103. {
  1104. AudioSurroundContext *s = ctx->priv;
  1105. const float level_out = s->output_levels[ch];
  1106. AVFrame *out = arg;
  1107. float *dst, *ptr;
  1108. int n;
  1109. av_rdft_calc(s->irdft[ch], (float *)s->output->extended_data[ch]);
  1110. dst = (float *)s->output->extended_data[ch];
  1111. ptr = (float *)s->overlap_buffer->extended_data[ch];
  1112. memmove(s->overlap_buffer->extended_data[ch],
  1113. s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
  1114. s->buf_size * sizeof(float));
  1115. memset(s->overlap_buffer->extended_data[ch] + s->buf_size * sizeof(float),
  1116. 0, s->hop_size * sizeof(float));
  1117. for (n = 0; n < s->buf_size; n++) {
  1118. ptr[n] += dst[n] * s->window_func_lut[n] * level_out;
  1119. }
  1120. ptr = (float *)s->overlap_buffer->extended_data[ch];
  1121. dst = (float *)out->extended_data[ch];
  1122. memcpy(dst, ptr, s->hop_size * sizeof(float));
  1123. return 0;
  1124. }
  1125. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  1126. {
  1127. AVFilterContext *ctx = inlink->dst;
  1128. AVFilterLink *outlink = ctx->outputs[0];
  1129. AudioSurroundContext *s = ctx->priv;
  1130. int ret;
  1131. ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
  1132. in->nb_samples);
  1133. if (ret >= 0 && s->pts == AV_NOPTS_VALUE)
  1134. s->pts = in->pts;
  1135. av_frame_free(&in);
  1136. if (ret < 0)
  1137. return ret;
  1138. while (av_audio_fifo_size(s->fifo) >= s->buf_size) {
  1139. AVFrame *out;
  1140. ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size);
  1141. if (ret < 0)
  1142. return ret;
  1143. ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels);
  1144. s->filter(ctx);
  1145. out = ff_get_audio_buffer(outlink, s->hop_size);
  1146. if (!out)
  1147. return AVERROR(ENOMEM);
  1148. ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels);
  1149. out->pts = s->pts;
  1150. if (s->pts != AV_NOPTS_VALUE)
  1151. s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base);
  1152. av_audio_fifo_drain(s->fifo, s->hop_size);
  1153. ret = ff_filter_frame(outlink, out);
  1154. if (ret < 0)
  1155. return ret;
  1156. }
  1157. return 0;
  1158. }
  1159. static int request_frame(AVFilterLink *outlink)
  1160. {
  1161. AVFilterContext *ctx = outlink->src;
  1162. AudioSurroundContext *s = ctx->priv;
  1163. int ret = 0;
  1164. ret = ff_request_frame(ctx->inputs[0]);
  1165. if (ret == AVERROR_EOF && av_audio_fifo_size(s->fifo) > 0 && av_audio_fifo_size(s->fifo) < s->buf_size) {
  1166. AVFrame *in;
  1167. in = ff_get_audio_buffer(outlink, s->buf_size - av_audio_fifo_size(s->fifo));
  1168. if (!in)
  1169. return AVERROR(ENOMEM);
  1170. ret = filter_frame(ctx->inputs[0], in);
  1171. av_audio_fifo_drain(s->fifo, s->buf_size);
  1172. }
  1173. return ret;
  1174. }
  1175. static av_cold void uninit(AVFilterContext *ctx)
  1176. {
  1177. AudioSurroundContext *s = ctx->priv;
  1178. int ch;
  1179. av_frame_free(&s->input);
  1180. av_frame_free(&s->output);
  1181. av_frame_free(&s->overlap_buffer);
  1182. for (ch = 0; ch < s->nb_in_channels; ch++) {
  1183. av_rdft_end(s->rdft[ch]);
  1184. }
  1185. for (ch = 0; ch < s->nb_out_channels; ch++) {
  1186. av_rdft_end(s->irdft[ch]);
  1187. }
  1188. av_freep(&s->input_levels);
  1189. av_freep(&s->output_levels);
  1190. av_freep(&s->rdft);
  1191. av_freep(&s->irdft);
  1192. av_audio_fifo_free(s->fifo);
  1193. av_freep(&s->window_func_lut);
  1194. }
  1195. #define OFFSET(x) offsetof(AudioSurroundContext, x)
  1196. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  1197. static const AVOption surround_options[] = {
  1198. { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
  1199. { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
  1200. { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1201. { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1202. { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
  1203. { "lfe_low", "LFE low cut off", OFFSET(lowcutf), AV_OPT_TYPE_INT, {.i64=128}, 0, 256, FLAGS },
  1204. { "lfe_high", "LFE high cut off", OFFSET(highcutf), AV_OPT_TYPE_INT, {.i64=256}, 0, 512, FLAGS },
  1205. { "fc_in", "set front center channel input level", OFFSET(fc_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1206. { "fc_out", "set front center channel output level", OFFSET(fc_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1207. { "lfe_in", "set lfe channel input level", OFFSET(lfe_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1208. { "lfe_out", "set lfe channel output level", OFFSET(lfe_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, FLAGS },
  1209. { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
  1210. { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, FLAGS, "win_func" },
  1211. { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
  1212. { "hann", "Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
  1213. { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
  1214. { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
  1215. { "blackman", "Blackman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
  1216. { "welch", "Welch", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH}, 0, 0, FLAGS, "win_func" },
  1217. { "flattop", "Flat-top", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP}, 0, 0, FLAGS, "win_func" },
  1218. { "bharris", "Blackman-Harris", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS}, 0, 0, FLAGS, "win_func" },
  1219. { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
  1220. { "bhann", "Bartlett-Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN}, 0, 0, FLAGS, "win_func" },
  1221. { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, FLAGS, "win_func" },
  1222. { "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
  1223. { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
  1224. { "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
  1225. { "tukey", "Tukey", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY}, 0, 0, FLAGS, "win_func" },
  1226. { "dolph", "Dolph-Chebyshev", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH}, 0, 0, FLAGS, "win_func" },
  1227. { "cauchy", "Cauchy", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY}, 0, 0, FLAGS, "win_func" },
  1228. { "parzen", "Parzen", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN}, 0, 0, FLAGS, "win_func" },
  1229. { "poisson", "Poisson", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON}, 0, 0, FLAGS, "win_func" },
  1230. { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, FLAGS, "win_func" },
  1231. { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS },
  1232. { NULL }
  1233. };
  1234. AVFILTER_DEFINE_CLASS(surround);
  1235. static const AVFilterPad inputs[] = {
  1236. {
  1237. .name = "default",
  1238. .type = AVMEDIA_TYPE_AUDIO,
  1239. .filter_frame = filter_frame,
  1240. .config_props = config_input,
  1241. },
  1242. { NULL }
  1243. };
  1244. static const AVFilterPad outputs[] = {
  1245. {
  1246. .name = "default",
  1247. .type = AVMEDIA_TYPE_AUDIO,
  1248. .request_frame = request_frame,
  1249. .config_props = config_output,
  1250. },
  1251. { NULL }
  1252. };
  1253. AVFilter ff_af_surround = {
  1254. .name = "surround",
  1255. .description = NULL_IF_CONFIG_SMALL("Apply audio surround upmix filter."),
  1256. .query_formats = query_formats,
  1257. .priv_size = sizeof(AudioSurroundContext),
  1258. .priv_class = &surround_class,
  1259. .init = init,
  1260. .uninit = uninit,
  1261. .inputs = inputs,
  1262. .outputs = outputs,
  1263. .flags = AVFILTER_FLAG_SLICE_THREADS,
  1264. };