FFmpeg
opus_celt.c
Go to the documentation of this file.
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 /**
24  * @file
25  * Opus CELT decoder
26  */
27 
28 #include "opus_celt.h"
29 #include "opustab.h"
30 #include "opus_pvq.h"
31 
32 /* Use the 2D z-transform to apply prediction in both the time domain (alpha)
33  * and the frequency domain (beta) */
35 {
36  int i, j;
37  float prev[2] = { 0 };
38  float alpha = ff_celt_alpha_coef[f->size];
39  float beta = ff_celt_beta_coef[f->size];
40  const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0];
41 
42  /* intra frame */
43  if (opus_rc_tell(rc) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) {
44  alpha = 0.0f;
45  beta = 1.0f - (4915.0f/32768.0f);
46  model = ff_celt_coarse_energy_dist[f->size][1];
47  }
48 
49  for (i = 0; i < CELT_MAX_BANDS; i++) {
50  for (j = 0; j < f->channels; j++) {
51  CeltBlock *block = &f->block[j];
52  float value;
53  int available;
54 
55  if (i < f->start_band || i >= f->end_band) {
56  block->energy[i] = 0.0;
57  continue;
58  }
59 
60  available = f->framebits - opus_rc_tell(rc);
61  if (available >= 15) {
62  /* decode using a Laplace distribution */
63  int k = FFMIN(i, 20) << 1;
64  value = ff_opus_rc_dec_laplace(rc, model[k] << 7, model[k+1] << 6);
65  } else if (available >= 2) {
67  value = (x>>1) ^ -(x&1);
68  } else if (available >= 1) {
69  value = -(float)ff_opus_rc_dec_log(rc, 1);
70  } else value = -1;
71 
72  block->energy[i] = FFMAX(-9.0f, block->energy[i]) * alpha + prev[j] + value;
73  prev[j] += beta * value;
74  }
75  }
76 }
77 
79 {
80  int i;
81  for (i = f->start_band; i < f->end_band; i++) {
82  int j;
83  if (!f->fine_bits[i])
84  continue;
85 
86  for (j = 0; j < f->channels; j++) {
87  CeltBlock *block = &f->block[j];
88  int q2;
89  float offset;
90  q2 = ff_opus_rc_get_raw(rc, f->fine_bits[i]);
91  offset = (q2 + 0.5f) * (1 << (14 - f->fine_bits[i])) / 16384.0f - 0.5f;
92  block->energy[i] += offset;
93  }
94  }
95 }
96 
98 {
99  int priority, i, j;
100  int bits_left = f->framebits - opus_rc_tell(rc);
101 
102  for (priority = 0; priority < 2; priority++) {
103  for (i = f->start_band; i < f->end_band && bits_left >= f->channels; i++) {
104  if (f->fine_priority[i] != priority || f->fine_bits[i] >= CELT_MAX_FINE_BITS)
105  continue;
106 
107  for (j = 0; j < f->channels; j++) {
108  int q2;
109  float offset;
110  q2 = ff_opus_rc_get_raw(rc, 1);
111  offset = (q2 - 0.5f) * (1 << (14 - f->fine_bits[i] - 1)) / 16384.0f;
112  f->block[j].energy[i] += offset;
113  bits_left--;
114  }
115  }
116  }
117 }
118 
120 {
121  int i, diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit;
122  int consumed, bits = f->transient ? 2 : 4;
123 
124  consumed = opus_rc_tell(rc);
125  tf_select_bit = (f->size != 0 && consumed+bits+1 <= f->framebits);
126 
127  for (i = f->start_band; i < f->end_band; i++) {
128  if (consumed+bits+tf_select_bit <= f->framebits) {
129  diff ^= ff_opus_rc_dec_log(rc, bits);
130  consumed = opus_rc_tell(rc);
131  tf_changed |= diff;
132  }
133  f->tf_change[i] = diff;
134  bits = f->transient ? 4 : 5;
135  }
136 
137  if (tf_select_bit && ff_celt_tf_select[f->size][f->transient][0][tf_changed] !=
138  ff_celt_tf_select[f->size][f->transient][1][tf_changed])
139  tf_select = ff_opus_rc_dec_log(rc, 1);
140 
141  for (i = f->start_band; i < f->end_band; i++) {
142  f->tf_change[i] = ff_celt_tf_select[f->size][f->transient][tf_select][f->tf_change[i]];
143  }
144 }
145 
147 {
148  int i, j;
149 
150  for (i = f->start_band; i < f->end_band; i++) {
151  float *dst = data + (ff_celt_freq_bands[i] << f->size);
152  float log_norm = block->energy[i] + ff_celt_mean_energy[i];
153  float norm = exp2f(FFMIN(log_norm, 32.0f));
154 
155  for (j = 0; j < ff_celt_freq_range[i] << f->size; j++)
156  dst[j] *= norm;
157  }
158 }
159 
161 {
162  const int T0 = block->pf_period_old;
163  const int T1 = block->pf_period;
164 
165  float g00, g01, g02;
166  float g10, g11, g12;
167 
168  float x0, x1, x2, x3, x4;
169 
170  int i;
171 
172  if (block->pf_gains[0] == 0.0 &&
173  block->pf_gains_old[0] == 0.0)
174  return;
175 
176  g00 = block->pf_gains_old[0];
177  g01 = block->pf_gains_old[1];
178  g02 = block->pf_gains_old[2];
179  g10 = block->pf_gains[0];
180  g11 = block->pf_gains[1];
181  g12 = block->pf_gains[2];
182 
183  x1 = data[-T1 + 1];
184  x2 = data[-T1];
185  x3 = data[-T1 - 1];
186  x4 = data[-T1 - 2];
187 
188  for (i = 0; i < CELT_OVERLAP; i++) {
189  float w = ff_celt_window2[i];
190  x0 = data[i - T1 + 2];
191 
192  data[i] += (1.0 - w) * g00 * data[i - T0] +
193  (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) +
194  (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) +
195  w * g10 * x2 +
196  w * g11 * (x1 + x3) +
197  w * g12 * (x0 + x4);
198  x4 = x3;
199  x3 = x2;
200  x2 = x1;
201  x1 = x0;
202  }
203 }
204 
206 {
207  int len = f->blocksize * f->blocks;
208  const int filter_len = len - 2 * CELT_OVERLAP;
209 
211 
212  block->pf_period_old = block->pf_period;
213  memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains));
214 
215  block->pf_period = block->pf_period_new;
216  memcpy(block->pf_gains, block->pf_gains_new, sizeof(block->pf_gains));
217 
218  if (len > CELT_OVERLAP) {
220 
221  if (block->pf_gains[0] > FLT_EPSILON && filter_len > 0)
222  f->opusdsp.postfilter(block->buf + 1024 + 2 * CELT_OVERLAP,
223  block->pf_period, block->pf_gains,
224  filter_len);
225 
226  block->pf_period_old = block->pf_period;
227  memcpy(block->pf_gains_old, block->pf_gains, sizeof(block->pf_gains));
228  }
229 
230  memmove(block->buf, block->buf + len, (1024 + CELT_OVERLAP / 2) * sizeof(float));
231 }
232 
233 static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed)
234 {
235  int i;
236 
237  memset(f->block[0].pf_gains_new, 0, sizeof(f->block[0].pf_gains_new));
238  memset(f->block[1].pf_gains_new, 0, sizeof(f->block[1].pf_gains_new));
239 
240  if (f->start_band == 0 && consumed + 16 <= f->framebits) {
241  int has_postfilter = ff_opus_rc_dec_log(rc, 1);
242  if (has_postfilter) {
243  float gain;
244  int tapset, octave, period;
245 
246  octave = ff_opus_rc_dec_uint(rc, 6);
247  period = (16 << octave) + ff_opus_rc_get_raw(rc, 4 + octave) - 1;
248  gain = 0.09375f * (ff_opus_rc_get_raw(rc, 3) + 1);
249  tapset = (opus_rc_tell(rc) + 2 <= f->framebits) ?
251 
252  for (i = 0; i < 2; i++) {
253  CeltBlock *block = &f->block[i];
254 
255  block->pf_period_new = FFMAX(period, CELT_POSTFILTER_MINPERIOD);
256  block->pf_gains_new[0] = gain * ff_celt_postfilter_taps[tapset][0];
257  block->pf_gains_new[1] = gain * ff_celt_postfilter_taps[tapset][1];
258  block->pf_gains_new[2] = gain * ff_celt_postfilter_taps[tapset][2];
259  }
260  }
261 
262  consumed = opus_rc_tell(rc);
263  }
264 
265  return consumed;
266 }
267 
269 {
270  int i, j, k;
271 
272  for (i = f->start_band; i < f->end_band; i++) {
273  int renormalize = 0;
274  float *xptr;
275  float prev[2];
276  float Ediff, r;
277  float thresh, sqrt_1;
278  int depth;
279 
280  /* depth in 1/8 bits */
281  depth = (1 + f->pulses[i]) / (ff_celt_freq_range[i] << f->size);
282  thresh = exp2f(-1.0 - 0.125f * depth);
283  sqrt_1 = 1.0f / sqrtf(ff_celt_freq_range[i] << f->size);
284 
285  xptr = X + (ff_celt_freq_bands[i] << f->size);
286 
287  prev[0] = block->prev_energy[0][i];
288  prev[1] = block->prev_energy[1][i];
289  if (f->channels == 1) {
290  CeltBlock *block1 = &f->block[1];
291 
292  prev[0] = FFMAX(prev[0], block1->prev_energy[0][i]);
293  prev[1] = FFMAX(prev[1], block1->prev_energy[1][i]);
294  }
295  Ediff = block->energy[i] - FFMIN(prev[0], prev[1]);
296  Ediff = FFMAX(0, Ediff);
297 
298  /* r needs to be multiplied by 2 or 2*sqrt(2) depending on LM because
299  short blocks don't have the same energy as long */
300  r = exp2f(1 - Ediff);
301  if (f->size == 3)
302  r *= M_SQRT2;
303  r = FFMIN(thresh, r) * sqrt_1;
304  for (k = 0; k < 1 << f->size; k++) {
305  /* Detect collapse */
306  if (!(block->collapse_masks[i] & 1 << k)) {
307  /* Fill with noise */
308  for (j = 0; j < ff_celt_freq_range[i]; j++)
309  xptr[(j << f->size) + k] = (celt_rng(f) & 0x8000) ? r : -r;
310  renormalize = 1;
311  }
312  }
313 
314  /* We just added some energy, so we need to renormalize */
315  if (renormalize)
316  celt_renormalize_vector(xptr, ff_celt_freq_range[i] << f->size, 1.0f);
317  }
318 }
319 
321  float **output, int channels, int frame_size,
322  int start_band, int end_band)
323 {
324  int i, j, downmix = 0;
325  int consumed; // bits of entropy consumed thus far for this frame
326  MDCT15Context *imdct;
327 
328  if (channels != 1 && channels != 2) {
329  av_log(f->avctx, AV_LOG_ERROR, "Invalid number of coded channels: %d\n",
330  channels);
331  return AVERROR_INVALIDDATA;
332  }
333  if (start_band < 0 || start_band > end_band || end_band > CELT_MAX_BANDS) {
334  av_log(f->avctx, AV_LOG_ERROR, "Invalid start/end band: %d %d\n",
335  start_band, end_band);
336  return AVERROR_INVALIDDATA;
337  }
338 
339  f->silence = 0;
340  f->transient = 0;
341  f->anticollapse = 0;
342  f->flushed = 0;
343  f->channels = channels;
344  f->start_band = start_band;
345  f->end_band = end_band;
346  f->framebits = rc->rb.bytes * 8;
347 
349  if (f->size > CELT_MAX_LOG_BLOCKS ||
350  frame_size != CELT_SHORT_BLOCKSIZE * (1 << f->size)) {
351  av_log(f->avctx, AV_LOG_ERROR, "Invalid CELT frame size: %d\n",
352  frame_size);
353  return AVERROR_INVALIDDATA;
354  }
355 
356  if (!f->output_channels)
357  f->output_channels = channels;
358 
359  for (i = 0; i < f->channels; i++) {
360  memset(f->block[i].coeffs, 0, sizeof(f->block[i].coeffs));
361  memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks));
362  }
363 
364  consumed = opus_rc_tell(rc);
365 
366  /* obtain silence flag */
367  if (consumed >= f->framebits)
368  f->silence = 1;
369  else if (consumed == 1)
370  f->silence = ff_opus_rc_dec_log(rc, 15);
371 
372 
373  if (f->silence) {
374  consumed = f->framebits;
375  rc->total_bits += f->framebits - opus_rc_tell(rc);
376  }
377 
378  /* obtain post-filter options */
379  consumed = parse_postfilter(f, rc, consumed);
380 
381  /* obtain transient flag */
382  if (f->size != 0 && consumed+3 <= f->framebits)
383  f->transient = ff_opus_rc_dec_log(rc, 3);
384 
385  f->blocks = f->transient ? 1 << f->size : 1;
386  f->blocksize = frame_size / f->blocks;
387 
388  imdct = f->imdct[f->transient ? 0 : f->size];
389 
390  if (channels == 1) {
391  for (i = 0; i < CELT_MAX_BANDS; i++)
392  f->block[0].energy[i] = FFMAX(f->block[0].energy[i], f->block[1].energy[i]);
393  }
394 
397  ff_celt_bitalloc (f, rc, 0);
399  ff_celt_quant_bands (f, rc);
400 
401  if (f->anticollapse_needed)
402  f->anticollapse = ff_opus_rc_get_raw(rc, 1);
403 
405 
406  /* apply anti-collapse processing and denormalization to
407  * each coded channel */
408  for (i = 0; i < f->channels; i++) {
409  CeltBlock *block = &f->block[i];
410 
411  if (f->anticollapse)
412  process_anticollapse(f, block, f->block[i].coeffs);
413 
414  celt_denormalize(f, block, f->block[i].coeffs);
415  }
416 
417  /* stereo -> mono downmix */
418  if (f->output_channels < f->channels) {
419  f->dsp->vector_fmac_scalar(f->block[0].coeffs, f->block[1].coeffs, 1.0, FFALIGN(frame_size, 16));
420  downmix = 1;
421  } else if (f->output_channels > f->channels)
422  memcpy(f->block[1].coeffs, f->block[0].coeffs, frame_size * sizeof(float));
423 
424  if (f->silence) {
425  for (i = 0; i < 2; i++) {
426  CeltBlock *block = &f->block[i];
427 
428  for (j = 0; j < FF_ARRAY_ELEMS(block->energy); j++)
429  block->energy[j] = CELT_ENERGY_SILENCE;
430  }
431  memset(f->block[0].coeffs, 0, sizeof(f->block[0].coeffs));
432  memset(f->block[1].coeffs, 0, sizeof(f->block[1].coeffs));
433  }
434 
435  /* transform and output for each output channel */
436  for (i = 0; i < f->output_channels; i++) {
437  CeltBlock *block = &f->block[i];
438 
439  /* iMDCT and overlap-add */
440  for (j = 0; j < f->blocks; j++) {
441  float *dst = block->buf + 1024 + j * f->blocksize;
442 
443  imdct->imdct_half(imdct, dst + CELT_OVERLAP / 2, f->block[i].coeffs + j,
444  f->blocks);
445  f->dsp->vector_fmul_window(dst, dst, dst + CELT_OVERLAP / 2,
447  }
448 
449  if (downmix)
450  f->dsp->vector_fmul_scalar(&block->buf[1024], &block->buf[1024], 0.5f, frame_size);
451 
452  /* postfilter */
454 
455  /* deemphasis */
456  block->emph_coeff = f->opusdsp.deemphasis(output[i],
457  &block->buf[1024 - frame_size],
458  block->emph_coeff, frame_size);
459  }
460 
461  if (channels == 1)
462  memcpy(f->block[1].energy, f->block[0].energy, sizeof(f->block[0].energy));
463 
464  for (i = 0; i < 2; i++ ) {
465  CeltBlock *block = &f->block[i];
466 
467  if (!f->transient) {
468  memcpy(block->prev_energy[1], block->prev_energy[0], sizeof(block->prev_energy[0]));
469  memcpy(block->prev_energy[0], block->energy, sizeof(block->prev_energy[0]));
470  } else {
471  for (j = 0; j < CELT_MAX_BANDS; j++)
472  block->prev_energy[0][j] = FFMIN(block->prev_energy[0][j], block->energy[j]);
473  }
474 
475  for (j = 0; j < f->start_band; j++) {
476  block->prev_energy[0][j] = CELT_ENERGY_SILENCE;
477  block->energy[j] = 0.0;
478  }
479  for (j = f->end_band; j < CELT_MAX_BANDS; j++) {
480  block->prev_energy[0][j] = CELT_ENERGY_SILENCE;
481  block->energy[j] = 0.0;
482  }
483  }
484 
485  f->seed = rc->range;
486 
487  return 0;
488 }
489 
491 {
492  int i, j;
493 
494  if (f->flushed)
495  return;
496 
497  for (i = 0; i < 2; i++) {
498  CeltBlock *block = &f->block[i];
499 
500  for (j = 0; j < CELT_MAX_BANDS; j++)
501  block->prev_energy[0][j] = block->prev_energy[1][j] = CELT_ENERGY_SILENCE;
502 
503  memset(block->energy, 0, sizeof(block->energy));
504  memset(block->buf, 0, sizeof(block->buf));
505 
506  memset(block->pf_gains, 0, sizeof(block->pf_gains));
507  memset(block->pf_gains_old, 0, sizeof(block->pf_gains_old));
508  memset(block->pf_gains_new, 0, sizeof(block->pf_gains_new));
509 
510  /* libopus uses CELT_EMPH_COEFF on init, but 0 is better since there's
511  * a lesser discontinuity when seeking.
512  * The deemphasis functions differ from libopus in that they require
513  * an initial state divided by the coefficient. */
514  block->emph_coeff = 0.0f / CELT_EMPH_COEFF;
515  }
516  f->seed = 0;
517 
518  f->flushed = 1;
519 }
520 
522 {
523  CeltFrame *frm = *f;
524  int i;
525 
526  if (!frm)
527  return;
528 
529  for (i = 0; i < FF_ARRAY_ELEMS(frm->imdct); i++)
530  ff_mdct15_uninit(&frm->imdct[i]);
531 
532  ff_celt_pvq_uninit(&frm->pvq);
533 
534  av_freep(&frm->dsp);
535  av_freep(f);
536 }
537 
538 int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels,
539  int apply_phase_inv)
540 {
541  CeltFrame *frm;
542  int i, ret;
543 
544  if (output_channels != 1 && output_channels != 2) {
545  av_log(avctx, AV_LOG_ERROR, "Invalid number of output channels: %d\n",
546  output_channels);
547  return AVERROR(EINVAL);
548  }
549 
550  frm = av_mallocz(sizeof(*frm));
551  if (!frm)
552  return AVERROR(ENOMEM);
553 
554  frm->avctx = avctx;
555  frm->output_channels = output_channels;
556  frm->apply_phase_inv = apply_phase_inv;
557 
558  for (i = 0; i < FF_ARRAY_ELEMS(frm->imdct); i++)
559  if ((ret = ff_mdct15_init(&frm->imdct[i], 1, i + 3, -1.0f/32768)) < 0)
560  goto fail;
561 
562  if ((ret = ff_celt_pvq_init(&frm->pvq, 0)) < 0)
563  goto fail;
564 
566  if (!frm->dsp) {
567  ret = AVERROR(ENOMEM);
568  goto fail;
569  }
570 
571  ff_opus_dsp_init(&frm->opusdsp);
572  ff_celt_flush(frm);
573 
574  *f = frm;
575 
576  return 0;
577 fail:
578  ff_celt_free(&frm);
579  return ret;
580 }
ff_celt_postfilter_taps
const float ff_celt_postfilter_taps[3][3]
Definition: opustab.c:1098
celt_decode_coarse_energy
static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc)
Definition: opus_celt.c:34
celt_postfilter_apply_transition
static void celt_postfilter_apply_transition(CeltBlock *block, float *data)
Definition: opus_celt.c:160
CeltFrame::dsp
AVFloatDSPContext * dsp
Definition: opus_celt.h:97
r
const char * r
Definition: vf_curves.c:116
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_celt_freq_bands
const uint8_t ff_celt_freq_bands[]
Definition: opustab.c:768
ff_opus_rc_get_raw
uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count)
CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise.
Definition: opus_rc.c:140
ff_celt_flush
void ff_celt_flush(CeltFrame *f)
Definition: opus_celt.c:490
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
ff_celt_model_tapset
const uint16_t ff_celt_model_tapset[]
Definition: opustab.c:758
w
uint8_t w
Definition: llviddspenc.c:38
CeltFrame::avctx
AVCodecContext * avctx
Definition: opus_celt.h:95
data
const char data[16]
Definition: mxf.c:143
ff_mdct15_init
av_cold int ff_mdct15_init(MDCT15Context **ps, int inverse, int N, double scale)
Definition: mdct15.c:248
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_celt_pvq_init
int av_cold ff_celt_pvq_init(CeltPVQ **pvq, int encode)
Definition: opus_pvq.c:899
opus_rc_tell
static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame,...
Definition: opus_rc.h:61
ff_celt_coarse_energy_dist
const uint8_t ff_celt_coarse_energy_dist[4][2][42]
Definition: opustab.c:808
CeltBlock
Definition: opus_celt.h:66
parse_postfilter
static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed)
Definition: opus_celt.c:233
CeltFrame::output_channels
int output_channels
Definition: opus_celt.h:102
fail
#define fail()
Definition: checkasm.h:131
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:469
celt_postfilter
static void celt_postfilter(CeltFrame *f, CeltBlock *block)
Definition: opus_celt.c:205
ff_celt_init
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
Definition: opus_celt.c:538
celt_renormalize_vector
static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
Definition: opus_celt.h:150
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
CeltFrame::apply_phase_inv
int apply_phase_inv
Definition: opus_celt.h:103
float
float
Definition: af_crystalizer.c:122
ff_opus_rc_dec_uint
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
Definition: opus_rc.c:182
CELT_SHORT_BLOCKSIZE
#define CELT_SHORT_BLOCKSIZE
Definition: opus.h:42
frame_size
int frame_size
Definition: mxfenc.c:2201
CELT_MAX_FINE_BITS
#define CELT_MAX_FINE_BITS
Definition: opus_celt.h:41
bits
uint8_t bits
Definition: vp3data.h:141
exp2f
#define exp2f(x)
Definition: libm.h:293
channels
channels
Definition: aptx.h:32
MDCT15Context
Definition: mdct15.h:30
ff_celt_bitalloc
void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode)
Definition: opus.c:578
OpusRangeCoder::range
uint32_t range
Definition: opus_rc.h:43
ff_celt_pvq_uninit
void av_cold ff_celt_pvq_uninit(CeltPVQ **pvq)
Definition: opus_pvq.c:917
period
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without period
Definition: writing_filters.txt:89
celt_decode_tf_changes
static void celt_decode_tf_changes(CeltFrame *f, OpusRangeCoder *rc)
Definition: opus_celt.c:119
CELT_MAX_BANDS
#define CELT_MAX_BANDS
Definition: opus.h:46
RawBitsContext::bytes
uint32_t bytes
Definition: opus_rc.h:35
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
ff_celt_freq_range
const uint8_t ff_celt_freq_range[]
Definition: opustab.c:772
CELT_ENERGY_SILENCE
#define CELT_ENERGY_SILENCE
Definition: opus_celt.h:46
opustab.h
f
f
Definition: af_crystalizer.c:122
opus_pvq.h
celt_decode_fine_energy
static void celt_decode_fine_energy(CeltFrame *f, OpusRangeCoder *rc)
Definition: opus_celt.c:78
OpusRangeCoder
Definition: opus_rc.h:40
ff_celt_free
void ff_celt_free(CeltFrame **f)
Definition: opus_celt.c:521
celt_denormalize
static void celt_denormalize(CeltFrame *f, CeltBlock *block, float *data)
Definition: opus_celt.c:146
ff_celt_window2
const float ff_celt_window2[120]
Definition: opustab.c:1138
celt_rng
static av_always_inline uint32_t celt_rng(CeltFrame *f)
Definition: opus_celt.h:144
ff_celt_tf_select
const int8_t ff_celt_tf_select[4][2][2][2]
Definition: opustab.c:782
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_celt_beta_coef
const float ff_celt_beta_coef[]
Definition: opustab.c:804
ff_opus_rc_dec_cdf
uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf)
Definition: opus_rc.c:90
ff_opus_rc_dec_laplace
int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay)
Definition: opus_rc.c:275
CELT_MAX_LOG_BLOCKS
#define CELT_MAX_LOG_BLOCKS
Definition: opus.h:44
X
@ X
Definition: vf_addroi.c:26
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
CeltFrame::imdct
MDCT15Context * imdct[4]
Definition: opus_celt.h:96
available
if no frame is available
Definition: filter_design.txt:166
opus_celt.h
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
celt_decode_final_energy
static void celt_decode_final_energy(CeltFrame *f, OpusRangeCoder *rc)
Definition: opus_celt.c:97
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
ff_mdct15_uninit
av_cold void ff_mdct15_uninit(MDCT15Context **ps)
Definition: mdct15.c:44
len
int len
Definition: vorbis_enc_data.h:426
CELT_POSTFILTER_MINPERIOD
#define CELT_POSTFILTER_MINPERIOD
Definition: opus_celt.h:45
ret
ret
Definition: filter_design.txt:187
ff_celt_decode_frame
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band)
Definition: opus_celt.c:320
CELT_EMPH_COEFF
#define CELT_EMPH_COEFF
Definition: opusdsp.h:22
MDCT15Context::imdct_half
void(* imdct_half)(struct MDCT15Context *s, float *dst, const float *src, ptrdiff_t stride)
Definition: mdct15.h:54
AVCodecContext
main external API structure.
Definition: avcodec.h:389
ff_celt_model_energy_small
const uint16_t ff_celt_model_energy_small[]
Definition: opustab.c:766
CeltFrame::opusdsp
OpusDSP opusdsp
Definition: opus_celt.h:100
ff_celt_window
const float *const ff_celt_window
Definition: opustab.c:1135
ff_opus_dsp_init
av_cold void ff_opus_dsp_init(OpusDSP *ctx)
Definition: opusdsp.c:54
ff_celt_quant_bands
void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)
Definition: opus.c:469
ff_celt_alpha_coef
const float ff_celt_alpha_coef[]
Definition: opustab.c:800
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:278
process_anticollapse
static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X)
Definition: opus_celt.c:268
OpusRangeCoder::rb
RawBitsContext rb
Definition: opus_rc.h:42
M_SQRT2
#define M_SQRT2
Definition: mathematics.h:61
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:139
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ff_opus_rc_dec_log
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
Definition: opus_rc.c:114
ff_celt_mean_energy
const float ff_celt_mean_energy[]
Definition: opustab.c:792
CELT_OVERLAP
#define CELT_OVERLAP
Definition: opus.h:43
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
block1
static int16_t block1[64]
Definition: dct.c:118
OpusRangeCoder::total_bits
uint32_t total_bits
Definition: opus_rc.h:45
CeltFrame
Definition: opus_celt.h:93
CeltFrame::pvq
CeltPVQ * pvq
Definition: opus_celt.h:99