af_surround.c 69 KB

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