2
0

opus_celt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright (c) 2012 Andrew D'Addesio
  3. * Copyright (c) 2013-2014 Mozilla Corporation
  4. * Copyright (c) 2016 Rostislav Pehlivanov <atomnuker@gmail.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Opus CELT decoder
  25. */
  26. #include "opus_celt.h"
  27. #include "opustab.h"
  28. #include "opus_pvq.h"
  29. /* Use the 2D z-transform to apply prediction in both the time domain (alpha)
  30. * and the frequency domain (beta) */
  31. static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc)
  32. {
  33. int i, j;
  34. float prev[2] = { 0 };
  35. float alpha = ff_celt_alpha_coef[f->size];
  36. float beta = ff_celt_beta_coef[f->size];
  37. const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0];
  38. /* intra frame */
  39. if (opus_rc_tell(rc) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) {
  40. alpha = 0.0f;
  41. beta = 1.0f - (4915.0f/32768.0f);
  42. model = ff_celt_coarse_energy_dist[f->size][1];
  43. }
  44. for (i = 0; i < CELT_MAX_BANDS; i++) {
  45. for (j = 0; j < f->channels; j++) {
  46. CeltBlock *block = &f->block[j];
  47. float value;
  48. int available;
  49. if (i < f->start_band || i >= f->end_band) {
  50. block->energy[i] = 0.0;
  51. continue;
  52. }
  53. available = f->framebits - opus_rc_tell(rc);
  54. if (available >= 15) {
  55. /* decode using a Laplace distribution */
  56. int k = FFMIN(i, 20) << 1;
  57. value = ff_opus_rc_dec_laplace(rc, model[k] << 7, model[k+1] << 6);
  58. } else if (available >= 2) {
  59. int x = ff_opus_rc_dec_cdf(rc, ff_celt_model_energy_small);
  60. value = (x>>1) ^ -(x&1);
  61. } else if (available >= 1) {
  62. value = -(float)ff_opus_rc_dec_log(rc, 1);
  63. } else value = -1;
  64. block->energy[i] = FFMAX(-9.0f, block->energy[i]) * alpha + prev[j] + value;
  65. prev[j] += beta * value;
  66. }
  67. }
  68. }
  69. static void celt_decode_fine_energy(CeltFrame *f, OpusRangeCoder *rc)
  70. {
  71. int i;
  72. for (i = f->start_band; i < f->end_band; i++) {
  73. int j;
  74. if (!f->fine_bits[i])
  75. continue;
  76. for (j = 0; j < f->channels; j++) {
  77. CeltBlock *block = &f->block[j];
  78. int q2;
  79. float offset;
  80. q2 = ff_opus_rc_get_raw(rc, f->fine_bits[i]);
  81. offset = (q2 + 0.5f) * (1 << (14 - f->fine_bits[i])) / 16384.0f - 0.5f;
  82. block->energy[i] += offset;
  83. }
  84. }
  85. }
  86. static void celt_decode_final_energy(CeltFrame *f, OpusRangeCoder *rc)
  87. {
  88. int priority, i, j;
  89. int bits_left = f->framebits - opus_rc_tell(rc);
  90. for (priority = 0; priority < 2; priority++) {
  91. for (i = f->start_band; i < f->end_band && bits_left >= f->channels; i++) {
  92. if (f->fine_priority[i] != priority || f->fine_bits[i] >= CELT_MAX_FINE_BITS)
  93. continue;
  94. for (j = 0; j < f->channels; j++) {
  95. int q2;
  96. float offset;
  97. q2 = ff_opus_rc_get_raw(rc, 1);
  98. offset = (q2 - 0.5f) * (1 << (14 - f->fine_bits[i] - 1)) / 16384.0f;
  99. f->block[j].energy[i] += offset;
  100. bits_left--;
  101. }
  102. }
  103. }
  104. }
  105. static void celt_decode_tf_changes(CeltFrame *f, OpusRangeCoder *rc)
  106. {
  107. int i, diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit;
  108. int consumed, bits = f->transient ? 2 : 4;
  109. consumed = opus_rc_tell(rc);
  110. tf_select_bit = (f->size != 0 && consumed+bits+1 <= f->framebits);
  111. for (i = f->start_band; i < f->end_band; i++) {
  112. if (consumed+bits+tf_select_bit <= f->framebits) {
  113. diff ^= ff_opus_rc_dec_log(rc, bits);
  114. consumed = opus_rc_tell(rc);
  115. tf_changed |= diff;
  116. }
  117. f->tf_change[i] = diff;
  118. bits = f->transient ? 4 : 5;
  119. }
  120. if (tf_select_bit && ff_celt_tf_select[f->size][f->transient][0][tf_changed] !=
  121. ff_celt_tf_select[f->size][f->transient][1][tf_changed])
  122. tf_select = ff_opus_rc_dec_log(rc, 1);
  123. for (i = f->start_band; i < f->end_band; i++) {
  124. f->tf_change[i] = ff_celt_tf_select[f->size][f->transient][tf_select][f->tf_change[i]];
  125. }
  126. }
  127. static void celt_denormalize(CeltFrame *f, CeltBlock *block, float *data)
  128. {
  129. int i, j;
  130. for (i = f->start_band; i < f->end_band; i++) {
  131. float *dst = data + (ff_celt_freq_bands[i] << f->size);
  132. float log_norm = block->energy[i] + ff_celt_mean_energy[i];
  133. float norm = exp2f(FFMIN(log_norm, 32.0f));
  134. for (j = 0; j < ff_celt_freq_range[i] << f->size; j++)
  135. dst[j] *= norm;
  136. }
  137. }
  138. static void celt_postfilter_apply_transition(CeltBlock *block, float *data)
  139. {
  140. const int T0 = block->pf_period_old;
  141. const int T1 = block->pf_period;
  142. float g00, g01, g02;
  143. float g10, g11, g12;
  144. float x0, x1, x2, x3, x4;
  145. int i;
  146. if (block->pf_gains[0] == 0.0 &&
  147. block->pf_gains_old[0] == 0.0)
  148. return;
  149. g00 = block->pf_gains_old[0];
  150. g01 = block->pf_gains_old[1];
  151. g02 = block->pf_gains_old[2];
  152. g10 = block->pf_gains[0];
  153. g11 = block->pf_gains[1];
  154. g12 = block->pf_gains[2];
  155. x1 = data[-T1 + 1];
  156. x2 = data[-T1];
  157. x3 = data[-T1 - 1];
  158. x4 = data[-T1 - 2];
  159. for (i = 0; i < CELT_OVERLAP; i++) {
  160. float w = ff_celt_window2[i];
  161. x0 = data[i - T1 + 2];
  162. data[i] += (1.0 - w) * g00 * data[i - T0] +
  163. (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) +
  164. (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) +
  165. w * g10 * x2 +
  166. w * g11 * (x1 + x3) +
  167. w * g12 * (x0 + x4);
  168. x4 = x3;
  169. x3 = x2;
  170. x2 = x1;
  171. x1 = x0;
  172. }
  173. }
  174. static void celt_postfilter_apply(CeltBlock *block, float *data, int len)
  175. {
  176. const int T = block->pf_period;
  177. float g0, g1, g2;
  178. float x0, x1, x2, x3, x4;
  179. int i;
  180. if (block->pf_gains[0] == 0.0 || len <= 0)
  181. return;
  182. g0 = block->pf_gains[0];
  183. g1 = block->pf_gains[1];
  184. g2 = block->pf_gains[2];
  185. x4 = data[-T - 2];
  186. x3 = data[-T - 1];
  187. x2 = data[-T];
  188. x1 = data[-T + 1];
  189. for (i = 0; i < len; i++) {
  190. x0 = data[i - T + 2];
  191. data[i] += g0 * x2 +
  192. g1 * (x1 + x3) +
  193. g2 * (x0 + x4);
  194. x4 = x3;
  195. x3 = x2;
  196. x2 = x1;
  197. x1 = x0;
  198. }
  199. }
  200. static void celt_postfilter(CeltFrame *f, CeltBlock *block)
  201. {
  202. int len = f->blocksize * f->blocks;
  203. celt_postfilter_apply_transition(block, block->buf + 1024);
  204. block->pf_period_old = block->pf_period;
  205. memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains));
  206. block->pf_period = block->pf_period_new;
  207. memcpy(block->pf_gains, block->pf_gains_new, sizeof(block->pf_gains));
  208. if (len > CELT_OVERLAP) {
  209. celt_postfilter_apply_transition(block, block->buf + 1024 + CELT_OVERLAP);
  210. celt_postfilter_apply(block, block->buf + 1024 + 2 * CELT_OVERLAP,
  211. len - 2 * CELT_OVERLAP);
  212. block->pf_period_old = block->pf_period;
  213. memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains));
  214. }
  215. memmove(block->buf, block->buf + len, (1024 + CELT_OVERLAP / 2) * sizeof(float));
  216. }
  217. static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed)
  218. {
  219. int i;
  220. memset(f->block[0].pf_gains_new, 0, sizeof(f->block[0].pf_gains_new));
  221. memset(f->block[1].pf_gains_new, 0, sizeof(f->block[1].pf_gains_new));
  222. if (f->start_band == 0 && consumed + 16 <= f->framebits) {
  223. int has_postfilter = ff_opus_rc_dec_log(rc, 1);
  224. if (has_postfilter) {
  225. float gain;
  226. int tapset, octave, period;
  227. octave = ff_opus_rc_dec_uint(rc, 6);
  228. period = (16 << octave) + ff_opus_rc_get_raw(rc, 4 + octave) - 1;
  229. gain = 0.09375f * (ff_opus_rc_get_raw(rc, 3) + 1);
  230. tapset = (opus_rc_tell(rc) + 2 <= f->framebits) ?
  231. ff_opus_rc_dec_cdf(rc, ff_celt_model_tapset) : 0;
  232. for (i = 0; i < 2; i++) {
  233. CeltBlock *block = &f->block[i];
  234. block->pf_period_new = FFMAX(period, CELT_POSTFILTER_MINPERIOD);
  235. block->pf_gains_new[0] = gain * ff_celt_postfilter_taps[tapset][0];
  236. block->pf_gains_new[1] = gain * ff_celt_postfilter_taps[tapset][1];
  237. block->pf_gains_new[2] = gain * ff_celt_postfilter_taps[tapset][2];
  238. }
  239. }
  240. consumed = opus_rc_tell(rc);
  241. }
  242. return consumed;
  243. }
  244. static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X)
  245. {
  246. int i, j, k;
  247. for (i = f->start_band; i < f->end_band; i++) {
  248. int renormalize = 0;
  249. float *xptr;
  250. float prev[2];
  251. float Ediff, r;
  252. float thresh, sqrt_1;
  253. int depth;
  254. /* depth in 1/8 bits */
  255. depth = (1 + f->pulses[i]) / (ff_celt_freq_range[i] << f->size);
  256. thresh = exp2f(-1.0 - 0.125f * depth);
  257. sqrt_1 = 1.0f / sqrtf(ff_celt_freq_range[i] << f->size);
  258. xptr = X + (ff_celt_freq_bands[i] << f->size);
  259. prev[0] = block->prev_energy[0][i];
  260. prev[1] = block->prev_energy[1][i];
  261. if (f->channels == 1) {
  262. CeltBlock *block1 = &f->block[1];
  263. prev[0] = FFMAX(prev[0], block1->prev_energy[0][i]);
  264. prev[1] = FFMAX(prev[1], block1->prev_energy[1][i]);
  265. }
  266. Ediff = block->energy[i] - FFMIN(prev[0], prev[1]);
  267. Ediff = FFMAX(0, Ediff);
  268. /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because
  269. short blocks don't have the same energy as long */
  270. r = exp2f(1 - Ediff);
  271. if (f->size == 3)
  272. r *= M_SQRT2;
  273. r = FFMIN(thresh, r) * sqrt_1;
  274. for (k = 0; k < 1 << f->size; k++) {
  275. /* Detect collapse */
  276. if (!(block->collapse_masks[i] & 1 << k)) {
  277. /* Fill with noise */
  278. for (j = 0; j < ff_celt_freq_range[i]; j++)
  279. xptr[(j << f->size) + k] = (celt_rng(f) & 0x8000) ? r : -r;
  280. renormalize = 1;
  281. }
  282. }
  283. /* We just added some energy, so we need to renormalize */
  284. if (renormalize)
  285. celt_renormalize_vector(xptr, ff_celt_freq_range[i] << f->size, 1.0f);
  286. }
  287. }
  288. int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc,
  289. float **output, int channels, int frame_size,
  290. int start_band, int end_band)
  291. {
  292. int i, j, downmix = 0;
  293. int consumed; // bits of entropy consumed thus far for this frame
  294. MDCT15Context *imdct;
  295. if (channels != 1 && channels != 2) {
  296. av_log(f->avctx, AV_LOG_ERROR, "Invalid number of coded channels: %d\n",
  297. channels);
  298. return AVERROR_INVALIDDATA;
  299. }
  300. if (start_band < 0 || start_band > end_band || end_band > CELT_MAX_BANDS) {
  301. av_log(f->avctx, AV_LOG_ERROR, "Invalid start/end band: %d %d\n",
  302. start_band, end_band);
  303. return AVERROR_INVALIDDATA;
  304. }
  305. f->silence = 0;
  306. f->transient = 0;
  307. f->anticollapse = 0;
  308. f->flushed = 0;
  309. f->channels = channels;
  310. f->start_band = start_band;
  311. f->end_band = end_band;
  312. f->framebits = rc->rb.bytes * 8;
  313. f->size = av_log2(frame_size / CELT_SHORT_BLOCKSIZE);
  314. if (f->size > CELT_MAX_LOG_BLOCKS ||
  315. frame_size != CELT_SHORT_BLOCKSIZE * (1 << f->size)) {
  316. av_log(f->avctx, AV_LOG_ERROR, "Invalid CELT frame size: %d\n",
  317. frame_size);
  318. return AVERROR_INVALIDDATA;
  319. }
  320. if (!f->output_channels)
  321. f->output_channels = channels;
  322. for (i = 0; i < f->channels; i++) {
  323. memset(f->block[i].coeffs, 0, sizeof(f->block[i].coeffs));
  324. memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks));
  325. }
  326. consumed = opus_rc_tell(rc);
  327. /* obtain silence flag */
  328. if (consumed >= f->framebits)
  329. f->silence = 1;
  330. else if (consumed == 1)
  331. f->silence = ff_opus_rc_dec_log(rc, 15);
  332. if (f->silence) {
  333. consumed = f->framebits;
  334. rc->total_bits += f->framebits - opus_rc_tell(rc);
  335. }
  336. /* obtain post-filter options */
  337. consumed = parse_postfilter(f, rc, consumed);
  338. /* obtain transient flag */
  339. if (f->size != 0 && consumed+3 <= f->framebits)
  340. f->transient = ff_opus_rc_dec_log(rc, 3);
  341. f->blocks = f->transient ? 1 << f->size : 1;
  342. f->blocksize = frame_size / f->blocks;
  343. imdct = f->imdct[f->transient ? 0 : f->size];
  344. if (channels == 1) {
  345. for (i = 0; i < CELT_MAX_BANDS; i++)
  346. f->block[0].energy[i] = FFMAX(f->block[0].energy[i], f->block[1].energy[i]);
  347. }
  348. celt_decode_coarse_energy(f, rc);
  349. celt_decode_tf_changes (f, rc);
  350. ff_celt_bitalloc (f, rc, 0);
  351. celt_decode_fine_energy (f, rc);
  352. ff_celt_quant_bands (f, rc);
  353. if (f->anticollapse_needed)
  354. f->anticollapse = ff_opus_rc_get_raw(rc, 1);
  355. celt_decode_final_energy(f, rc);
  356. /* apply anti-collapse processing and denormalization to
  357. * each coded channel */
  358. for (i = 0; i < f->channels; i++) {
  359. CeltBlock *block = &f->block[i];
  360. if (f->anticollapse)
  361. process_anticollapse(f, block, f->block[i].coeffs);
  362. celt_denormalize(f, block, f->block[i].coeffs);
  363. }
  364. /* stereo -> mono downmix */
  365. if (f->output_channels < f->channels) {
  366. f->dsp->vector_fmac_scalar(f->block[0].coeffs, f->block[1].coeffs, 1.0, FFALIGN(frame_size, 16));
  367. downmix = 1;
  368. } else if (f->output_channels > f->channels)
  369. memcpy(f->block[1].coeffs, f->block[0].coeffs, frame_size * sizeof(float));
  370. if (f->silence) {
  371. for (i = 0; i < 2; i++) {
  372. CeltBlock *block = &f->block[i];
  373. for (j = 0; j < FF_ARRAY_ELEMS(block->energy); j++)
  374. block->energy[j] = CELT_ENERGY_SILENCE;
  375. }
  376. memset(f->block[0].coeffs, 0, sizeof(f->block[0].coeffs));
  377. memset(f->block[1].coeffs, 0, sizeof(f->block[1].coeffs));
  378. }
  379. /* transform and output for each output channel */
  380. for (i = 0; i < f->output_channels; i++) {
  381. CeltBlock *block = &f->block[i];
  382. float m = block->emph_coeff;
  383. /* iMDCT and overlap-add */
  384. for (j = 0; j < f->blocks; j++) {
  385. float *dst = block->buf + 1024 + j * f->blocksize;
  386. imdct->imdct_half(imdct, dst + CELT_OVERLAP / 2, f->block[i].coeffs + j,
  387. f->blocks);
  388. f->dsp->vector_fmul_window(dst, dst, dst + CELT_OVERLAP / 2,
  389. ff_celt_window, CELT_OVERLAP / 2);
  390. }
  391. if (downmix)
  392. f->dsp->vector_fmul_scalar(&block->buf[1024], &block->buf[1024], 0.5f, frame_size);
  393. /* postfilter */
  394. celt_postfilter(f, block);
  395. /* deemphasis and output scaling */
  396. for (j = 0; j < frame_size; j++) {
  397. const float tmp = block->buf[1024 - frame_size + j] + m;
  398. m = tmp * CELT_EMPH_COEFF;
  399. output[i][j] = tmp;
  400. }
  401. block->emph_coeff = m;
  402. }
  403. if (channels == 1)
  404. memcpy(f->block[1].energy, f->block[0].energy, sizeof(f->block[0].energy));
  405. for (i = 0; i < 2; i++ ) {
  406. CeltBlock *block = &f->block[i];
  407. if (!f->transient) {
  408. memcpy(block->prev_energy[1], block->prev_energy[0], sizeof(block->prev_energy[0]));
  409. memcpy(block->prev_energy[0], block->energy, sizeof(block->prev_energy[0]));
  410. } else {
  411. for (j = 0; j < CELT_MAX_BANDS; j++)
  412. block->prev_energy[0][j] = FFMIN(block->prev_energy[0][j], block->energy[j]);
  413. }
  414. for (j = 0; j < f->start_band; j++) {
  415. block->prev_energy[0][j] = CELT_ENERGY_SILENCE;
  416. block->energy[j] = 0.0;
  417. }
  418. for (j = f->end_band; j < CELT_MAX_BANDS; j++) {
  419. block->prev_energy[0][j] = CELT_ENERGY_SILENCE;
  420. block->energy[j] = 0.0;
  421. }
  422. }
  423. f->seed = rc->range;
  424. return 0;
  425. }
  426. void ff_celt_flush(CeltFrame *f)
  427. {
  428. int i, j;
  429. if (f->flushed)
  430. return;
  431. for (i = 0; i < 2; i++) {
  432. CeltBlock *block = &f->block[i];
  433. for (j = 0; j < CELT_MAX_BANDS; j++)
  434. block->prev_energy[0][j] = block->prev_energy[1][j] = CELT_ENERGY_SILENCE;
  435. memset(block->energy, 0, sizeof(block->energy));
  436. memset(block->buf, 0, sizeof(block->buf));
  437. memset(block->pf_gains, 0, sizeof(block->pf_gains));
  438. memset(block->pf_gains_old, 0, sizeof(block->pf_gains_old));
  439. memset(block->pf_gains_new, 0, sizeof(block->pf_gains_new));
  440. block->emph_coeff = 0.0;
  441. }
  442. f->seed = 0;
  443. f->flushed = 1;
  444. }
  445. void ff_celt_free(CeltFrame **f)
  446. {
  447. CeltFrame *frm = *f;
  448. int i;
  449. if (!frm)
  450. return;
  451. for (i = 0; i < FF_ARRAY_ELEMS(frm->imdct); i++)
  452. ff_mdct15_uninit(&frm->imdct[i]);
  453. ff_celt_pvq_uninit(&frm->pvq);
  454. av_freep(&frm->dsp);
  455. av_freep(f);
  456. }
  457. int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels,
  458. int apply_phase_inv)
  459. {
  460. CeltFrame *frm;
  461. int i, ret;
  462. if (output_channels != 1 && output_channels != 2) {
  463. av_log(avctx, AV_LOG_ERROR, "Invalid number of output channels: %d\n",
  464. output_channels);
  465. return AVERROR(EINVAL);
  466. }
  467. frm = av_mallocz(sizeof(*frm));
  468. if (!frm)
  469. return AVERROR(ENOMEM);
  470. frm->avctx = avctx;
  471. frm->output_channels = output_channels;
  472. frm->apply_phase_inv = apply_phase_inv;
  473. for (i = 0; i < FF_ARRAY_ELEMS(frm->imdct); i++)
  474. if ((ret = ff_mdct15_init(&frm->imdct[i], 1, i + 3, -1.0f/32768)) < 0)
  475. goto fail;
  476. if ((ret = ff_celt_pvq_init(&frm->pvq, 0)) < 0)
  477. goto fail;
  478. frm->dsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
  479. if (!frm->dsp) {
  480. ret = AVERROR(ENOMEM);
  481. goto fail;
  482. }
  483. ff_celt_flush(frm);
  484. *f = frm;
  485. return 0;
  486. fail:
  487. ff_celt_free(&frm);
  488. return ret;
  489. }