FFmpeg
evrcdec.c
Go to the documentation of this file.
1 /*
2  * Enhanced Variable Rate Codec, Service Option 3 decoder
3  * Copyright (c) 2013 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Enhanced Variable Rate Codec, Service Option 3 decoder
25  * @author Paul B Mahol
26  */
27 
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 #include "avcodec.h"
32 #include "internal.h"
33 #include "get_bits.h"
34 #include "evrcdata.h"
35 #include "acelp_vectors.h"
36 #include "lsp.h"
37 
38 #define MIN_LSP_SEP (0.05 / (2.0 * M_PI))
39 #define MIN_DELAY 20
40 #define MAX_DELAY 120
41 #define NB_SUBFRAMES 3
42 #define SUBFRAME_SIZE 54
43 #define FILTER_ORDER 10
44 #define ACB_SIZE 128
45 
46 typedef enum {
47  RATE_ERRS = -1,
54 
55 /**
56  * EVRC-A unpacked data frame
57  */
58 typedef struct EVRCAFrame {
59  uint8_t lpc_flag; ///< spectral change indicator
60  uint16_t lsp[4]; ///< index into LSP codebook
61  uint8_t pitch_delay; ///< pitch delay for entire frame
62  uint8_t delay_diff; ///< delay difference for entire frame
63  uint8_t acb_gain[3]; ///< adaptive codebook gain
64  uint16_t fcb_shape[3][4]; ///< fixed codebook shape
65  uint8_t fcb_gain[3]; ///< fixed codebook gain index
66  uint8_t energy_gain; ///< frame energy gain index
67  uint8_t tty; ///< tty baud rate bit
68 } EVRCAFrame;
69 
70 typedef struct EVRCContext {
71  AVClass *class;
72 
74 
79 
86  float pitch_delay;
88  float avg_acb_gain; ///< average adaptive codebook gain
89  float avg_fcb_gain; ///< average fixed codebook gain
94  float fade_scale;
95  float last;
96 
98  uint8_t prev_error_flag;
100 } EVRCContext;
101 
102 /**
103  * Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT
104  *
105  * @param e the context
106  *
107  * TIA/IS-127 Table 4.21-1
108  */
109 static void unpack_frame(EVRCContext *e)
110 {
111  EVRCAFrame *frame = &e->frame;
112  GetBitContext *gb = &e->gb;
113 
114  switch (e->bitrate) {
115  case RATE_FULL:
116  frame->lpc_flag = get_bits1(gb);
117  frame->lsp[0] = get_bits(gb, 6);
118  frame->lsp[1] = get_bits(gb, 6);
119  frame->lsp[2] = get_bits(gb, 9);
120  frame->lsp[3] = get_bits(gb, 7);
121  frame->pitch_delay = get_bits(gb, 7);
122  frame->delay_diff = get_bits(gb, 5);
123  frame->acb_gain[0] = get_bits(gb, 3);
124  frame->fcb_shape[0][0] = get_bits(gb, 8);
125  frame->fcb_shape[0][1] = get_bits(gb, 8);
126  frame->fcb_shape[0][2] = get_bits(gb, 8);
127  frame->fcb_shape[0][3] = get_bits(gb, 11);
128  frame->fcb_gain[0] = get_bits(gb, 5);
129  frame->acb_gain[1] = get_bits(gb, 3);
130  frame->fcb_shape[1][0] = get_bits(gb, 8);
131  frame->fcb_shape[1][1] = get_bits(gb, 8);
132  frame->fcb_shape[1][2] = get_bits(gb, 8);
133  frame->fcb_shape[1][3] = get_bits(gb, 11);
134  frame->fcb_gain [1] = get_bits(gb, 5);
135  frame->acb_gain [2] = get_bits(gb, 3);
136  frame->fcb_shape[2][0] = get_bits(gb, 8);
137  frame->fcb_shape[2][1] = get_bits(gb, 8);
138  frame->fcb_shape[2][2] = get_bits(gb, 8);
139  frame->fcb_shape[2][3] = get_bits(gb, 11);
140  frame->fcb_gain [2] = get_bits(gb, 5);
141  frame->tty = get_bits1(gb);
142  break;
143  case RATE_HALF:
144  frame->lsp [0] = get_bits(gb, 7);
145  frame->lsp [1] = get_bits(gb, 7);
146  frame->lsp [2] = get_bits(gb, 8);
147  frame->pitch_delay = get_bits(gb, 7);
148  frame->acb_gain [0] = get_bits(gb, 3);
149  frame->fcb_shape[0][0] = get_bits(gb, 10);
150  frame->fcb_gain [0] = get_bits(gb, 4);
151  frame->acb_gain [1] = get_bits(gb, 3);
152  frame->fcb_shape[1][0] = get_bits(gb, 10);
153  frame->fcb_gain [1] = get_bits(gb, 4);
154  frame->acb_gain [2] = get_bits(gb, 3);
155  frame->fcb_shape[2][0] = get_bits(gb, 10);
156  frame->fcb_gain [2] = get_bits(gb, 4);
157  break;
158  case RATE_QUANT:
159  frame->lsp [0] = get_bits(gb, 4);
160  frame->lsp [1] = get_bits(gb, 4);
161  frame->energy_gain = get_bits(gb, 8);
162  break;
163  }
164 }
165 
166 static evrc_packet_rate buf_size2bitrate(const int buf_size)
167 {
168  switch (buf_size) {
169  case 23: return RATE_FULL;
170  case 11: return RATE_HALF;
171  case 6: return RATE_QUARTER;
172  case 3: return RATE_QUANT;
173  case 1: return SILENCE;
174  }
175 
176  return RATE_ERRS;
177 }
178 
179 /**
180  * Determine the bitrate from the frame size and/or the first byte of the frame.
181  *
182  * @param avctx the AV codec context
183  * @param buf_size length of the buffer
184  * @param buf the bufffer
185  *
186  * @return the bitrate on success,
187  * RATE_ERRS if the bitrate cannot be satisfactorily determined
188  */
190  int *buf_size,
191  const uint8_t **buf)
192 {
194 
195  if ((bitrate = buf_size2bitrate(*buf_size)) >= 0) {
196  if (bitrate > **buf) {
197  EVRCContext *e = avctx->priv_data;
198  if (!e->warned_buf_mismatch_bitrate) {
199  av_log(avctx, AV_LOG_WARNING,
200  "Claimed bitrate and buffer size mismatch.\n");
202  }
203  bitrate = **buf;
204  } else if (bitrate < **buf) {
205  av_log(avctx, AV_LOG_ERROR,
206  "Buffer is too small for the claimed bitrate.\n");
207  return RATE_ERRS;
208  }
209  (*buf)++;
210  *buf_size -= 1;
211  } else if ((bitrate = buf_size2bitrate(*buf_size + 1)) >= 0) {
212  av_log(avctx, AV_LOG_DEBUG,
213  "Bitrate byte is missing, guessing the bitrate from packet size.\n");
214  } else
215  return RATE_ERRS;
216 
217  return bitrate;
218 }
219 
221  const char *message)
222 {
223  av_log(avctx, AV_LOG_WARNING, "Frame #%d, %s\n",
224  avctx->frame_number, message);
225 }
226 
227 /**
228  * Initialize the speech codec according to the specification.
229  *
230  * TIA/IS-127 5.2
231  */
233 {
234  EVRCContext *e = avctx->priv_data;
235  int i, n, idx = 0;
236  float denom = 2.0 / (2.0 * 8.0 + 1.0);
237 
238  avctx->channels = 1;
240  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
241 
242  for (i = 0; i < FILTER_ORDER; i++) {
243  e->prev_lspf[i] = (i + 1) * 0.048;
244  e->synthesis[i] = 0.0;
245  }
246 
247  for (i = 0; i < ACB_SIZE; i++)
248  e->pitch[i] = e->pitch_back[i] = 0.0;
249 
251  e->prev_pitch_delay = 40.0;
252  e->fade_scale = 1.0;
253  e->prev_error_flag = 0;
254  e->avg_acb_gain = e->avg_fcb_gain = 0.0;
255 
256  for (i = 0; i < 8; i++) {
257  float tt = ((float)i - 8.0 / 2.0) / 8.0;
258 
259  for (n = -8; n <= 8; n++, idx++) {
260  float arg1 = M_PI * 0.9 * (tt - n);
261  float arg2 = M_PI * (tt - n);
262 
263  e->interpolation_coeffs[idx] = 0.9;
264  if (arg1)
265  e->interpolation_coeffs[idx] *= (0.54 + 0.46 * cos(arg2 * denom)) *
266  sin(arg1) / arg1;
267  }
268  }
269 
270  return 0;
271 }
272 
273 /**
274  * Decode the 10 vector quantized line spectral pair frequencies from the LSP
275  * transmission codes of any bitrate and check for badly received packets.
276  *
277  * @param e the context
278  *
279  * @return 0 on success, -1 if the packet is badly received
280  *
281  * TIA/IS-127 5.2.1, 5.7.1
282  */
283 static int decode_lspf(EVRCContext *e)
284 {
285  const float * const *codebooks = evrc_lspq_codebooks[e->bitrate];
286  int i, j, k = 0;
287 
288  for (i = 0; i < evrc_lspq_nb_codebooks[e->bitrate]; i++) {
289  int row_size = evrc_lspq_codebooks_row_sizes[e->bitrate][i];
290  const float *codebook = codebooks[i];
291 
292  for (j = 0; j < row_size; j++)
293  e->lspf[k++] = codebook[e->frame.lsp[i] * row_size + j];
294  }
295 
296  // check for monotonic LSPs
297  for (i = 1; i < FILTER_ORDER; i++)
298  if (e->lspf[i] <= e->lspf[i - 1])
299  return -1;
300 
301  // check for minimum separation of LSPs at the splits
302  for (i = 0, k = 0; i < evrc_lspq_nb_codebooks[e->bitrate] - 1; i++) {
304  if (e->lspf[k] - e->lspf[k - 1] <= MIN_LSP_SEP)
305  return -1;
306  }
307 
308  return 0;
309 }
310 
311 /*
312  * Interpolation of LSP parameters.
313  *
314  * TIA/IS-127 5.2.3.1, 5.7.3.2
315  */
316 static void interpolate_lsp(float *ilsp, const float *lsp,
317  const float *prev, int index)
318 {
319  static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 };
320  ff_weighted_vector_sumf(ilsp, prev, lsp,
321  1.0 - lsp_interpolation_factors[index],
322  lsp_interpolation_factors[index], FILTER_ORDER);
323 }
324 
325 /*
326  * Reconstruction of the delay contour.
327  *
328  * TIA/IS-127 5.2.2.3.2
329  */
330 static void interpolate_delay(float *dst, float current, float prev, int index)
331 {
332  static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 };
333  dst[0] = (1.0 - d_interpolation_factors[index ]) * prev
334  + d_interpolation_factors[index ] * current;
335  dst[1] = (1.0 - d_interpolation_factors[index + 1]) * prev
336  + d_interpolation_factors[index + 1] * current;
337  dst[2] = (1.0 - d_interpolation_factors[index + 2]) * prev
338  + d_interpolation_factors[index + 2] * current;
339 }
340 
341 /*
342  * Convert the quantized, interpolated line spectral frequencies,
343  * to prediction coefficients.
344  *
345  * TIA/IS-127 5.2.3.2, 4.7.2.2
346  */
347 static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
348 {
349  double lsp[FILTER_ORDER];
350  float a[FILTER_ORDER / 2 + 1], b[FILTER_ORDER / 2 + 1];
351  float a1[FILTER_ORDER / 2] = { 0 };
352  float a2[FILTER_ORDER / 2] = { 0 };
353  float b1[FILTER_ORDER / 2] = { 0 };
354  float b2[FILTER_ORDER / 2] = { 0 };
355  int i, k;
356 
357  ff_acelp_lsf2lspd(lsp, ilspf, FILTER_ORDER);
358 
359  for (k = 0; k <= FILTER_ORDER; k++) {
360  a[0] = k < 2 ? 0.25 : 0;
361  b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
362 
363  for (i = 0; i < FILTER_ORDER / 2; i++) {
364  a[i + 1] = a[i] - 2 * lsp[i * 2 ] * a1[i] + a2[i];
365  b[i + 1] = b[i] - 2 * lsp[i * 2 + 1] * b1[i] + b2[i];
366  a2[i] = a1[i];
367  a1[i] = a[i];
368  b2[i] = b1[i];
369  b1[i] = b[i];
370  }
371 
372  if (k)
373  ilpc[k - 1] = 2.0 * (a[FILTER_ORDER / 2] + b[FILTER_ORDER / 2]);
374  }
375 }
376 
377 static void bl_intrp(EVRCContext *e, float *ex, float delay)
378 {
379  float *f;
380  int offset, i, coef_idx;
381  int16_t t;
382 
383  offset = lrintf(delay);
384 
385  t = (offset - delay + 0.5) * 8.0 + 0.5;
386  if (t == 8) {
387  t = 0;
388  offset--;
389  }
390 
391  f = ex - offset - 8;
392 
393  coef_idx = t * (2 * 8 + 1);
394 
395  ex[0] = 0.0;
396  for (i = 0; i < 2 * 8 + 1; i++)
397  ex[0] += e->interpolation_coeffs[coef_idx + i] * f[i];
398 }
399 
400 /*
401  * Adaptive codebook excitation.
402  *
403  * TIA/IS-127 5.2.2.3.3, 4.12.5.2
404  */
405 static void acb_excitation(EVRCContext *e, float *excitation, float gain,
406  const float delay[3], int length)
407 {
408  float denom, locdelay, dpr, invl;
409  int i;
410 
411  invl = 1.0 / ((float) length);
412  dpr = length;
413 
414  /* first at-most extra samples */
415  denom = (delay[1] - delay[0]) * invl;
416  for (i = 0; i < dpr; i++) {
417  locdelay = delay[0] + i * denom;
418  bl_intrp(e, excitation + i, locdelay);
419  }
420 
421  denom = (delay[2] - delay[1]) * invl;
422  /* interpolation */
423  for (i = dpr; i < dpr + 10; i++) {
424  locdelay = delay[1] + (i - dpr) * denom;
425  bl_intrp(e, excitation + i, locdelay);
426  }
427 
428  for (i = 0; i < length; i++)
429  excitation[i] *= gain;
430 }
431 
432 static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
433 {
434  int i, pos1, pos2, offset;
435 
436  offset = (fixed_index[3] >> 9) & 3;
437 
438  for (i = 0; i < 3; i++) {
439  pos1 = ((fixed_index[i] & 0x7f) / 11) * 5 + ((i + offset) % 5);
440  pos2 = ((fixed_index[i] & 0x7f) % 11) * 5 + ((i + offset) % 5);
441 
442  cod[pos1] = (fixed_index[i] & 0x80) ? -1.0 : 1.0;
443 
444  if (pos2 < pos1)
445  cod[pos2] = -cod[pos1];
446  else
447  cod[pos2] += cod[pos1];
448  }
449 
450  pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 + offset) % 5);
451  pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 + offset) % 5);
452 
453  cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0;
454  cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0;
455 }
456 
457 static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
458 {
459  float sign;
460  int pos;
461 
462  sign = (fixed_index & 0x200) ? -1.0 : 1.0;
463 
464  pos = ((fixed_index & 0x7) * 7) + 4;
465  cod[pos] += sign;
466  pos = (((fixed_index >> 3) & 0x7) * 7) + 2;
467  cod[pos] -= sign;
468  pos = (((fixed_index >> 6) & 0x7) * 7);
469  cod[pos] += sign;
470 }
471 
472 /*
473  * Reconstruction of ACELP fixed codebook excitation for full and half rate.
474  *
475  * TIA/IS-127 5.2.3.7
476  */
477 static void fcb_excitation(EVRCContext *e, const uint16_t *codebook,
478  float *excitation, float pitch_gain,
479  int pitch_lag, int subframe_size)
480 {
481  int i;
482 
483  if (e->bitrate == RATE_FULL)
484  decode_8_pulses_35bits(codebook, excitation);
485  else
486  decode_3_pulses_10bits(*codebook, excitation);
487 
488  pitch_gain = av_clipf(pitch_gain, 0.2, 0.9);
489 
490  for (i = pitch_lag; i < subframe_size; i++)
491  excitation[i] += pitch_gain * excitation[i - pitch_lag];
492 }
493 
494 /**
495  * Synthesis of the decoder output signal.
496  *
497  * param[in] in input signal
498  * param[in] filter_coeffs LPC coefficients
499  * param[in/out] memory synthesis filter memory
500  * param buffer_length amount of data to process
501  * param[out] samples output samples
502  *
503  * TIA/IS-127 5.2.3.15, 5.7.3.4
504  */
505 static void synthesis_filter(const float *in, const float *filter_coeffs,
506  float *memory, int buffer_length, float *samples)
507 {
508  int i, j;
509 
510  for (i = 0; i < buffer_length; i++) {
511  samples[i] = in[i];
512  for (j = FILTER_ORDER - 1; j > 0; j--) {
513  samples[i] -= filter_coeffs[j] * memory[j];
514  memory[j] = memory[j - 1];
515  }
516  samples[i] -= filter_coeffs[0] * memory[0];
517  memory[0] = samples[i];
518  }
519 }
520 
521 static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
522 {
523  double fac = gamma;
524  int i;
525 
526  for (i = 0; i < FILTER_ORDER; i++) {
527  coeff[i] = inbuf[i] * fac;
528  fac *= gamma;
529  }
530 }
531 
532 static void residual_filter(float *output, const float *input,
533  const float *coef, float *memory, int length)
534 {
535  float sum;
536  int i, j;
537 
538  for (i = 0; i < length; i++) {
539  sum = input[i];
540 
541  for (j = FILTER_ORDER - 1; j > 0; j--) {
542  sum += coef[j] * memory[j];
543  memory[j] = memory[j - 1];
544  }
545  sum += coef[0] * memory[0];
546  memory[0] = input[i];
547  output[i] = sum;
548  }
549 }
550 
551 /*
552  * TIA/IS-127 Table 5.9.1-1.
553  */
554 static const struct PfCoeff {
555  float tilt;
556  float ltgain;
557  float p1;
558  float p2;
559 } postfilter_coeffs[5] = {
560  { 0.0 , 0.0 , 0.0 , 0.0 },
561  { 0.0 , 0.0 , 0.57, 0.57 },
562  { 0.0 , 0.0 , 0.0 , 0.0 },
563  { 0.35, 0.50, 0.50, 0.75 },
564  { 0.20, 0.50, 0.57, 0.75 },
565 };
566 
567 /*
568  * Adaptive postfilter.
569  *
570  * TIA/IS-127 5.9
571  */
572 static void postfilter(EVRCContext *e, float *in, const float *coeff,
573  float *out, int idx, const struct PfCoeff *pfc,
574  int length)
575 {
576  float wcoef1[FILTER_ORDER], wcoef2[FILTER_ORDER],
577  scratch[SUBFRAME_SIZE], temp[SUBFRAME_SIZE],
578  mem[SUBFRAME_SIZE];
579  float sum1 = 0.0, sum2 = 0.0, gamma, gain;
580  float tilt = pfc->tilt;
581  int i, n, best;
582 
583  bandwidth_expansion(wcoef1, coeff, pfc->p1);
584  bandwidth_expansion(wcoef2, coeff, pfc->p2);
585 
586  /* Tilt compensation filter, TIA/IS-127 5.9.1 */
587  for (i = 0; i < length - 1; i++)
588  sum2 += in[i] * in[i + 1];
589  if (sum2 < 0.0)
590  tilt = 0.0;
591 
592  for (i = 0; i < length; i++) {
593  scratch[i] = in[i] - tilt * e->last;
594  e->last = in[i];
595  }
596 
597  /* Short term residual filter, TIA/IS-127 5.9.2 */
598  residual_filter(&e->postfilter_residual[ACB_SIZE], scratch, wcoef1, e->postfilter_fir, length);
599 
600  /* Long term postfilter */
601  best = idx;
602  for (i = FFMIN(MIN_DELAY, idx - 3); i <= FFMAX(MAX_DELAY, idx + 3); i++) {
603  for (n = ACB_SIZE, sum2 = 0; n < ACB_SIZE + length; n++)
604  sum2 += e->postfilter_residual[n] * e->postfilter_residual[n - i];
605  if (sum2 > sum1) {
606  sum1 = sum2;
607  best = i;
608  }
609  }
610 
611  for (i = ACB_SIZE, sum1 = 0; i < ACB_SIZE + length; i++)
612  sum1 += e->postfilter_residual[i - best] * e->postfilter_residual[i - best];
613  for (i = ACB_SIZE, sum2 = 0; i < ACB_SIZE + length; i++)
614  sum2 += e->postfilter_residual[i] * e->postfilter_residual[i - best];
615 
616  if (sum2 * sum1 == 0 || e->bitrate == RATE_QUANT) {
617  memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));
618  } else {
619  gamma = sum2 / sum1;
620  if (gamma < 0.5)
621  memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));
622  else {
623  gamma = FFMIN(gamma, 1.0);
624 
625  for (i = 0; i < length; i++) {
626  temp[i] = e->postfilter_residual[ACB_SIZE + i] + gamma *
627  pfc->ltgain * e->postfilter_residual[ACB_SIZE + i - best];
628  }
629  }
630  }
631 
632  memcpy(scratch, temp, length * sizeof(float));
633  memcpy(mem, e->postfilter_iir, FILTER_ORDER * sizeof(float));
634  synthesis_filter(scratch, wcoef2, mem, length, scratch);
635 
636  /* Gain computation, TIA/IS-127 5.9.4-2 */
637  for (i = 0, sum1 = 0, sum2 = 0; i < length; i++) {
638  sum1 += in[i] * in[i];
639  sum2 += scratch[i] * scratch[i];
640  }
641  gain = sum2 ? sqrt(sum1 / sum2) : 1.0;
642 
643  for (i = 0; i < length; i++)
644  temp[i] *= gain;
645 
646  /* Short term postfilter */
647  synthesis_filter(temp, wcoef2, e->postfilter_iir, length, out);
648 
649  memmove(e->postfilter_residual,
650  e->postfilter_residual + length, ACB_SIZE * sizeof(float));
651 }
652 
653 static void frame_erasure(EVRCContext *e, float *samples)
654 {
655  float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES],
656  tmp[SUBFRAME_SIZE + 6], f;
657  int i, j;
658 
659  for (i = 0; i < FILTER_ORDER; i++) {
660  if (e->bitrate != RATE_QUANT)
661  e->lspf[i] = e->prev_lspf[i] * 0.875 + 0.125 * (i + 1) * 0.048;
662  else
663  e->lspf[i] = e->prev_lspf[i];
664  }
665 
666  if (e->prev_error_flag)
667  e->avg_acb_gain *= 0.75;
668  if (e->bitrate == RATE_FULL)
669  memcpy(e->pitch_back, e->pitch, ACB_SIZE * sizeof(float));
670  if (e->last_valid_bitrate == RATE_QUANT)
671  e->bitrate = RATE_QUANT;
672  else
673  e->bitrate = RATE_FULL;
674 
675  if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) {
677  } else {
678  float sum = 0;
679 
680  idelay[0] = idelay[1] = idelay[2] = MIN_DELAY;
681 
682  for (i = 0; i < NB_SUBFRAMES; i++)
684  sum /= (float) NB_SUBFRAMES;
685  sum = pow(10, sum);
686  for (i = 0; i < NB_SUBFRAMES; i++)
687  e->energy_vector[i] = sum;
688  }
689 
690  if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15)
692 
693  for (i = 0; i < NB_SUBFRAMES; i++) {
694  int subframe_size = subframe_sizes[i];
695  int pitch_lag;
696 
697  interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i);
698 
699  if (e->bitrate != RATE_QUANT) {
700  if (e->avg_acb_gain < 0.3) {
701  idelay[0] = estimation_delay[i];
702  idelay[1] = estimation_delay[i + 1];
703  idelay[2] = estimation_delay[i + 2];
704  } else {
706  }
707  }
708 
709  pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0);
710  decode_predictor_coeffs(ilspf, ilpc);
711 
712  if (e->bitrate != RATE_QUANT) {
713  acb_excitation(e, e->pitch + ACB_SIZE,
714  e->avg_acb_gain, idelay, subframe_size);
715  for (j = 0; j < subframe_size; j++)
716  e->pitch[ACB_SIZE + j] *= e->fade_scale;
717  e->fade_scale = FFMAX(e->fade_scale - 0.05, 0.0);
718  } else {
719  for (j = 0; j < subframe_size; j++)
720  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
721  }
722 
723  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
724 
725  if (e->bitrate != RATE_QUANT && e->avg_acb_gain < 0.4) {
726  f = 0.1 * e->avg_fcb_gain;
727  for (j = 0; j < subframe_size; j++)
728  e->pitch[ACB_SIZE + j] += f;
729  } else if (e->bitrate == RATE_QUANT) {
730  for (j = 0; j < subframe_size; j++)
731  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
732  }
733 
734  synthesis_filter(e->pitch + ACB_SIZE, ilpc,
735  e->synthesis, subframe_size, tmp);
736  postfilter(e, tmp, ilpc, samples, pitch_lag,
737  &postfilter_coeffs[e->bitrate], subframe_size);
738 
739  samples += subframe_size;
740  }
741 }
742 
743 static int evrc_decode_frame(AVCodecContext *avctx, void *data,
744  int *got_frame_ptr, AVPacket *avpkt)
745 {
746  const uint8_t *buf = avpkt->data;
747  AVFrame *frame = data;
748  EVRCContext *e = avctx->priv_data;
749  int buf_size = avpkt->size;
750  float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES];
751  float *samples;
752  int i, j, ret, error_flag = 0;
753 
754  frame->nb_samples = 160;
755  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
756  return ret;
757  samples = (float *)frame->data[0];
758 
759  if ((e->bitrate = determine_bitrate(avctx, &buf_size, &buf)) == RATE_ERRS) {
760  warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
761  goto erasure;
762  }
763  if (e->bitrate <= SILENCE || e->bitrate == RATE_QUARTER)
764  goto erasure;
766  && !e->prev_error_flag)
767  goto erasure;
768 
769  if ((ret = init_get_bits8(&e->gb, buf, buf_size)) < 0)
770  return ret;
771  memset(&e->frame, 0, sizeof(EVRCAFrame));
772 
773  unpack_frame(e);
774 
775  if (e->bitrate != RATE_QUANT) {
776  uint8_t *p = (uint8_t *) &e->frame;
777  for (i = 0; i < sizeof(EVRCAFrame); i++) {
778  if (p[i])
779  break;
780  }
781  if (i == sizeof(EVRCAFrame))
782  goto erasure;
783  } else if (e->frame.lsp[0] == 0xf &&
784  e->frame.lsp[1] == 0xf &&
785  e->frame.energy_gain == 0xff) {
786  goto erasure;
787  }
788 
789  if (decode_lspf(e) < 0)
790  goto erasure;
791 
792  if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) {
793  /* Pitch delay parameter checking as per TIA/IS-127 5.1.5.1 */
795  goto erasure;
796 
798 
799  /* Delay diff parameter checking as per TIA/IS-127 5.1.5.2 */
800  if (e->frame.delay_diff) {
801  int p = e->pitch_delay - e->frame.delay_diff + 16;
802  if (p < MIN_DELAY || p > MAX_DELAY)
803  goto erasure;
804  }
805 
806  /* Delay contour reconstruction as per TIA/IS-127 5.2.2.2 */
807  if (e->frame.delay_diff &&
808  e->bitrate == RATE_FULL && e->prev_error_flag) {
809  float delay;
810 
811  memcpy(e->pitch, e->pitch_back, ACB_SIZE * sizeof(float));
812 
813  delay = e->prev_pitch_delay;
814  e->prev_pitch_delay = delay - e->frame.delay_diff + 16.0;
815 
816  if (fabs(e->pitch_delay - delay) > 15)
817  delay = e->pitch_delay;
818 
819  for (i = 0; i < NB_SUBFRAMES; i++) {
820  int subframe_size = subframe_sizes[i];
821 
822  interpolate_delay(idelay, delay, e->prev_pitch_delay, i);
823  acb_excitation(e, e->pitch + ACB_SIZE, e->avg_acb_gain, idelay, subframe_size);
824  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
825  }
826  }
827 
828  /* Smoothing of the decoded delay as per TIA/IS-127 5.2.2.5 */
829  if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15)
831 
832  e->avg_acb_gain = e->avg_fcb_gain = 0.0;
833  } else {
834  idelay[0] = idelay[1] = idelay[2] = MIN_DELAY;
835 
836  /* Decode frame energy vectors as per TIA/IS-127 5.7.2 */
837  for (i = 0; i < NB_SUBFRAMES; i++)
838  e->energy_vector[i] = pow(10, evrc_energy_quant[e->frame.energy_gain][i]);
840  }
841 
842  for (i = 0; i < NB_SUBFRAMES; i++) {
843  float tmp[SUBFRAME_SIZE + 6] = { 0 };
844  int subframe_size = subframe_sizes[i];
845  int pitch_lag;
846 
847  interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i);
848 
849  if (e->bitrate != RATE_QUANT)
851 
852  pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0);
853  decode_predictor_coeffs(ilspf, ilpc);
854 
855  /* Bandwidth expansion as per TIA/IS-127 5.2.3.3 */
856  if (e->frame.lpc_flag && e->prev_error_flag)
857  bandwidth_expansion(ilpc, ilpc, 0.75);
858 
859  if (e->bitrate != RATE_QUANT) {
860  float acb_sum, f;
861 
862  f = exp((e->bitrate == RATE_HALF ? 0.5 : 0.25)
863  * (e->frame.fcb_gain[i] + 1));
864  acb_sum = pitch_gain_vq[e->frame.acb_gain[i]];
865  e->avg_acb_gain += acb_sum / NB_SUBFRAMES;
866  e->avg_fcb_gain += f / NB_SUBFRAMES;
867 
868  acb_excitation(e, e->pitch + ACB_SIZE,
869  acb_sum, idelay, subframe_size);
871  acb_sum, pitch_lag, subframe_size);
872 
873  /* Total excitation generation as per TIA/IS-127 5.2.3.9 */
874  for (j = 0; j < subframe_size; j++)
875  e->pitch[ACB_SIZE + j] += f * tmp[j];
876  e->fade_scale = FFMIN(e->fade_scale + 0.2, 1.0);
877  } else {
878  for (j = 0; j < subframe_size; j++)
879  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
880  }
881 
882  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
883 
884  synthesis_filter(e->pitch + ACB_SIZE, ilpc,
885  e->synthesis, subframe_size,
886  e->postfilter ? tmp : samples);
887  if (e->postfilter)
888  postfilter(e, tmp, ilpc, samples, pitch_lag,
889  &postfilter_coeffs[e->bitrate], subframe_size);
890 
891  samples += subframe_size;
892  }
893 
894  if (error_flag) {
895 erasure:
896  error_flag = 1;
897  av_log(avctx, AV_LOG_WARNING, "frame erasure\n");
899  }
900 
901  memcpy(e->prev_lspf, e->lspf, sizeof(e->prev_lspf));
902  e->prev_error_flag = error_flag;
903  e->last_valid_bitrate = e->bitrate;
904 
905  if (e->bitrate != RATE_QUANT)
907 
908  samples = (float *)frame->data[0];
909  for (i = 0; i < 160; i++)
910  samples[i] /= 32768;
911 
912  *got_frame_ptr = 1;
913 
914  return avpkt->size;
915 }
916 
917 #define OFFSET(x) offsetof(EVRCContext, x)
918 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
919 
920 static const AVOption options[] = {
921  { "postfilter", "enable postfilter", OFFSET(postfilter), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AD },
922  { NULL }
923 };
924 
925 static const AVClass evrcdec_class = {
926  .class_name = "evrc",
927  .item_name = av_default_item_name,
928  .option = options,
929  .version = LIBAVUTIL_VERSION_INT,
930 };
931 
933  .name = "evrc",
934  .long_name = NULL_IF_CONFIG_SMALL("EVRC (Enhanced Variable Rate Codec)"),
935  .type = AVMEDIA_TYPE_AUDIO,
936  .id = AV_CODEC_ID_EVRC,
937  .init = evrc_decode_init,
938  .decode = evrc_decode_frame,
940  .priv_data_size = sizeof(EVRCContext),
941  .priv_class = &evrcdec_class,
942  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
943 };
AVCodec
AVCodec.
Definition: codec.h:202
EVRCAFrame::lsp
uint16_t lsp[4]
index into LSP codebook
Definition: evrcdec.c:60
PfCoeff::p2
float p2
Definition: evrcdec.c:558
determine_bitrate
static evrc_packet_rate determine_bitrate(AVCodecContext *avctx, int *buf_size, const uint8_t **buf)
Determine the bitrate from the frame size and/or the first byte of the frame.
Definition: evrcdec.c:189
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
FILTER_ORDER
#define FILTER_ORDER
Definition: evrcdec.c:43
EVRCContext::gb
GetBitContext gb
Definition: evrcdec.c:75
RATE_ERRS
@ RATE_ERRS
Definition: evrcdec.c:47
interpolate_delay
static void interpolate_delay(float *dst, float current, float prev, int index)
Definition: evrcdec.c:330
acelp_vectors.h
opt.h
decode_lspf
static int decode_lspf(EVRCContext *e)
Decode the 10 vector quantized line spectral pair frequencies from the LSP transmission codes of any ...
Definition: evrcdec.c:283
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1043
out
FILE * out
Definition: movenc.c:54
fcb_excitation
static void fcb_excitation(EVRCContext *e, const uint16_t *codebook, float *excitation, float pitch_gain, int pitch_lag, int subframe_size)
Definition: evrcdec.c:477
message
Definition: api-threadmessage-test.c:46
buf_size2bitrate
static evrc_packet_rate buf_size2bitrate(const int buf_size)
Definition: evrcdec.c:166
PfCoeff::p1
float p1
Definition: evrcdec.c:557
residual_filter
static void residual_filter(float *output, const float *input, const float *coef, float *memory, int length)
Definition: evrcdec.c:532
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:90
EVRCContext::prev_energy_gain
uint8_t prev_energy_gain
Definition: evrcdec.c:97
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
evrc_lspq_codebooks
static const float *const *const evrc_lspq_codebooks[]
Definition: evrcdata.h:1454
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
index
fg index
Definition: ffmpeg_filter.c:167
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
AVOption
AVOption.
Definition: opt.h:247
EVRCContext::prev_error_flag
uint8_t prev_error_flag
Definition: evrcdec.c:98
b
#define b
Definition: input.c:40
codebooks
static const uint8_t codebooks[]
Definition: vorbis_enc_data.h:26
data
const char data[16]
Definition: mxf.c:143
EVRCContext::pitch_back
float pitch_back[ACB_SIZE]
Definition: evrcdec.c:91
mathematics.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
evrc_energy_quant
static const float evrc_energy_quant[][3]
Rate 1/8 frame energy quantization.
Definition: evrcdata.h:38
EVRCContext::pitch
float pitch[ACB_SIZE+FILTER_ORDER+SUBFRAME_SIZE]
Definition: evrcdec.c:90
EVRCAFrame::fcb_gain
uint8_t fcb_gain[3]
fixed codebook gain index
Definition: evrcdec.c:65
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:380
EVRCAFrame::tty
uint8_t tty
tty baud rate bit
Definition: evrcdec.c:67
postfilter_coeffs
static const struct PfCoeff postfilter_coeffs[5]
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1703
MIN_LSP_SEP
#define MIN_LSP_SEP
Definition: evrcdec.c:38
subframe_sizes
static const uint8_t subframe_sizes[]
Definition: evrcdata.h:1498
GetBitContext
Definition: get_bits.h:62
unpack_frame
static void unpack_frame(EVRCContext *e)
Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT.
Definition: evrcdec.c:109
SILENCE
@ SILENCE
Definition: evrcdec.c:48
EVRCContext::last_valid_bitrate
evrc_packet_rate last_valid_bitrate
Definition: evrcdec.c:77
interpolate_lsp
static void interpolate_lsp(float *ilsp, const float *lsp, const float *prev, int index)
Definition: evrcdec.c:316
a1
#define a1
Definition: regdef.h:47
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:678
acb_excitation
static void acb_excitation(EVRCContext *e, float *excitation, float gain, const float delay[3], int length)
Definition: evrcdec.c:405
EVRCAFrame::fcb_shape
uint16_t fcb_shape[3][4]
fixed codebook shape
Definition: evrcdec.c:64
EVRCContext::warned_buf_mismatch_bitrate
uint8_t warned_buf_mismatch_bitrate
Definition: evrcdec.c:99
ff_evrc_decoder
const AVCodec ff_evrc_decoder
Definition: evrcdec.c:932
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
evrc_lspq_codebooks_row_sizes
static const uint8_t *const evrc_lspq_codebooks_row_sizes[]
Definition: evrcdata.h:1488
AD
#define AD
Definition: evrcdec.c:918
ff_acelp_lsf2lspd
void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp()
Definition: lsp.c:93
EVRCAFrame::acb_gain
uint8_t acb_gain[3]
adaptive codebook gain
Definition: evrcdec.c:63
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
get_bits.h
EVRCContext::avg_fcb_gain
float avg_fcb_gain
average fixed codebook gain
Definition: evrcdec.c:89
evrc_decode_frame
static int evrc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: evrcdec.c:743
EVRCAFrame::lpc_flag
uint8_t lpc_flag
spectral change indicator
Definition: evrcdec.c:59
f
#define f(width, name)
Definition: cbs_vp9.c:255
EVRCContext::postfilter_fir
float postfilter_fir[FILTER_ORDER]
Definition: evrcdec.c:83
if
if(ret)
Definition: filter_design.txt:179
bl_intrp
static void bl_intrp(EVRCContext *e, float *ex, float delay)
Definition: evrcdec.c:377
EVRCContext::prev_lspf
float prev_lspf[FILTER_ORDER]
Definition: evrcdec.c:81
EVRCContext::postfilter_iir
float postfilter_iir[FILTER_ORDER]
Definition: evrcdec.c:84
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
EVRCAFrame::delay_diff
uint8_t delay_diff
delay difference for entire frame
Definition: evrcdec.c:62
bandwidth_expansion
static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
Definition: evrcdec.c:521
decode_8_pulses_35bits
static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
Definition: evrcdec.c:432
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
EVRCAFrame::pitch_delay
uint8_t pitch_delay
pitch delay for entire frame
Definition: evrcdec.c:61
PfCoeff
Definition: evrcdec.c:554
av_clipf
#define av_clipf
Definition: common.h:144
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:499
EVRCContext::interpolation_coeffs
float interpolation_coeffs[136]
Definition: evrcdec.c:92
MAX_DELAY
#define MAX_DELAY
Definition: evrcdec.c:40
EVRCContext::postfilter
int postfilter
Definition: evrcdec.c:73
OFFSET
#define OFFSET(x)
Definition: evrcdec.c:917
exp
int8_t exp
Definition: eval.c:72
estimation_delay
static const float estimation_delay[]
Definition: evrcdata.h:1497
decode_3_pulses_10bits
static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
Definition: evrcdec.c:457
ACB_SIZE
#define ACB_SIZE
Definition: evrcdec.c:44
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:109
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1652
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
EVRCAFrame
EVRC-A unpacked data frame.
Definition: evrcdec.c:58
EVRCContext::pitch_delay
float pitch_delay
Definition: evrcdec.c:86
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1000
EVRCContext::prev_pitch_delay
float prev_pitch_delay
Definition: evrcdec.c:87
EVRCContext::fade_scale
float fade_scale
Definition: evrcdec.c:94
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:1704
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
RATE_QUARTER
@ RATE_QUARTER
Definition: evrcdec.c:50
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
RATE_HALF
@ RATE_HALF
Definition: evrcdec.c:51
EVRCContext::lspf
float lspf[FILTER_ORDER]
Definition: evrcdec.c:80
bitrate
int64_t bitrate
Definition: h264_levels.c:131
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
M_PI
#define M_PI
Definition: mathematics.h:52
evrc_packet_rate
evrc_packet_rate
Definition: evrcdec.c:46
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:993
options
static const AVOption options[]
Definition: evrcdec.c:920
PfCoeff::tilt
float tilt
Definition: evrcdec.c:555
EVRCContext::postfilter_residual
float postfilter_residual[ACB_SIZE+SUBFRAME_SIZE]
Definition: evrcdec.c:85
synthesis_filter
static void synthesis_filter(const float *in, const float *filter_coeffs, float *memory, int buffer_length, float *samples)
Synthesis of the decoder output signal.
Definition: evrcdec.c:505
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AV_CODEC_ID_EVRC
@ AV_CODEC_ID_EVRC
Definition: codec_id.h:494
NB_SUBFRAMES
#define NB_SUBFRAMES
Definition: evrcdec.c:41
a2
#define a2
Definition: regdef.h:48
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
postfilter
static void postfilter(EVRCContext *e, float *in, const float *coeff, float *out, int idx, const struct PfCoeff *pfc, int length)
Definition: evrcdec.c:572
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
EVRCContext::frame
EVRCAFrame frame
Definition: evrcdec.c:78
ff_weighted_vector_sumf
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b, float weight_coeff_a, float weight_coeff_b, int length)
float implementation of weighted sum of two vectors.
Definition: acelp_vectors.c:182
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:209
PfCoeff::ltgain
float ltgain
Definition: evrcdec.c:556
EVRCContext::avg_acb_gain
float avg_acb_gain
average adaptive codebook gain
Definition: evrcdec.c:88
RATE_QUANT
@ RATE_QUANT
Definition: evrcdec.c:49
warn_insufficient_frame_quality
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
Definition: evrcdec.c:220
avcodec.h
ret
ret
Definition: filter_design.txt:187
EVRCContext::energy_vector
float energy_vector[NB_SUBFRAMES]
Definition: evrcdec.c:93
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
lsp.h
evrcdata.h
pos
unsigned int pos
Definition: spdifenc.c:412
AVCodecContext
main external API structure.
Definition: avcodec.h:383
channel_layout.h
EVRCContext::last
float last
Definition: evrcdec.c:95
MIN_DELAY
#define MIN_DELAY
Definition: evrcdec.c:39
temp
else temp
Definition: vf_mcdeint.c:248
SUBFRAME_SIZE
#define SUBFRAME_SIZE
Definition: evrcdec.c:42
RATE_FULL
@ RATE_FULL
Definition: evrcdec.c:52
frame_erasure
static void frame_erasure(EVRCContext *e, float *samples)
Definition: evrcdec.c:653
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
EVRCAFrame::energy_gain
uint8_t energy_gain
frame energy gain index
Definition: evrcdec.c:66
evrc_lspq_nb_codebooks
static const uint8_t evrc_lspq_nb_codebooks[]
Definition: evrcdata.h:1462
AVCodecContext::frame_number
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1023
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
EVRCContext::bitrate
evrc_packet_rate bitrate
Definition: evrcdec.c:76
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:78
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
decode_predictor_coeffs
static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
Definition: evrcdec.c:347
pitch_gain_vq
static const float pitch_gain_vq[]
Definition: evrcdata.h:1496
EVRCContext::synthesis
float synthesis[FILTER_ORDER]
Definition: evrcdec.c:82
EVRCContext
Definition: evrcdec.c:70
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
codebook
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
evrcdec_class
static const AVClass evrcdec_class
Definition: evrcdec.c:925
evrc_decode_init
static av_cold int evrc_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
Definition: evrcdec.c:232