Libav
g723_1dec.c
Go to the documentation of this file.
1 /*
2  * G.723.1 compatible decoder
3  * Copyright (c) 2006 Benjamin Larsson
4  * Copyright (c) 2010 Mohamed Naufal Basheer
5  *
6  * This file is part of Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 
32 #define BITSTREAM_READER_LE
33 #include "acelp_vectors.h"
34 #include "avcodec.h"
35 #include "celp_filters.h"
36 #include "get_bits.h"
37 #include "internal.h"
38 #include "g723_1.h"
39 
40 #define CNG_RANDOM_SEED 12345
41 
43 {
44  G723_1_Context *p = avctx->priv_data;
45 
48  avctx->channels = 1;
49  avctx->sample_rate = 8000;
50  p->pf_gain = 1 << 12;
51 
52  memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
53  memcpy(p->sid_lsp, dc_lsp, LPC_ORDER * sizeof(*p->sid_lsp));
54 
57 
58  return 0;
59 }
60 
68 static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
69  int buf_size)
70 {
71  GetBitContext gb;
72  int ad_cb_len;
73  int temp, info_bits, i;
74 
75  init_get_bits(&gb, buf, buf_size * 8);
76 
77  /* Extract frame type and rate info */
78  info_bits = get_bits(&gb, 2);
79 
80  if (info_bits == 3) {
82  return 0;
83  }
84 
85  /* Extract 24 bit lsp indices, 8 bit for each band */
86  p->lsp_index[2] = get_bits(&gb, 8);
87  p->lsp_index[1] = get_bits(&gb, 8);
88  p->lsp_index[0] = get_bits(&gb, 8);
89 
90  if (info_bits == 2) {
92  p->subframe[0].amp_index = get_bits(&gb, 6);
93  return 0;
94  }
95 
96  /* Extract the info common to both rates */
97  p->cur_rate = info_bits ? RATE_5300 : RATE_6300;
99 
100  p->pitch_lag[0] = get_bits(&gb, 7);
101  if (p->pitch_lag[0] > 123) /* test if forbidden code */
102  return -1;
103  p->pitch_lag[0] += PITCH_MIN;
104  p->subframe[1].ad_cb_lag = get_bits(&gb, 2);
105 
106  p->pitch_lag[1] = get_bits(&gb, 7);
107  if (p->pitch_lag[1] > 123)
108  return -1;
109  p->pitch_lag[1] += PITCH_MIN;
110  p->subframe[3].ad_cb_lag = get_bits(&gb, 2);
111  p->subframe[0].ad_cb_lag = 1;
112  p->subframe[2].ad_cb_lag = 1;
113 
114  for (i = 0; i < SUBFRAMES; i++) {
115  /* Extract combined gain */
116  temp = get_bits(&gb, 12);
117  ad_cb_len = 170;
118  p->subframe[i].dirac_train = 0;
119  if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) {
120  p->subframe[i].dirac_train = temp >> 11;
121  temp &= 0x7FF;
122  ad_cb_len = 85;
123  }
124  p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS);
125  if (p->subframe[i].ad_cb_gain < ad_cb_len) {
126  p->subframe[i].amp_index = temp - p->subframe[i].ad_cb_gain *
127  GAIN_LEVELS;
128  } else {
129  return -1;
130  }
131  }
132 
133  p->subframe[0].grid_index = get_bits(&gb, 1);
134  p->subframe[1].grid_index = get_bits(&gb, 1);
135  p->subframe[2].grid_index = get_bits(&gb, 1);
136  p->subframe[3].grid_index = get_bits(&gb, 1);
137 
138  if (p->cur_rate == RATE_6300) {
139  skip_bits(&gb, 1); /* skip reserved bit */
140 
141  /* Compute pulse_pos index using the 13-bit combined position index */
142  temp = get_bits(&gb, 13);
143  p->subframe[0].pulse_pos = temp / 810;
144 
145  temp -= p->subframe[0].pulse_pos * 810;
146  p->subframe[1].pulse_pos = FASTDIV(temp, 90);
147 
148  temp -= p->subframe[1].pulse_pos * 90;
149  p->subframe[2].pulse_pos = FASTDIV(temp, 9);
150  p->subframe[3].pulse_pos = temp - p->subframe[2].pulse_pos * 9;
151 
152  p->subframe[0].pulse_pos = (p->subframe[0].pulse_pos << 16) +
153  get_bits(&gb, 16);
154  p->subframe[1].pulse_pos = (p->subframe[1].pulse_pos << 14) +
155  get_bits(&gb, 14);
156  p->subframe[2].pulse_pos = (p->subframe[2].pulse_pos << 16) +
157  get_bits(&gb, 16);
158  p->subframe[3].pulse_pos = (p->subframe[3].pulse_pos << 14) +
159  get_bits(&gb, 14);
160 
161  p->subframe[0].pulse_sign = get_bits(&gb, 6);
162  p->subframe[1].pulse_sign = get_bits(&gb, 5);
163  p->subframe[2].pulse_sign = get_bits(&gb, 6);
164  p->subframe[3].pulse_sign = get_bits(&gb, 5);
165  } else { /* 5300 bps */
166  p->subframe[0].pulse_pos = get_bits(&gb, 12);
167  p->subframe[1].pulse_pos = get_bits(&gb, 12);
168  p->subframe[2].pulse_pos = get_bits(&gb, 12);
169  p->subframe[3].pulse_pos = get_bits(&gb, 12);
170 
171  p->subframe[0].pulse_sign = get_bits(&gb, 4);
172  p->subframe[1].pulse_sign = get_bits(&gb, 4);
173  p->subframe[2].pulse_sign = get_bits(&gb, 4);
174  p->subframe[3].pulse_sign = get_bits(&gb, 4);
175  }
176 
177  return 0;
178 }
179 
183 static int16_t square_root(int val)
184 {
185  int16_t res = 0;
186  int16_t exp = 0x4000;
187  int i;
188 
189  for (i = 0; i < 14; i ++) {
190  int res_exp = res + exp;
191  if (val >= res_exp * res_exp << 1)
192  res += exp;
193  exp >>= 1;
194  }
195  return res;
196 }
197 
204 #define MULL2(a, b) \
205  ((((a) >> 16) * (b) << 1) + (((a) & 0xffff) * (b) >> 15))
206 
216 static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe *subfrm,
217  enum Rate cur_rate, int pitch_lag, int index)
218 {
219  int temp, i, j;
220 
221  memset(vector, 0, SUBFRAME_LEN * sizeof(*vector));
222 
223  if (cur_rate == RATE_6300) {
224  if (subfrm->pulse_pos >= max_pos[index])
225  return;
226 
227  /* Decode amplitudes and positions */
228  j = PULSE_MAX - pulses[index];
229  temp = subfrm->pulse_pos;
230  for (i = 0; i < SUBFRAME_LEN / GRID_SIZE; i++) {
231  temp -= combinatorial_table[j][i];
232  if (temp >= 0)
233  continue;
234  temp += combinatorial_table[j++][i];
235  if (subfrm->pulse_sign & (1 << (PULSE_MAX - j))) {
236  vector[subfrm->grid_index + GRID_SIZE * i] =
237  -fixed_cb_gain[subfrm->amp_index];
238  } else {
239  vector[subfrm->grid_index + GRID_SIZE * i] =
240  fixed_cb_gain[subfrm->amp_index];
241  }
242  if (j == PULSE_MAX)
243  break;
244  }
245  if (subfrm->dirac_train == 1)
246  ff_g723_1_gen_dirac_train(vector, pitch_lag);
247  } else { /* 5300 bps */
248  int cb_gain = fixed_cb_gain[subfrm->amp_index];
249  int cb_shift = subfrm->grid_index;
250  int cb_sign = subfrm->pulse_sign;
251  int cb_pos = subfrm->pulse_pos;
252  int offset, beta, lag;
253 
254  for (i = 0; i < 8; i += 2) {
255  offset = ((cb_pos & 7) << 3) + cb_shift + i;
256  vector[offset] = (cb_sign & 1) ? cb_gain : -cb_gain;
257  cb_pos >>= 3;
258  cb_sign >>= 1;
259  }
260 
261  /* Enhance harmonic components */
262  lag = pitch_contrib[subfrm->ad_cb_gain << 1] + pitch_lag +
263  subfrm->ad_cb_lag - 1;
264  beta = pitch_contrib[(subfrm->ad_cb_gain << 1) + 1];
265 
266  if (lag < SUBFRAME_LEN - 2) {
267  for (i = lag; i < SUBFRAME_LEN; i++)
268  vector[i] += beta * vector[i - lag] >> 15;
269  }
270  }
271 }
272 
283 static int autocorr_max(const int16_t *buf, int offset, int *ccr_max,
284  int pitch_lag, int length, int dir)
285 {
286  int limit, ccr, lag = 0;
287  int i;
288 
289  pitch_lag = FFMIN(PITCH_MAX - 3, pitch_lag);
290  if (dir > 0)
291  limit = FFMIN(FRAME_LEN + PITCH_MAX - offset - length, pitch_lag + 3);
292  else
293  limit = pitch_lag + 3;
294 
295  for (i = pitch_lag - 3; i <= limit; i++) {
296  ccr = ff_g723_1_dot_product(buf, buf + dir * i, length);
297 
298  if (ccr > *ccr_max) {
299  *ccr_max = ccr;
300  lag = i;
301  }
302  }
303  return lag;
304 }
305 
316 static void comp_ppf_gains(int lag, PPFParam *ppf, enum Rate cur_rate,
317  int tgt_eng, int ccr, int res_eng)
318 {
319  int pf_residual; /* square of postfiltered residual */
320  int temp1, temp2;
321 
322  ppf->index = lag;
323 
324  temp1 = tgt_eng * res_eng >> 1;
325  temp2 = ccr * ccr << 1;
326 
327  if (temp2 > temp1) {
328  if (ccr >= res_eng) {
329  ppf->opt_gain = ppf_gain_weight[cur_rate];
330  } else {
331  ppf->opt_gain = (ccr << 15) / res_eng *
332  ppf_gain_weight[cur_rate] >> 15;
333  }
334  /* pf_res^2 = tgt_eng + 2*ccr*gain + res_eng*gain^2 */
335  temp1 = (tgt_eng << 15) + (ccr * ppf->opt_gain << 1);
336  temp2 = (ppf->opt_gain * ppf->opt_gain >> 15) * res_eng;
337  pf_residual = av_sat_add32(temp1, temp2 + (1 << 15)) >> 16;
338 
339  if (tgt_eng >= pf_residual << 1) {
340  temp1 = 0x7fff;
341  } else {
342  temp1 = (tgt_eng << 14) / pf_residual;
343  }
344 
345  /* scaling_gain = sqrt(tgt_eng/pf_res^2) */
346  ppf->sc_gain = square_root(temp1 << 16);
347  } else {
348  ppf->opt_gain = 0;
349  ppf->sc_gain = 0x7fff;
350  }
351 
352  ppf->opt_gain = av_clip_int16(ppf->opt_gain * ppf->sc_gain >> 15);
353 }
354 
364 static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag,
365  PPFParam *ppf, enum Rate cur_rate)
366 {
367 
368  int16_t scale;
369  int i;
370  int temp1, temp2;
371 
372  /*
373  * 0 - target energy
374  * 1 - forward cross-correlation
375  * 2 - forward residual energy
376  * 3 - backward cross-correlation
377  * 4 - backward residual energy
378  */
379  int energy[5] = {0, 0, 0, 0, 0};
380  int16_t *buf = p->audio + LPC_ORDER + offset;
381  int fwd_lag = autocorr_max(buf, offset, &energy[1], pitch_lag,
382  SUBFRAME_LEN, 1);
383  int back_lag = autocorr_max(buf, offset, &energy[3], pitch_lag,
384  SUBFRAME_LEN, -1);
385 
386  ppf->index = 0;
387  ppf->opt_gain = 0;
388  ppf->sc_gain = 0x7fff;
389 
390  /* Case 0, Section 3.6 */
391  if (!back_lag && !fwd_lag)
392  return;
393 
394  /* Compute target energy */
395  energy[0] = ff_g723_1_dot_product(buf, buf, SUBFRAME_LEN);
396 
397  /* Compute forward residual energy */
398  if (fwd_lag)
399  energy[2] = ff_g723_1_dot_product(buf + fwd_lag, buf + fwd_lag,
400  SUBFRAME_LEN);
401 
402  /* Compute backward residual energy */
403  if (back_lag)
404  energy[4] = ff_g723_1_dot_product(buf - back_lag, buf - back_lag,
405  SUBFRAME_LEN);
406 
407  /* Normalize and shorten */
408  temp1 = 0;
409  for (i = 0; i < 5; i++)
410  temp1 = FFMAX(energy[i], temp1);
411 
412  scale = ff_g723_1_normalize_bits(temp1, 31);
413  for (i = 0; i < 5; i++)
414  energy[i] = (energy[i] << scale) >> 16;
415 
416  if (fwd_lag && !back_lag) { /* Case 1 */
417  comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1],
418  energy[2]);
419  } else if (!fwd_lag) { /* Case 2 */
420  comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3],
421  energy[4]);
422  } else { /* Case 3 */
423 
424  /*
425  * Select the largest of energy[1]^2/energy[2]
426  * and energy[3]^2/energy[4]
427  */
428  temp1 = energy[4] * ((energy[1] * energy[1] + (1 << 14)) >> 15);
429  temp2 = energy[2] * ((energy[3] * energy[3] + (1 << 14)) >> 15);
430  if (temp1 >= temp2) {
431  comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1],
432  energy[2]);
433  } else {
434  comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3],
435  energy[4]);
436  }
437  }
438 }
439 
450 static int comp_interp_index(G723_1_Context *p, int pitch_lag,
451  int *exc_eng, int *scale)
452 {
453  int offset = PITCH_MAX + 2 * SUBFRAME_LEN;
454  int16_t *buf = p->audio + LPC_ORDER;
455 
456  int index, ccr, tgt_eng, best_eng, temp;
457 
459  buf += offset;
460 
461  /* Compute maximum backward cross-correlation */
462  ccr = 0;
463  index = autocorr_max(buf, offset, &ccr, pitch_lag, SUBFRAME_LEN * 2, -1);
464  ccr = av_sat_add32(ccr, 1 << 15) >> 16;
465 
466  /* Compute target energy */
467  tgt_eng = ff_g723_1_dot_product(buf, buf, SUBFRAME_LEN * 2);
468  *exc_eng = av_sat_add32(tgt_eng, 1 << 15) >> 16;
469 
470  if (ccr <= 0)
471  return 0;
472 
473  /* Compute best energy */
474  best_eng = ff_g723_1_dot_product(buf - index, buf - index,
475  SUBFRAME_LEN * 2);
476  best_eng = av_sat_add32(best_eng, 1 << 15) >> 16;
477 
478  temp = best_eng * *exc_eng >> 3;
479 
480  if (temp < ccr * ccr)
481  return index;
482  else
483  return 0;
484 }
485 
495 static void residual_interp(int16_t *buf, int16_t *out, int lag,
496  int gain, int *rseed)
497 {
498  int i;
499  if (lag) { /* Voiced */
500  int16_t *vector_ptr = buf + PITCH_MAX;
501  /* Attenuate */
502  for (i = 0; i < lag; i++)
503  out[i] = vector_ptr[i - lag] * 3 >> 2;
504  av_memcpy_backptr((uint8_t*)(out + lag), lag * sizeof(*out),
505  (FRAME_LEN - lag) * sizeof(*out));
506  } else { /* Unvoiced */
507  for (i = 0; i < FRAME_LEN; i++) {
508  *rseed = *rseed * 521 + 259;
509  out[i] = gain * *rseed >> 15;
510  }
511  memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(*buf));
512  }
513 }
514 
523 static void iir_filter(int16_t *fir_coef, int16_t *iir_coef,
524  int16_t *src, int *dest)
525 {
526  int m, n;
527 
528  for (m = 0; m < SUBFRAME_LEN; m++) {
529  int64_t filter = 0;
530  for (n = 1; n <= LPC_ORDER; n++) {
531  filter -= fir_coef[n - 1] * src[m - n] -
532  iir_coef[n - 1] * (dest[m - n] >> 16);
533  }
534 
535  dest[m] = av_clipl_int32((src[m] << 16) + (filter << 3) + (1 << 15));
536  }
537 }
538 
546 static void gain_scale(G723_1_Context *p, int16_t * buf, int energy)
547 {
548  int num, denom, gain, bits1, bits2;
549  int i;
550 
551  num = energy;
552  denom = 0;
553  for (i = 0; i < SUBFRAME_LEN; i++) {
554  int temp = buf[i] >> 2;
555  temp *= temp;
556  denom = av_sat_dadd32(denom, temp);
557  }
558 
559  if (num && denom) {
560  bits1 = ff_g723_1_normalize_bits(num, 31);
561  bits2 = ff_g723_1_normalize_bits(denom, 31);
562  num = num << bits1 >> 1;
563  denom <<= bits2;
564 
565  bits2 = 5 + bits1 - bits2;
566  bits2 = FFMAX(0, bits2);
567 
568  gain = (num >> 1) / (denom >> 16);
569  gain = square_root(gain << 16 >> bits2);
570  } else {
571  gain = 1 << 12;
572  }
573 
574  for (i = 0; i < SUBFRAME_LEN; i++) {
575  p->pf_gain = (15 * p->pf_gain + gain + (1 << 3)) >> 4;
576  buf[i] = av_clip_int16((buf[i] * (p->pf_gain + (p->pf_gain >> 4)) +
577  (1 << 10)) >> 11);
578  }
579 }
580 
589 static void formant_postfilter(G723_1_Context *p, int16_t *lpc,
590  int16_t *buf, int16_t *dst)
591 {
592  int16_t filter_coef[2][LPC_ORDER];
593  int filter_signal[LPC_ORDER + FRAME_LEN], *signal_ptr;
594  int i, j, k;
595 
596  memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(*buf));
597  memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(*filter_signal));
598 
599  for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) {
600  for (k = 0; k < LPC_ORDER; k++) {
601  filter_coef[0][k] = (-lpc[k] * postfilter_tbl[0][k] +
602  (1 << 14)) >> 15;
603  filter_coef[1][k] = (-lpc[k] * postfilter_tbl[1][k] +
604  (1 << 14)) >> 15;
605  }
606  iir_filter(filter_coef[0], filter_coef[1], buf + i, filter_signal + i);
607  lpc += LPC_ORDER;
608  }
609 
610  memcpy(p->fir_mem, buf + FRAME_LEN, LPC_ORDER * sizeof(*p->fir_mem));
611  memcpy(p->iir_mem, filter_signal + FRAME_LEN,
612  LPC_ORDER * sizeof(*p->iir_mem));
613 
614  buf += LPC_ORDER;
615  signal_ptr = filter_signal + LPC_ORDER;
616  for (i = 0; i < SUBFRAMES; i++) {
617  int temp;
618  int auto_corr[2];
619  int scale, energy;
620 
621  /* Normalize */
622  scale = ff_g723_1_scale_vector(dst, buf, SUBFRAME_LEN);
623 
624  /* Compute auto correlation coefficients */
625  auto_corr[0] = ff_g723_1_dot_product(dst, dst + 1, SUBFRAME_LEN - 1);
626  auto_corr[1] = ff_g723_1_dot_product(dst, dst, SUBFRAME_LEN);
627 
628  /* Compute reflection coefficient */
629  temp = auto_corr[1] >> 16;
630  if (temp) {
631  temp = (auto_corr[0] >> 2) / temp;
632  }
633  p->reflection_coef = (3 * p->reflection_coef + temp + 2) >> 2;
634  temp = -p->reflection_coef >> 1 & ~3;
635 
636  /* Compensation filter */
637  for (j = 0; j < SUBFRAME_LEN; j++) {
638  dst[j] = av_sat_dadd32(signal_ptr[j],
639  (signal_ptr[j - 1] >> 16) * temp) >> 16;
640  }
641 
642  /* Compute normalized signal energy */
643  temp = 2 * scale + 4;
644  if (temp < 0) {
645  energy = av_clipl_int32((int64_t)auto_corr[1] << -temp);
646  } else
647  energy = auto_corr[1] >> temp;
648 
649  gain_scale(p, dst, energy);
650 
651  buf += SUBFRAME_LEN;
652  signal_ptr += SUBFRAME_LEN;
653  dst += SUBFRAME_LEN;
654  }
655 }
656 
657 static int sid_gain_to_lsp_index(int gain)
658 {
659  if (gain < 0x10)
660  return gain << 6;
661  else if (gain < 0x20)
662  return gain - 8 << 7;
663  else
664  return gain - 20 << 8;
665 }
666 
667 static inline int cng_rand(int *state, int base)
668 {
669  *state = (*state * 521 + 259) & 0xFFFF;
670  return (*state & 0x7FFF) * base >> 15;
671 }
672 
674 {
675  int i, shift, seg, seg2, t, val, val_add, x, y;
676 
677  shift = 16 - p->cur_gain * 2;
678  if (shift > 0)
679  t = p->sid_gain << shift;
680  else
681  t = p->sid_gain >> -shift;
682  x = t * cng_filt[0] >> 16;
683 
684  if (x >= cng_bseg[2])
685  return 0x3F;
686 
687  if (x >= cng_bseg[1]) {
688  shift = 4;
689  seg = 3;
690  } else {
691  shift = 3;
692  seg = (x >= cng_bseg[0]);
693  }
694  seg2 = FFMIN(seg, 3);
695 
696  val = 1 << shift;
697  val_add = val >> 1;
698  for (i = 0; i < shift; i++) {
699  t = seg * 32 + (val << seg2);
700  t *= t;
701  if (x >= t)
702  val += val_add;
703  else
704  val -= val_add;
705  val_add >>= 1;
706  }
707 
708  t = seg * 32 + (val << seg2);
709  y = t * t - x;
710  if (y <= 0) {
711  t = seg * 32 + (val + 1 << seg2);
712  t = t * t - x;
713  val = (seg2 - 1 << 4) + val;
714  if (t >= y)
715  val++;
716  } else {
717  t = seg * 32 + (val - 1 << seg2);
718  t = t * t - x;
719  val = (seg2 - 1 << 4) + val;
720  if (t >= y)
721  val--;
722  }
723 
724  return val;
725 }
726 
728 {
729  int i, j, idx, t;
730  int off[SUBFRAMES];
731  int signs[SUBFRAMES / 2 * 11], pos[SUBFRAMES / 2 * 11];
732  int tmp[SUBFRAME_LEN * 2];
733  int16_t *vector_ptr;
734  int64_t sum;
735  int b0, c, delta, x, shift;
736 
737  p->pitch_lag[0] = cng_rand(&p->cng_random_seed, 21) + 123;
738  p->pitch_lag[1] = cng_rand(&p->cng_random_seed, 19) + 123;
739 
740  for (i = 0; i < SUBFRAMES; i++) {
741  p->subframe[i].ad_cb_gain = cng_rand(&p->cng_random_seed, 50) + 1;
743  }
744 
745  for (i = 0; i < SUBFRAMES / 2; i++) {
746  t = cng_rand(&p->cng_random_seed, 1 << 13);
747  off[i * 2] = t & 1;
748  off[i * 2 + 1] = ((t >> 1) & 1) + SUBFRAME_LEN;
749  t >>= 2;
750  for (j = 0; j < 11; j++) {
751  signs[i * 11 + j] = (t & 1) * 2 - 1 << 14;
752  t >>= 1;
753  }
754  }
755 
756  idx = 0;
757  for (i = 0; i < SUBFRAMES; i++) {
758  for (j = 0; j < SUBFRAME_LEN / 2; j++)
759  tmp[j] = j;
760  t = SUBFRAME_LEN / 2;
761  for (j = 0; j < pulses[i]; j++, idx++) {
762  int idx2 = cng_rand(&p->cng_random_seed, t);
763 
764  pos[idx] = tmp[idx2] * 2 + off[i];
765  tmp[idx2] = tmp[--t];
766  }
767  }
768 
769  vector_ptr = p->audio + LPC_ORDER;
770  memcpy(vector_ptr, p->prev_excitation,
771  PITCH_MAX * sizeof(*p->excitation));
772  for (i = 0; i < SUBFRAMES; i += 2) {
773  ff_g723_1_gen_acb_excitation(vector_ptr, vector_ptr,
774  p->pitch_lag[i >> 1], &p->subframe[i],
775  p->cur_rate);
777  vector_ptr + SUBFRAME_LEN,
778  p->pitch_lag[i >> 1], &p->subframe[i + 1],
779  p->cur_rate);
780 
781  t = 0;
782  for (j = 0; j < SUBFRAME_LEN * 2; j++)
783  t |= FFABS(vector_ptr[j]);
784  t = FFMIN(t, 0x7FFF);
785  if (!t) {
786  shift = 0;
787  } else {
788  shift = -10 + av_log2(t);
789  if (shift < -2)
790  shift = -2;
791  }
792  sum = 0;
793  if (shift < 0) {
794  for (j = 0; j < SUBFRAME_LEN * 2; j++) {
795  t = vector_ptr[j] << -shift;
796  sum += t * t;
797  tmp[j] = t;
798  }
799  } else {
800  for (j = 0; j < SUBFRAME_LEN * 2; j++) {
801  t = vector_ptr[j] >> shift;
802  sum += t * t;
803  tmp[j] = t;
804  }
805  }
806 
807  b0 = 0;
808  for (j = 0; j < 11; j++)
809  b0 += tmp[pos[(i / 2) * 11 + j]] * signs[(i / 2) * 11 + j];
810  b0 = b0 * 2 * 2979LL + (1 << 29) >> 30; // approximated division by 11
811 
812  c = p->cur_gain * (p->cur_gain * SUBFRAME_LEN >> 5);
813  if (shift * 2 + 3 >= 0)
814  c >>= shift * 2 + 3;
815  else
816  c <<= -(shift * 2 + 3);
817  c = (av_clipl_int32(sum << 1) - c) * 2979LL >> 15;
818 
819  delta = b0 * b0 * 2 - c;
820  if (delta <= 0) {
821  x = -b0;
822  } else {
823  delta = square_root(delta);
824  x = delta - b0;
825  t = delta + b0;
826  if (FFABS(t) < FFABS(x))
827  x = -t;
828  }
829  shift++;
830  if (shift < 0)
831  x >>= -shift;
832  else
833  x <<= shift;
834  x = av_clip(x, -10000, 10000);
835 
836  for (j = 0; j < 11; j++) {
837  idx = (i / 2) * 11 + j;
838  vector_ptr[pos[idx]] = av_clip_int16(vector_ptr[pos[idx]] +
839  (x * signs[idx] >> 15));
840  }
841 
842  /* copy decoded data to serve as a history for the next decoded subframes */
843  memcpy(vector_ptr + PITCH_MAX, vector_ptr,
844  sizeof(*vector_ptr) * SUBFRAME_LEN * 2);
845  vector_ptr += SUBFRAME_LEN * 2;
846  }
847  /* Save the excitation for the next frame */
848  memcpy(p->prev_excitation, p->audio + LPC_ORDER + FRAME_LEN,
849  PITCH_MAX * sizeof(*p->excitation));
850 }
851 
852 static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
853  int *got_frame_ptr, AVPacket *avpkt)
854 {
855  G723_1_Context *p = avctx->priv_data;
856  AVFrame *frame = data;
857  const uint8_t *buf = avpkt->data;
858  int buf_size = avpkt->size;
859  int dec_mode = buf[0] & 3;
860 
861  PPFParam ppf[SUBFRAMES];
862  int16_t cur_lsp[LPC_ORDER];
863  int16_t lpc[SUBFRAMES * LPC_ORDER];
864  int16_t acb_vector[SUBFRAME_LEN];
865  int16_t *out;
866  int bad_frame = 0, i, j, ret;
867  int16_t *audio = p->audio;
868 
869  if (buf_size < frame_size[dec_mode]) {
870  if (buf_size)
871  av_log(avctx, AV_LOG_WARNING,
872  "Expected %d bytes, got %d - skipping packet\n",
873  frame_size[dec_mode], buf_size);
874  *got_frame_ptr = 0;
875  return buf_size;
876  }
877 
878  if (unpack_bitstream(p, buf, buf_size) < 0) {
879  bad_frame = 1;
880  if (p->past_frame_type == ACTIVE_FRAME)
882  else
884  }
885 
886  frame->nb_samples = FRAME_LEN;
887  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
888  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
889  return ret;
890  }
891 
892  out = (int16_t *)frame->data[0];
893 
894  if (p->cur_frame_type == ACTIVE_FRAME) {
895  if (!bad_frame)
896  p->erased_frames = 0;
897  else if (p->erased_frames != 3)
898  p->erased_frames++;
899 
900  ff_g723_1_inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame);
901  ff_g723_1_lsp_interpolate(lpc, cur_lsp, p->prev_lsp);
902 
903  /* Save the lsp_vector for the next frame */
904  memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
905 
906  /* Generate the excitation for the frame */
907  memcpy(p->excitation, p->prev_excitation,
908  PITCH_MAX * sizeof(*p->excitation));
909  if (!p->erased_frames) {
910  int16_t *vector_ptr = p->excitation + PITCH_MAX;
911 
912  /* Update interpolation gain memory */
914  p->subframe[3].amp_index) >> 1];
915  for (i = 0; i < SUBFRAMES; i++) {
916  gen_fcb_excitation(vector_ptr, &p->subframe[i], p->cur_rate,
917  p->pitch_lag[i >> 1], i);
918  ff_g723_1_gen_acb_excitation(acb_vector,
919  &p->excitation[SUBFRAME_LEN * i],
920  p->pitch_lag[i >> 1],
921  &p->subframe[i], p->cur_rate);
922  /* Get the total excitation */
923  for (j = 0; j < SUBFRAME_LEN; j++) {
924  int v = av_clip_int16(vector_ptr[j] << 1);
925  vector_ptr[j] = av_clip_int16(v + acb_vector[j]);
926  }
927  vector_ptr += SUBFRAME_LEN;
928  }
929 
930  vector_ptr = p->excitation + PITCH_MAX;
931 
933  &p->sid_gain, &p->cur_gain);
934 
935  /* Perform pitch postfiltering */
936  if (p->postfilter) {
937  i = PITCH_MAX;
938  for (j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
939  comp_ppf_coeff(p, i, p->pitch_lag[j >> 1],
940  ppf + j, p->cur_rate);
941 
942  for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
944  vector_ptr + i,
945  vector_ptr + i + ppf[j].index,
946  ppf[j].sc_gain,
947  ppf[j].opt_gain,
948  1 << 14, 15, SUBFRAME_LEN);
949  } else {
950  audio = vector_ptr - LPC_ORDER;
951  }
952 
953  /* Save the excitation for the next frame */
954  memcpy(p->prev_excitation, p->excitation + FRAME_LEN,
955  PITCH_MAX * sizeof(*p->excitation));
956  } else {
957  p->interp_gain = (p->interp_gain * 3 + 2) >> 2;
958  if (p->erased_frames == 3) {
959  /* Mute output */
960  memset(p->excitation, 0,
961  (FRAME_LEN + PITCH_MAX) * sizeof(*p->excitation));
962  memset(p->prev_excitation, 0,
963  PITCH_MAX * sizeof(*p->excitation));
964  memset(frame->data[0], 0,
965  (FRAME_LEN + LPC_ORDER) * sizeof(int16_t));
966  } else {
967  int16_t *buf = p->audio + LPC_ORDER;
968 
969  /* Regenerate frame */
971  p->interp_gain, &p->random_seed);
972 
973  /* Save the excitation for the next frame */
974  memcpy(p->prev_excitation, buf + (FRAME_LEN - PITCH_MAX),
975  PITCH_MAX * sizeof(*p->excitation));
976  }
977  }
979  } else {
980  if (p->cur_frame_type == SID_FRAME) {
983  } else if (p->past_frame_type == ACTIVE_FRAME) {
984  p->sid_gain = estimate_sid_gain(p);
985  }
986 
987  if (p->past_frame_type == ACTIVE_FRAME)
988  p->cur_gain = p->sid_gain;
989  else
990  p->cur_gain = (p->cur_gain * 7 + p->sid_gain) >> 3;
991  generate_noise(p);
993  /* Save the lsp_vector for the next frame */
994  memcpy(p->prev_lsp, p->sid_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
995  }
996 
998 
999  memcpy(p->audio, p->synth_mem, LPC_ORDER * sizeof(*p->audio));
1000  for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++)
1001  ff_celp_lp_synthesis_filter(p->audio + i, &lpc[j * LPC_ORDER],
1002  audio + i, SUBFRAME_LEN, LPC_ORDER,
1003  0, 1, 1 << 12);
1004  memcpy(p->synth_mem, p->audio + FRAME_LEN, LPC_ORDER * sizeof(*p->audio));
1005 
1006  if (p->postfilter) {
1007  formant_postfilter(p, lpc, p->audio, out);
1008  } else { // if output is not postfiltered it should be scaled by 2
1009  for (i = 0; i < FRAME_LEN; i++)
1010  out[i] = av_clip_int16(p->audio[LPC_ORDER + i] << 1);
1011  }
1012 
1013  *got_frame_ptr = 1;
1014 
1015  return frame_size[dec_mode];
1016 }
1017 
1018 #define OFFSET(x) offsetof(G723_1_Context, x)
1019 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1020 
1021 static const AVOption options[] = {
1022  { "postfilter", "postfilter on/off", OFFSET(postfilter), AV_OPT_TYPE_INT,
1023  { .i64 = 1 }, 0, 1, AD },
1024  { NULL }
1025 };
1026 
1027 
1028 static const AVClass g723_1dec_class = {
1029  .class_name = "G.723.1 decoder",
1030  .item_name = av_default_item_name,
1031  .option = options,
1032  .version = LIBAVUTIL_VERSION_INT,
1033 };
1034 
1036  .name = "g723_1",
1037  .long_name = NULL_IF_CONFIG_SMALL("G.723.1"),
1038  .type = AVMEDIA_TYPE_AUDIO,
1039  .id = AV_CODEC_ID_G723_1,
1040  .priv_data_size = sizeof(G723_1_Context),
1043  .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
1044  .priv_class = &g723_1dec_class,
1045 };
int16_t audio[FRAME_LEN+LPC_ORDER+PITCH_MAX+4]
Definition: g723_1.h:148
static void comp_ppf_gains(int lag, PPFParam *ppf, enum Rate cur_rate, int tgt_eng, int ccr, int res_eng)
Calculate pitch postfilter optimal and scaling gains.
Definition: g723_1dec.c:316
int cur_gain
Definition: g723_1.h:143
int erased_frames
Definition: g723_1.h:128
int dirac_train
Definition: g723_1.h:83
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
int reflection_coef
Definition: g723_1.h:144
int ad_cb_gain
Definition: g723_1.h:82
static void iir_filter(int16_t *fir_coef, int16_t *iir_coef, int16_t *src, int *dest)
Perform IIR filtering.
Definition: g723_1dec.c:523
AVOption.
Definition: opt.h:234
int pitch_lag[2]
Definition: g723_1.h:127
static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe *subfrm, enum Rate cur_rate, int pitch_lag, int index)
Generate fixed codebook excitation vector.
Definition: g723_1dec.c:216
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:228
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
static const int32_t max_pos[4]
Definition: g723_1.h:707
memory handling functions
static const uint8_t frame_size[4]
Definition: g723_1.h:219
G723.1 unpacked data subframe.
Definition: g723_1.h:80
int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, const int16_t *in, int buffer_length, int filter_length, int stop_on_overflow, int shift, int rounder)
LP synthesis filter.
Definition: celp_filters.c:59
int16_t fir_mem[LPC_ORDER]
Definition: g723_1.h:135
int16_t excitation[PITCH_MAX+FRAME_LEN+4]
Definition: g723_1.h:133
static const AVClass g723_1dec_class
Definition: g723_1dec.c:1028
static const int8_t pulses[4]
Definition: g723_1.h:704
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static void residual_interp(int16_t *buf, int16_t *out, int lag, int gain, int *rseed)
Perform residual interpolation based on frame classification.
Definition: g723_1dec.c:495
AVCodec.
Definition: avcodec.h:3120
#define PITCH_MIN
Definition: g723_1.h:43
static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, int buf_size)
Unpack the frame into parameters.
Definition: g723_1dec.c:68
static void postfilter(AMRContext *p, float *lpc, float *buf_out)
Perform adaptive post-filtering to enhance the quality of the speech.
Definition: amrnbdec.c:886
enum FrameType past_frame_type
Definition: g723_1.h:124
#define FRAME_LEN
Definition: g723_1.h:37
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:39
void ff_g723_1_inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, uint8_t *lsp_index, int bad_frame)
Perform inverse quantization of LSP frequencies.
Definition: g723_1.c:202
static const int cng_filt[4]
Definition: g723_1.h:1418
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2160
uint8_t
#define av_cold
Definition: attributes.h:66
float delta
static int comp_interp_index(G723_1_Context *p, int pitch_lag, int *exc_eng, int *scale)
Classify frames as voiced/unvoiced.
Definition: g723_1dec.c:450
AVOptions.
#define LPC_ORDER
Definition: g723_1.h:40
Rate
G723.1 rate values.
Definition: g723_1.h:72
int pulse_sign
Definition: g723_1.h:84
const char data[16]
Definition: mxf.c:70
static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag, PPFParam *ppf, enum Rate cur_rate)
Calculate pitch postfilter parameters.
Definition: g723_1dec.c:364
uint8_t * data
Definition: avcodec.h:1346
static const uint8_t bits2[81]
Definition: aactab.c:126
bitstream reader API header.
void ff_g723_1_lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
Quantize LSP frequencies by interpolation and convert them to the corresponding LPC coefficients...
Definition: g723_1.c:181
#define GRID_SIZE
Definition: g723_1.h:46
#define SUBFRAMES
Definition: dss_sp.c:31
static int16_t square_root(int val)
Bitexact implementation of sqrt(val/2).
Definition: g723_1dec.c:183
#define src
Definition: vp8dsp.c:254
static const int32_t combinatorial_table[PULSE_MAX][SUBFRAME_LEN/GRID_SIZE]
Definition: g723_1.h:613
int16_t sid_lsp[LPC_ORDER]
Definition: g723_1.h:131
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
int ff_g723_1_normalize_bits(int num, int width)
Calculate the number of left-shifts required for normalizing the input.
Definition: g723_1.c:49
int amp_index
Definition: g723_1.h:86
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
void ff_g723_1_gen_dirac_train(int16_t *buf, int pitch_lag)
Generate a train of dirac functions with period as pitch lag.
Definition: g723_1.c:74
static void gain_scale(G723_1_Context *p, int16_t *buf, int energy)
Adjust gain of postfiltered signal.
Definition: g723_1dec.c:546
int grid_index
Definition: g723_1.h:85
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
int16_t prev_excitation[PITCH_MAX]
Definition: g723_1.h:132
#define FFMAX(a, b)
Definition: common.h:64
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2203
int interp_index
Definition: g723_1.h:140
static int estimate_sid_gain(G723_1_Context *p)
Definition: g723_1dec.c:673
void ff_g723_1_gen_acb_excitation(int16_t *vector, int16_t *prev_excitation, int pitch_lag, G723_1_Subframe *subfrm, enum Rate cur_rate)
Generate adaptive codebook excitation.
Definition: g723_1.c:86
G723_1_Subframe subframe[4]
Definition: g723_1.h:122
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
#define PITCH_MAX
Definition: g723_1.h:44
static const int16_t fixed_cb_gain[GAIN_LEVELS]
Definition: g723_1.h:709
enum Rate cur_rate
Definition: g723_1.h:125
void ff_acelp_weighted_vector_sum(int16_t *out, const int16_t *in_a, const int16_t *in_b, int16_t weight_coeff_a, int16_t weight_coeff_b, int16_t rounder, int shift, int length)
weighted sum of two vectors with rounding.
static const int16_t postfilter_tbl[2][LPC_ORDER]
Definition: g723_1.h:1360
audio channel layout utility functions
int16_t synth_mem[LPC_ORDER]
Definition: g723_1.h:134
#define FFMIN(a, b)
Definition: common.h:66
AVCodec ff_g723_1_decoder
Definition: g723_1dec.c:1035
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
static const int cng_adaptive_cb_lag[4]
Definition: g723_1.h:1416
int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length)
Definition: g723_1.c:54
#define FFABS(a)
Definition: common.h:61
#define OFFSET(x)
Definition: g723_1dec.c:1018
int index
postfilter backward/forward lag
Definition: g723_1.h:94
static int autocorr_max(const int16_t *buf, int offset, int *ccr_max, int pitch_lag, int length, int dir)
Estimate maximum auto-correlation around pitch lag.
Definition: g723_1dec.c:283
int sid_gain
Definition: g723_1.h:142
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
if(ac->has_optimized_func)
#define GAIN_LEVELS
Definition: g723_1.h:48
int16_t opt_gain
optimal gain
Definition: g723_1.h:95
int postfilter
Definition: g723_1.h:146
NULL
Definition: eval.c:55
int ff_g723_1_scale_vector(int16_t *dst, const int16_t *vector, int length)
Scale vector contents based on the largest of their absolutes.
Definition: g723_1.c:32
Libavcodec external API header.
static const int16_t dc_lsp[LPC_ORDER]
Definition: g723_1.h:225
static const int16_t pitch_contrib[340]
Definition: g723_1.h:657
int sample_rate
samples per second
Definition: avcodec.h:2152
av_default_item_name
Definition: dnxhdenc.c:55
main external API structure.
Definition: avcodec.h:1409
static const int16_t ppf_gain_weight[2]
Definition: g723_1.h:222
static int sid_gain_to_lsp_index(int gain)
Definition: g723_1dec.c:657
#define FASTDIV(a, b)
Definition: mathops.h:190
Silence Insertion Descriptor frame.
Definition: g723_1.h:65
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
G.723.1 types, functions and data tables.
static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf, int16_t *dst)
Perform formant filtering.
Definition: g723_1dec.c:589
Describe the class of an AVClass context structure.
Definition: log.h:34
#define PULSE_MAX
Definition: dss_sp.c:32
int16_t sc_gain
scaling gain
Definition: g723_1.h:96
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:259
int index
Definition: gxfenc.c:72
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
Definition: avcodec.h:880
int cng_random_seed
Definition: g723_1.h:139
int random_seed
Definition: g723_1.h:138
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:362
Active speech.
Definition: g723_1.h:64
#define CNG_RANDOM_SEED
Definition: g723_1dec.c:40
enum FrameType cur_frame_type
Definition: g723_1.h:123
#define SUBFRAME_LEN
Definition: g723_1.h:36
int16_t prev_lsp[LPC_ORDER]
Definition: g723_1.h:130
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
#define AD
Definition: g723_1dec.c:1019
static struct @174 state
common internal api header.
Pitch postfilter parameters.
Definition: g723_1.h:93
signed 16 bits
Definition: samplefmt.h:63
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
void * priv_data
Definition: avcodec.h:1451
static const int cng_bseg[3]
Definition: g723_1.h:1420
int channels
number of audio channels
Definition: avcodec.h:2153
#define av_log2
Definition: intmath.h:85
static uint8_t tmp[8]
Definition: des.c:38
static const AVOption options[]
Definition: g723_1dec.c:1021
uint8_t lsp_index[LSP_BANDS]
Definition: g723_1.h:126
int pulse_pos
Definition: g723_1.h:87
int iir_mem[LPC_ORDER]
Definition: g723_1.h:136
static av_cold int g723_1_decode_init(AVCodecContext *avctx)
Definition: g723_1dec.c:42
FILE * out
Definition: movenc.c:54
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
Definition: mem.c:325
static int cng_rand(int *state, int base)
Definition: g723_1dec.c:667
int interp_gain
Definition: g723_1.h:141
static void generate_noise(G723_1_Context *p)
Definition: g723_1dec.c:727
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
Definition: avcodec.h:1323
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:184
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
static int g723_1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: g723_1dec.c:852
static const uint8_t bits1[81]
Definition: aactab.c:103
int ad_cb_lag
adaptive codebook lag
Definition: g723_1.h:81