af_surround.c 68 KB

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