FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
28 #include "libavutil/mathematics.h"
29 #include "avcodec.h"
30 #include "internal.h"
31 #include "get_bits.h"
32 #include "evrcdata.h"
33 #include "acelp_vectors.h"
34 #include "lsp.h"
35 
36 #define MIN_LSP_SEP (0.05 / (2.0 * M_PI))
37 #define MIN_DELAY 20
38 #define MAX_DELAY 120
39 #define NB_SUBFRAMES 3
40 #define SUBFRAME_SIZE 54
41 #define FILTER_ORDER 10
42 #define ACB_SIZE 128
43 
44 typedef enum {
45  RATE_ERRS = -1,
52 
53 /**
54  * EVRC-A unpacked data frame
55  */
56 typedef struct EVRCAFrame {
57  uint8_t lpc_flag; ///< spectral change indicator
58  uint16_t lsp[4]; ///< index into LSP codebook
59  uint8_t pitch_delay; ///< pitch delay for entire frame
60  uint8_t delay_diff; ///< delay difference for entire frame
61  uint8_t acb_gain[3]; ///< adaptive codebook gain
62  uint16_t fcb_shape[3][4]; ///< fixed codebook shape
63  uint8_t fcb_gain[3]; ///< fixed codebook gain index
64  uint8_t energy_gain; ///< frame energy gain index
65  uint8_t tty; ///< tty baud rate bit
66 } EVRCAFrame;
67 
68 typedef struct EVRCContext {
73 
80  float pitch_delay;
82  float avg_acb_gain; ///< average adaptive codebook gain
83  float avg_fcb_gain; ///< average fixed codebook gain
88  float fade_scale;
89  float last;
90 
94 } EVRCContext;
95 
96 /**
97  * Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT
98  *
99  * @param e the context
100  *
101  * TIA/IS-127 Table 4.21-1
102  */
103 static void unpack_frame(EVRCContext *e)
104 {
105  EVRCAFrame *frame = &e->frame;
106  GetBitContext *gb = &e->gb;
107 
108  switch (e->bitrate) {
109  case RATE_FULL:
110  frame->lpc_flag = get_bits1(gb);
111  frame->lsp[0] = get_bits(gb, 6);
112  frame->lsp[1] = get_bits(gb, 6);
113  frame->lsp[2] = get_bits(gb, 9);
114  frame->lsp[3] = get_bits(gb, 7);
115  frame->pitch_delay = get_bits(gb, 7);
116  frame->delay_diff = get_bits(gb, 5);
117  frame->acb_gain[0] = get_bits(gb, 3);
118  frame->fcb_shape[0][0] = get_bits(gb, 8);
119  frame->fcb_shape[0][1] = get_bits(gb, 8);
120  frame->fcb_shape[0][2] = get_bits(gb, 8);
121  frame->fcb_shape[0][3] = get_bits(gb, 11);
122  frame->fcb_gain[0] = get_bits(gb, 5);
123  frame->acb_gain[1] = get_bits(gb, 3);
124  frame->fcb_shape[1][0] = get_bits(gb, 8);
125  frame->fcb_shape[1][1] = get_bits(gb, 8);
126  frame->fcb_shape[1][2] = get_bits(gb, 8);
127  frame->fcb_shape[1][3] = get_bits(gb, 11);
128  frame->fcb_gain [1] = get_bits(gb, 5);
129  frame->acb_gain [2] = get_bits(gb, 3);
130  frame->fcb_shape[2][0] = get_bits(gb, 8);
131  frame->fcb_shape[2][1] = get_bits(gb, 8);
132  frame->fcb_shape[2][2] = get_bits(gb, 8);
133  frame->fcb_shape[2][3] = get_bits(gb, 11);
134  frame->fcb_gain [2] = get_bits(gb, 5);
135  frame->tty = get_bits1(gb);
136  break;
137  case RATE_HALF:
138  frame->lsp [0] = get_bits(gb, 7);
139  frame->lsp [1] = get_bits(gb, 7);
140  frame->lsp [2] = get_bits(gb, 8);
141  frame->pitch_delay = get_bits(gb, 7);
142  frame->acb_gain [0] = get_bits(gb, 3);
143  frame->fcb_shape[0][0] = get_bits(gb, 10);
144  frame->fcb_gain [0] = get_bits(gb, 4);
145  frame->acb_gain [1] = get_bits(gb, 3);
146  frame->fcb_shape[1][0] = get_bits(gb, 10);
147  frame->fcb_gain [1] = get_bits(gb, 4);
148  frame->acb_gain [2] = get_bits(gb, 3);
149  frame->fcb_shape[2][0] = get_bits(gb, 10);
150  frame->fcb_gain [2] = get_bits(gb, 4);
151  break;
152  case RATE_QUANT:
153  frame->lsp [0] = get_bits(gb, 4);
154  frame->lsp [1] = get_bits(gb, 4);
155  frame->energy_gain = get_bits(gb, 8);
156  break;
157  }
158 }
159 
160 static evrc_packet_rate buf_size2bitrate(const int buf_size)
161 {
162  switch (buf_size) {
163  case 23: return RATE_FULL;
164  case 11: return RATE_HALF;
165  case 6: return RATE_QUARTER;
166  case 3: return RATE_QUANT;
167  case 1: return SILENCE;
168  }
169 
170  return RATE_ERRS;
171 }
172 
173 /**
174  * Determine the bitrate from the frame size and/or the first byte of the frame.
175  *
176  * @param avctx the AV codec context
177  * @param buf_size length of the buffer
178  * @param buf the bufffer
179  *
180  * @return the bitrate on success,
181  * RATE_ERRS if the bitrate cannot be satisfactorily determined
182  */
184  int *buf_size,
185  const uint8_t **buf)
186 {
187  evrc_packet_rate bitrate;
188 
189  if ((bitrate = buf_size2bitrate(*buf_size)) >= 0) {
190  if (bitrate > **buf) {
191  EVRCContext *e = avctx->priv_data;
192  if (!e->warned_buf_mismatch_bitrate) {
193  av_log(avctx, AV_LOG_WARNING,
194  "Claimed bitrate and buffer size mismatch.\n");
196  }
197  bitrate = **buf;
198  } else if (bitrate < **buf) {
199  av_log(avctx, AV_LOG_ERROR,
200  "Buffer is too small for the claimed bitrate.\n");
201  return RATE_ERRS;
202  }
203  (*buf)++;
204  *buf_size -= 1;
205  } else if ((bitrate = buf_size2bitrate(*buf_size + 1)) >= 0) {
206  av_log(avctx, AV_LOG_DEBUG,
207  "Bitrate byte is missing, guessing the bitrate from packet size.\n");
208  } else
209  return RATE_ERRS;
210 
211  return bitrate;
212 }
213 
215  const char *message)
216 {
217  av_log(avctx, AV_LOG_WARNING, "Frame #%d, %s\n",
218  avctx->frame_number, message);
219 }
220 
221 /**
222  * Initialize the speech codec according to the specification.
223  *
224  * TIA/IS-127 5.2
225  */
227 {
228  EVRCContext *e = avctx->priv_data;
229  int i, n, idx = 0;
230  float denom = 2.0 / (2.0 * 8.0 + 1.0);
231 
232  avctx->channels = 1;
234  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
235 
236  for (i = 0; i < FILTER_ORDER; i++) {
237  e->prev_lspf[i] = (i + 1) * 0.048;
238  e->synthesis[i] = 0.0;
239  }
240 
241  for (i = 0; i < ACB_SIZE; i++)
242  e->pitch[i] = e->pitch_back[i] = 0.0;
243 
245  e->prev_pitch_delay = 40.0;
246  e->fade_scale = 1.0;
247  e->prev_error_flag = 0;
248  e->avg_acb_gain = e->avg_fcb_gain = 0.0;
249 
250  for (i = 0; i < 8; i++) {
251  float tt = ((float)i - 8.0 / 2.0) / 8.0;
252 
253  for (n = -8; n <= 8; n++, idx++) {
254  float arg1 = M_PI * 0.9 * (tt - n);
255  float arg2 = M_PI * (tt - n);
256 
257  e->interpolation_coeffs[idx] = 0.9;
258  if (arg1)
259  e->interpolation_coeffs[idx] *= (0.54 + 0.46 * cos(arg2 * denom)) *
260  sin(arg1) / arg1;
261  }
262  }
263 
264  return 0;
265 }
266 
267 /**
268  * Decode the 10 vector quantized line spectral pair frequencies from the LSP
269  * transmission codes of any bitrate and check for badly received packets.
270  *
271  * @param e the context
272  *
273  * @return 0 on success, -1 if the packet is badly received
274  *
275  * TIA/IS-127 5.2.1, 5.7.1
276  */
277 static int decode_lspf(EVRCContext *e)
278 {
279  const float * const *codebooks = evrc_lspq_codebooks[e->bitrate];
280  int i, j, k = 0;
281 
282  for (i = 0; i < evrc_lspq_nb_codebooks[e->bitrate]; i++) {
284  const float *codebook = codebooks[i];
285 
286  for (j = 0; j < row_size; j++)
287  e->lspf[k++] = codebook[e->frame.lsp[i] * row_size + j];
288  }
289 
290  // check for monotonic LSPs
291  for (i = 1; i < FILTER_ORDER; i++)
292  if (e->lspf[i] <= e->lspf[i - 1])
293  return -1;
294 
295  // check for minimum separation of LSPs at the splits
296  for (i = 0, k = 0; i < evrc_lspq_nb_codebooks[e->bitrate] - 1; i++) {
298  if (e->lspf[k] - e->lspf[k - 1] <= MIN_LSP_SEP)
299  return -1;
300  }
301 
302  return 0;
303 }
304 
305 /*
306  * Interpolation of LSP parameters.
307  *
308  * TIA/IS-127 5.2.3.1, 5.7.3.2
309  */
310 static void interpolate_lsp(float *ilsp, const float *lsp,
311  const float *prev, int index)
312 {
313  static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 };
314  ff_weighted_vector_sumf(ilsp, prev, lsp,
315  1.0 - lsp_interpolation_factors[index],
316  lsp_interpolation_factors[index], FILTER_ORDER);
317 }
318 
319 /*
320  * Reconstruction of the delay contour.
321  *
322  * TIA/IS-127 5.2.2.3.2
323  */
324 static void interpolate_delay(float *dst, float current, float prev, int index)
325 {
326  static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 };
327  dst[0] = (1.0 - d_interpolation_factors[index ]) * prev
328  + d_interpolation_factors[index ] * current;
329  dst[1] = (1.0 - d_interpolation_factors[index + 1]) * prev
330  + d_interpolation_factors[index + 1] * current;
331  dst[2] = (1.0 - d_interpolation_factors[index + 2]) * prev
332  + d_interpolation_factors[index + 2] * current;
333 }
334 
335 /*
336  * Convert the quantized, interpolated line spectral frequencies,
337  * to prediction coefficients.
338  *
339  * TIA/IS-127 5.2.3.2, 4.7.2.2
340  */
341 static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
342 {
343  double lsp[FILTER_ORDER];
344  float a[FILTER_ORDER / 2 + 1], b[FILTER_ORDER / 2 + 1];
345  float a1[FILTER_ORDER / 2] = { 0 };
346  float a2[FILTER_ORDER / 2] = { 0 };
347  float b1[FILTER_ORDER / 2] = { 0 };
348  float b2[FILTER_ORDER / 2] = { 0 };
349  int i, k;
350 
351  ff_acelp_lsf2lspd(lsp, ilspf, FILTER_ORDER);
352 
353  for (k = 0; k <= FILTER_ORDER; k++) {
354  a[0] = k < 2 ? 0.25 : 0;
355  b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
356 
357  for (i = 0; i < FILTER_ORDER / 2; i++) {
358  a[i + 1] = a[i] - 2 * lsp[i * 2 ] * a1[i] + a2[i];
359  b[i + 1] = b[i] - 2 * lsp[i * 2 + 1] * b1[i] + b2[i];
360  a2[i] = a1[i];
361  a1[i] = a[i];
362  b2[i] = b1[i];
363  b1[i] = b[i];
364  }
365 
366  if (k)
367  ilpc[k - 1] = 2.0 * (a[FILTER_ORDER / 2] + b[FILTER_ORDER / 2]);
368  }
369 }
370 
371 static void bl_intrp(EVRCContext *e, float *ex, float delay)
372 {
373  float *f;
374  int offset, i, coef_idx;
375  int16_t t;
376 
377  offset = lrintf(delay);
378 
379  t = (offset - delay + 0.5) * 8.0 + 0.5;
380  if (t == 8) {
381  t = 0;
382  offset--;
383  }
384 
385  f = ex - offset - 8;
386 
387  coef_idx = t * (2 * 8 + 1);
388 
389  ex[0] = 0.0;
390  for (i = 0; i < 2 * 8 + 1; i++)
391  ex[0] += e->interpolation_coeffs[coef_idx + i] * f[i];
392 }
393 
394 /*
395  * Adaptive codebook excitation.
396  *
397  * TIA/IS-127 5.2.2.3.3, 4.12.5.2
398  */
399 static void acb_excitation(EVRCContext *e, float *excitation, float gain,
400  const float delay[3], int length)
401 {
402  float denom, locdelay, dpr, invl;
403  int i;
404 
405  invl = 1.0 / ((float) length);
406  dpr = length;
407 
408  /* first at-most extra samples */
409  denom = (delay[1] - delay[0]) * invl;
410  for (i = 0; i < dpr; i++) {
411  locdelay = delay[0] + i * denom;
412  bl_intrp(e, excitation + i, locdelay);
413  }
414 
415  denom = (delay[2] - delay[1]) * invl;
416  /* interpolation */
417  for (i = dpr; i < dpr + 10; i++) {
418  locdelay = delay[1] + (i - dpr) * denom;
419  bl_intrp(e, excitation + i, locdelay);
420  }
421 
422  for (i = 0; i < length; i++)
423  excitation[i] *= gain;
424 }
425 
426 static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
427 {
428  int i, pos1, pos2, offset;
429 
430  offset = (fixed_index[3] >> 9) & 3;
431 
432  for (i = 0; i < 3; i++) {
433  pos1 = ((fixed_index[i] & 0x7f) / 11) * 5 + ((i + offset) % 5);
434  pos2 = ((fixed_index[i] & 0x7f) % 11) * 5 + ((i + offset) % 5);
435 
436  cod[pos1] = (fixed_index[i] & 0x80) ? -1.0 : 1.0;
437 
438  if (pos2 < pos1)
439  cod[pos2] = -cod[pos1];
440  else
441  cod[pos2] += cod[pos1];
442  }
443 
444  pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 + offset) % 5);
445  pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 + offset) % 5);
446 
447  cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0;
448  cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0;
449 }
450 
451 static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
452 {
453  float sign;
454  int pos;
455 
456  sign = (fixed_index & 0x200) ? -1.0 : 1.0;
457 
458  pos = ((fixed_index & 0x7) * 7) + 4;
459  cod[pos] += sign;
460  pos = (((fixed_index >> 3) & 0x7) * 7) + 2;
461  cod[pos] -= sign;
462  pos = (((fixed_index >> 6) & 0x7) * 7);
463  cod[pos] += sign;
464 }
465 
466 /*
467  * Reconstruction of ACELP fixed codebook excitation for full and half rate.
468  *
469  * TIA/IS-127 5.2.3.7
470  */
471 static void fcb_excitation(EVRCContext *e, const uint16_t *codebook,
472  float *excitation, float pitch_gain,
473  int pitch_lag, int subframe_size)
474 {
475  int i;
476 
477  if (e->bitrate == RATE_FULL)
478  decode_8_pulses_35bits(codebook, excitation);
479  else
480  decode_3_pulses_10bits(*codebook, excitation);
481 
482  pitch_gain = av_clipf(pitch_gain, 0.2, 0.9);
483 
484  for (i = pitch_lag; i < subframe_size; i++)
485  excitation[i] += pitch_gain * excitation[i - pitch_lag];
486 }
487 
488 /**
489  * Synthesis of the decoder output signal.
490  *
491  * param[in] in input signal
492  * param[in] filter_coeffs LPC coefficients
493  * param[in/out] memory synthesis filter memory
494  * param buffer_length amount of data to process
495  * param[out] samples output samples
496  *
497  * TIA/IS-127 5.2.3.15, 5.7.3.4
498  */
499 static void synthesis_filter(const float *in, const float *filter_coeffs,
500  float *memory, int buffer_length, float *samples)
501 {
502  int i, j;
503 
504  for (i = 0; i < buffer_length; i++) {
505  samples[i] = in[i];
506  for (j = FILTER_ORDER - 1; j > 0; j--) {
507  samples[i] -= filter_coeffs[j] * memory[j];
508  memory[j] = memory[j - 1];
509  }
510  samples[i] -= filter_coeffs[0] * memory[0];
511  memory[0] = samples[i];
512  }
513 }
514 
515 static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
516 {
517  double fac = gamma;
518  int i;
519 
520  for (i = 0; i < FILTER_ORDER; i++) {
521  coeff[i] = inbuf[i] * fac;
522  fac *= gamma;
523  }
524 }
525 
526 static void residual_filter(float *output, const float *input,
527  const float *coef, float *memory, int length)
528 {
529  float sum;
530  int i, j;
531 
532  for (i = 0; i < length; i++) {
533  sum = input[i];
534 
535  for (j = FILTER_ORDER - 1; j > 0; j--) {
536  sum += coef[j] * memory[j];
537  memory[j] = memory[j - 1];
538  }
539  sum += coef[0] * memory[0];
540  memory[0] = input[i];
541  output[i] = sum;
542  }
543 }
544 
545 /*
546  * TIA/IS-127 Table 5.9.1-1.
547  */
548 static const struct PfCoeff {
549  float tilt;
550  float ltgain;
551  float p1;
552  float p2;
553 } postfilter_coeffs[5] = {
554  { 0.0 , 0.0 , 0.0 , 0.0 },
555  { 0.0 , 0.0 , 0.57, 0.57 },
556  { 0.0 , 0.0 , 0.0 , 0.0 },
557  { 0.35, 0.50, 0.50, 0.75 },
558  { 0.20, 0.50, 0.57, 0.75 },
559 };
560 
561 /*
562  * Adaptive postfilter.
563  *
564  * TIA/IS-127 5.9
565  */
566 static void postfilter(EVRCContext *e, float *in, const float *coeff,
567  float *out, int idx, const struct PfCoeff *pfc,
568  int length)
569 {
570  float wcoef1[FILTER_ORDER], wcoef2[FILTER_ORDER],
571  scratch[SUBFRAME_SIZE], temp[SUBFRAME_SIZE],
573  float sum1 = 0.0, sum2 = 0.0, gamma, gain;
574  float tilt = pfc->tilt;
575  int i, n, best;
576 
577  bandwidth_expansion(wcoef1, coeff, pfc->p1);
578  bandwidth_expansion(wcoef2, coeff, pfc->p2);
579 
580  /* Tilt compensation filter, TIA/IS-127 5.9.1 */
581  for (i = 0; i < length - 1; i++)
582  sum2 += in[i] * in[i + 1];
583  if (sum2 < 0.0)
584  tilt = 0.0;
585 
586  for (i = 0; i < length; i++) {
587  scratch[i] = in[i] - tilt * e->last;
588  e->last = in[i];
589  }
590 
591  /* Short term residual filter, TIA/IS-127 5.9.2 */
592  residual_filter(&e->postfilter_residual[ACB_SIZE], scratch, wcoef1, e->postfilter_fir, length);
593 
594  /* Long term postfilter */
595  best = idx;
596  for (i = FFMIN(MIN_DELAY, idx - 3); i <= FFMAX(MAX_DELAY, idx + 3); i++) {
597  for (n = ACB_SIZE, sum2 = 0; n < ACB_SIZE + length; n++)
598  sum2 += e->postfilter_residual[n] * e->postfilter_residual[n - i];
599  if (sum2 > sum1) {
600  sum1 = sum2;
601  best = i;
602  }
603  }
604 
605  for (i = ACB_SIZE, sum1 = 0; i < ACB_SIZE + length; i++)
606  sum1 += e->postfilter_residual[i - best] * e->postfilter_residual[i - best];
607  for (i = ACB_SIZE, sum2 = 0; i < ACB_SIZE + length; i++)
608  sum2 += e->postfilter_residual[i] * e->postfilter_residual[i - best];
609 
610  if (sum2 * sum1 == 0 || e->bitrate == RATE_QUANT) {
611  memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));
612  } else {
613  gamma = sum2 / sum1;
614  if (gamma < 0.5)
615  memcpy(temp, e->postfilter_residual + ACB_SIZE, length * sizeof(float));
616  else {
617  gamma = FFMIN(gamma, 1.0);
618 
619  for (i = 0; i < length; i++) {
620  temp[i] = e->postfilter_residual[ACB_SIZE + i] + gamma *
621  pfc->ltgain * e->postfilter_residual[ACB_SIZE + i - best];
622  }
623  }
624  }
625 
626  memcpy(scratch, temp, length * sizeof(float));
627  memcpy(mem, e->postfilter_iir, FILTER_ORDER * sizeof(float));
628  synthesis_filter(scratch, wcoef2, mem, length, scratch);
629 
630  /* Gain computation, TIA/IS-127 5.9.4-2 */
631  for (i = 0, sum1 = 0, sum2 = 0; i < length; i++) {
632  sum1 += in[i] * in[i];
633  sum2 += scratch[i] * scratch[i];
634  }
635  gain = sum2 ? sqrt(sum1 / sum2) : 1.0;
636 
637  for (i = 0; i < length; i++)
638  temp[i] *= gain;
639 
640  /* Short term postfilter */
641  synthesis_filter(temp, wcoef2, e->postfilter_iir, length, out);
642 
643  memmove(e->postfilter_residual,
644  e->postfilter_residual + length, ACB_SIZE * sizeof(float));
645 }
646 
647 static void frame_erasure(EVRCContext *e, float *samples)
648 {
649  float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES],
650  tmp[SUBFRAME_SIZE + 6], f;
651  int i, j;
652 
653  for (i = 0; i < FILTER_ORDER; i++) {
654  if (e->bitrate != RATE_QUANT)
655  e->lspf[i] = e->prev_lspf[i] * 0.875 + 0.125 * (i + 1) * 0.048;
656  else
657  e->lspf[i] = e->prev_lspf[i];
658  }
659 
660  if (e->prev_error_flag)
661  e->avg_acb_gain *= 0.75;
662  if (e->bitrate == RATE_FULL)
663  memcpy(e->pitch_back, e->pitch, ACB_SIZE * sizeof(float));
664  if (e->last_valid_bitrate == RATE_QUANT)
665  e->bitrate = RATE_QUANT;
666  else
667  e->bitrate = RATE_FULL;
668 
669  if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) {
671  } else {
672  float sum = 0;
673 
674  idelay[0] = idelay[1] = idelay[2] = MIN_DELAY;
675 
676  for (i = 0; i < NB_SUBFRAMES; i++)
677  sum += evrc_energy_quant[e->prev_energy_gain][i];
678  sum /= (float) NB_SUBFRAMES;
679  sum = pow(10, sum);
680  for (i = 0; i < NB_SUBFRAMES; i++)
681  e->energy_vector[i] = sum;
682  }
683 
684  if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15)
686 
687  for (i = 0; i < NB_SUBFRAMES; i++) {
688  int subframe_size = subframe_sizes[i];
689  int pitch_lag;
690 
691  interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i);
692 
693  if (e->bitrate != RATE_QUANT) {
694  if (e->avg_acb_gain < 0.3) {
695  idelay[0] = estimation_delay[i];
696  idelay[1] = estimation_delay[i + 1];
697  idelay[2] = estimation_delay[i + 2];
698  } else {
700  }
701  }
702 
703  pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0);
704  decode_predictor_coeffs(ilspf, ilpc);
705 
706  if (e->bitrate != RATE_QUANT) {
707  acb_excitation(e, e->pitch + ACB_SIZE,
708  e->avg_acb_gain, idelay, subframe_size);
709  for (j = 0; j < subframe_size; j++)
710  e->pitch[ACB_SIZE + j] *= e->fade_scale;
711  e->fade_scale = FFMAX(e->fade_scale - 0.05, 0.0);
712  } else {
713  for (j = 0; j < subframe_size; j++)
714  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
715  }
716 
717  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
718 
719  if (e->bitrate != RATE_QUANT && e->avg_acb_gain < 0.4) {
720  f = 0.1 * e->avg_fcb_gain;
721  for (j = 0; j < subframe_size; j++)
722  e->pitch[ACB_SIZE + j] += f;
723  } else if (e->bitrate == RATE_QUANT) {
724  for (j = 0; j < subframe_size; j++)
725  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
726  }
727 
728  synthesis_filter(e->pitch + ACB_SIZE, ilpc,
729  e->synthesis, subframe_size, tmp);
730  postfilter(e, tmp, ilpc, samples, pitch_lag,
731  &postfilter_coeffs[e->bitrate], subframe_size);
732 
733  samples += subframe_size;
734  }
735 }
736 
737 static int evrc_decode_frame(AVCodecContext *avctx, void *data,
738  int *got_frame_ptr, AVPacket *avpkt)
739 {
740  const uint8_t *buf = avpkt->data;
741  AVFrame *frame = data;
742  EVRCContext *e = avctx->priv_data;
743  int buf_size = avpkt->size;
744  float ilspf[FILTER_ORDER], ilpc[FILTER_ORDER], idelay[NB_SUBFRAMES];
745  float *samples;
746  int i, j, ret, error_flag = 0;
747 
748  frame->nb_samples = 160;
749  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
750  return ret;
751  samples = (float *)frame->data[0];
752 
753  if ((e->bitrate = determine_bitrate(avctx, &buf_size, &buf)) == RATE_ERRS) {
754  warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
755  goto erasure;
756  }
757  if (e->bitrate <= SILENCE || e->bitrate == RATE_QUARTER)
758  goto erasure;
760  && !e->prev_error_flag)
761  goto erasure;
762 
763  if ((ret = init_get_bits8(&e->gb, buf, buf_size)) < 0)
764  return ret;
765  memset(&e->frame, 0, sizeof(EVRCAFrame));
766 
767  unpack_frame(e);
768 
769  if (e->bitrate != RATE_QUANT) {
770  uint8_t *p = (uint8_t *) &e->frame;
771  for (i = 0; i < sizeof(EVRCAFrame); i++) {
772  if (p[i])
773  break;
774  }
775  if (i == sizeof(EVRCAFrame))
776  goto erasure;
777  } else if (e->frame.lsp[0] == 0xf &&
778  e->frame.lsp[1] == 0xf &&
779  e->frame.energy_gain == 0xff) {
780  goto erasure;
781  }
782 
783  if (decode_lspf(e) < 0)
784  goto erasure;
785 
786  if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) {
787  /* Pitch delay parameter checking as per TIA/IS-127 5.1.5.1 */
789  goto erasure;
790 
792 
793  /* Delay diff parameter checking as per TIA/IS-127 5.1.5.2 */
794  if (e->frame.delay_diff) {
795  int p = e->pitch_delay - e->frame.delay_diff + 16;
796  if (p < MIN_DELAY || p > MAX_DELAY)
797  goto erasure;
798  }
799 
800  /* Delay contour reconstruction as per TIA/IS-127 5.2.2.2 */
801  if (e->frame.delay_diff &&
802  e->bitrate == RATE_FULL && e->prev_error_flag) {
803  float delay;
804 
805  memcpy(e->pitch, e->pitch_back, ACB_SIZE * sizeof(float));
806 
807  delay = e->prev_pitch_delay;
808  e->prev_pitch_delay = delay - e->frame.delay_diff + 16.0;
809 
810  if (fabs(e->pitch_delay - delay) > 15)
811  delay = e->pitch_delay;
812 
813  for (i = 0; i < NB_SUBFRAMES; i++) {
814  int subframe_size = subframe_sizes[i];
815 
816  interpolate_delay(idelay, delay, e->prev_pitch_delay, i);
817  acb_excitation(e, e->pitch + ACB_SIZE, e->avg_acb_gain, idelay, subframe_size);
818  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
819  }
820  }
821 
822  /* Smoothing of the decoded delay as per TIA/IS-127 5.2.2.5 */
823  if (fabs(e->pitch_delay - e->prev_pitch_delay) > 15)
825 
826  e->avg_acb_gain = e->avg_fcb_gain = 0.0;
827  } else {
828  idelay[0] = idelay[1] = idelay[2] = MIN_DELAY;
829 
830  /* Decode frame energy vectors as per TIA/IS-127 5.7.2 */
831  for (i = 0; i < NB_SUBFRAMES; i++)
832  e->energy_vector[i] = pow(10, evrc_energy_quant[e->frame.energy_gain][i]);
834  }
835 
836  for (i = 0; i < NB_SUBFRAMES; i++) {
837  float tmp[SUBFRAME_SIZE + 6] = { 0 };
838  int subframe_size = subframe_sizes[i];
839  int pitch_lag;
840 
841  interpolate_lsp(ilspf, e->lspf, e->prev_lspf, i);
842 
843  if (e->bitrate != RATE_QUANT)
845 
846  pitch_lag = lrintf((idelay[1] + idelay[0]) / 2.0);
847  decode_predictor_coeffs(ilspf, ilpc);
848 
849  /* Bandwidth expansion as per TIA/IS-127 5.2.3.3 */
850  if (e->frame.lpc_flag && e->prev_error_flag)
851  bandwidth_expansion(ilpc, ilpc, 0.75);
852 
853  if (e->bitrate != RATE_QUANT) {
854  float acb_sum, f;
855 
856  f = exp((e->bitrate == RATE_HALF ? 0.5 : 0.25)
857  * (e->frame.fcb_gain[i] + 1));
858  acb_sum = pitch_gain_vq[e->frame.acb_gain[i]];
859  e->avg_acb_gain += acb_sum / NB_SUBFRAMES;
860  e->avg_fcb_gain += f / NB_SUBFRAMES;
861 
862  acb_excitation(e, e->pitch + ACB_SIZE,
863  acb_sum, idelay, subframe_size);
864  fcb_excitation(e, e->frame.fcb_shape[i], tmp,
865  acb_sum, pitch_lag, subframe_size);
866 
867  /* Total excitation generation as per TIA/IS-127 5.2.3.9 */
868  for (j = 0; j < subframe_size; j++)
869  e->pitch[ACB_SIZE + j] += f * tmp[j];
870  e->fade_scale = FFMIN(e->fade_scale + 0.2, 1.0);
871  } else {
872  for (j = 0; j < subframe_size; j++)
873  e->pitch[ACB_SIZE + j] = e->energy_vector[i];
874  }
875 
876  memmove(e->pitch, e->pitch + subframe_size, ACB_SIZE * sizeof(float));
877 
878  synthesis_filter(e->pitch + ACB_SIZE, ilpc,
879  e->synthesis, subframe_size, tmp);
880  postfilter(e, tmp, ilpc, samples, pitch_lag,
881  &postfilter_coeffs[e->bitrate], subframe_size);
882 
883  samples += subframe_size;
884  }
885 
886  if (error_flag) {
887 erasure:
888  error_flag = 1;
889  av_log(avctx, AV_LOG_WARNING, "frame erasure\n");
890  frame_erasure(e, samples);
891  }
892 
893  memcpy(e->prev_lspf, e->lspf, sizeof(e->prev_lspf));
894  e->prev_error_flag = error_flag;
895  e->last_valid_bitrate = e->bitrate;
896 
897  if (e->bitrate != RATE_QUANT)
899 
900  samples = (float *)frame->data[0];
901  for (i = 0; i < 160; i++)
902  samples[i] /= 32768;
903 
904  *got_frame_ptr = 1;
905 
906  return avpkt->size;
907 }
908 
910  .name = "evrc",
911  .long_name = NULL_IF_CONFIG_SMALL("EVRC (Enhanced Variable Rate Codec)"),
912  .type = AVMEDIA_TYPE_AUDIO,
913  .id = AV_CODEC_ID_EVRC,
914  .init = evrc_decode_init,
915  .decode = evrc_decode_frame,
916  .capabilities = CODEC_CAP_DR1,
917  .priv_data_size = sizeof(EVRCContext),
918 };
Data tables for the EVRC decoder.
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
BYTE int const BYTE int int row_size
Definition: avisynth_c.h:676
uint8_t fcb_gain[3]
fixed codebook gain index
Definition: evrcdec.c:63
uint16_t lsp[4]
index into LSP codebook
Definition: evrcdec.c:58
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define FILTER_ORDER
Definition: evrcdec.c:41
uint8_t prev_energy_gain
Definition: evrcdec.c:91
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:183
else temp
Definition: vf_mcdeint.c:257
#define MIN_LSP_SEP
Definition: evrcdec.c:36
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.
static const float *const *const evrc_lspq_codebooks[]
Definition: evrcdata.h:1454
int size
Definition: avcodec.h:1163
const char * b
Definition: vf_curves.c:109
static void fcb_excitation(EVRCContext *e, const uint16_t *codebook, float *excitation, float pitch_gain, int pitch_lag, int subframe_size)
Definition: evrcdec.c:471
#define a1
Definition: regdef.h:47
float pitch_delay
Definition: evrcdec.c:80
float energy_vector[NB_SUBFRAMES]
Definition: evrcdec.c:87
static av_cold int evrc_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
Definition: evrcdec.c:226
float avg_fcb_gain
average fixed codebook gain
Definition: evrcdec.c:83
AVCodec.
Definition: avcodec.h:3181
uint8_t warned_buf_mismatch_bitrate
Definition: evrcdec.c:93
float lspf[FILTER_ORDER]
Definition: evrcdec.c:74
uint8_t tty
tty baud rate bit
Definition: evrcdec.c:65
static evrc_packet_rate buf_size2bitrate(const int buf_size)
Definition: evrcdec.c:160
if()
Definition: avfilter.c:975
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1993
int mem
Definition: avisynth_c.h:684
static void interpolate_lsp(float *ilsp, const float *lsp, const float *prev, int index)
Definition: evrcdec.c:310
uint8_t
#define av_cold
Definition: attributes.h:74
uint8_t lpc_flag
spectral change indicator
Definition: evrcdec.c:57
static void bl_intrp(EVRCContext *e, float *ex, float delay)
Definition: evrcdec.c:371
uint16_t fcb_shape[3][4]
fixed codebook shape
Definition: evrcdec.c:62
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:789
static AVFrame * frame
static const uint8_t *const evrc_lspq_codebooks_row_sizes[]
Definition: evrcdata.h:1488
uint8_t * data
Definition: avcodec.h:1162
static const float evrc_energy_quant[][3]
Rate 1/8 frame energy quantization.
Definition: evrcdata.h:38
float p1
Definition: evrcdec.c:551
bitstream reader API header.
#define lrintf(x)
Definition: libm_mips.h:70
static const uint8_t subframe_sizes[]
Definition: evrcdata.h:1498
float last
Definition: evrcdec.c:89
#define av_log(a,...)
float pitch[ACB_SIZE+FILTER_ORDER+SUBFRAME_SIZE]
Definition: evrcdec.c:84
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t prev_error_flag
Definition: evrcdec.c:92
#define ACB_SIZE
Definition: evrcdec.c:42
static const uint8_t evrc_lspq_nb_codebooks[]
Definition: evrcdata.h:1462
static void acb_excitation(EVRCContext *e, float *excitation, float gain, const float delay[3], int length)
Definition: evrcdec.c:399
float interpolation_coeffs[136]
Definition: evrcdec.c:86
float postfilter_residual[ACB_SIZE+SUBFRAME_SIZE]
Definition: evrcdec.c:79
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
AVCodec ff_evrc_decoder
Definition: evrcdec.c:909
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static void unpack_frame(EVRCContext *e)
Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT.
Definition: evrcdec.c:103
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3188
static int evrc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: evrcdec.c:737
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define FFMAX(a, b)
Definition: common.h:64
uint8_t acb_gain[3]
adaptive codebook gain
Definition: evrcdec.c:61
Libavcodec external API header.
#define MAX_DELAY
Definition: evrcdec.c:38
static const float pitch_gain_vq[]
Definition: evrcdata.h:1496
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2046
float prev_pitch_delay
Definition: evrcdec.c:81
float avg_acb_gain
average adaptive codebook gain
Definition: evrcdec.c:82
#define FFMIN(a, b)
Definition: common.h:66
evrc_packet_rate
Definition: evrcdec.c:44
ret
Definition: avfilter.c:974
GetBitContext gb
Definition: evrcdec.c:69
#define NB_SUBFRAMES
Definition: evrcdec.c:39
#define a2
Definition: regdef.h:48
float pitch_back[ACB_SIZE]
Definition: evrcdec.c:85
int n
Definition: avisynth_c.h:547
float prev_lspf[FILTER_ORDER]
Definition: evrcdec.c:75
static void postfilter(EVRCContext *e, float *in, const float *coeff, float *out, int idx, const struct PfCoeff *pfc, int length)
Definition: evrcdec.c:566
float postfilter_fir[FILTER_ORDER]
Definition: evrcdec.c:77
static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
Definition: evrcdec.c:515
uint8_t pitch_delay
pitch delay for entire frame
Definition: evrcdec.c:59
static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
Definition: evrcdec.c:426
uint8_t delay_diff
delay difference for entire frame
Definition: evrcdec.c:60
static const float estimation_delay[]
Definition: evrcdata.h:1497
float p2
Definition: evrcdec.c:552
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:441
static const struct PfCoeff postfilter_coeffs[5]
main external API structure.
Definition: avcodec.h:1241
static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
Definition: evrcdec.c:451
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1035
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
void * buf
Definition: avisynth_c.h:553
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
int index
Definition: gxfenc.c:89
float synthesis[FILTER_ORDER]
Definition: evrcdec.c:76
void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp()
Definition: lsp.c:93
EVRCAFrame frame
Definition: evrcdec.c:72
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:499
static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
Definition: evrcdec.c:341
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
evrc_packet_rate last_valid_bitrate
Definition: evrcdec.c:71
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
Definition: evrcdec.c:214
float tilt
Definition: evrcdec.c:549
common internal api header.
void * priv_data
Definition: avcodec.h:1283
int channels
number of audio channels
Definition: avcodec.h:1986
#define SUBFRAME_SIZE
Definition: evrcdec.c:40
evrc_packet_rate bitrate
Definition: evrcdec.c:70
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:277
static const double coeff[2][5]
Definition: vf_owdenoise.c:71
static void frame_erasure(EVRCContext *e, float *samples)
Definition: evrcdec.c:647
uint8_t energy_gain
frame energy gain index
Definition: evrcdec.c:64
float fade_scale
Definition: evrcdec.c:88
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2016
static void residual_filter(float *output, const float *input, const float *coef, float *memory, int length)
Definition: evrcdec.c:526
#define M_PI
Definition: mathematics.h:46
float postfilter_iir[FILTER_ORDER]
Definition: evrcdec.c:78
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
Definition: avcodec.h:1139
static void interpolate_delay(float *dst, float current, float prev, int index)
Definition: evrcdec.c:324
float ltgain
Definition: evrcdec.c:550
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
EVRC-A unpacked data frame.
Definition: evrcdec.c:56
#define MIN_DELAY
Definition: evrcdec.c:37
for(j=16;j >0;--j)