sipr.c
Go to the documentation of this file.
1 /*
2  * SIPR / ACELP.NET decoder
3  *
4  * Copyright (c) 2008 Vladimir Voroshilov
5  * Copyright (c) 2009 Vitor Sessak
6  *
7  * This file is part of Libav.
8  *
9  * Libav is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * Libav is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with Libav; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <math.h>
25 #include <stdint.h>
26 #include <string.h>
27 
29 #include "libavutil/mathematics.h"
30 #include "avcodec.h"
31 #define BITSTREAM_READER_LE
32 #include "get_bits.h"
33 #include "dsputil.h"
34 #include "internal.h"
35 
36 #include "lsp.h"
37 #include "acelp_vectors.h"
38 #include "acelp_pitch_delay.h"
39 #include "acelp_filters.h"
40 #include "celp_filters.h"
41 
42 #define MAX_SUBFRAME_COUNT 5
43 
44 #include "sipr.h"
45 #include "siprdata.h"
46 
47 typedef struct {
48  const char *mode_name;
49  uint16_t bits_per_frame;
53 
54  /* bitstream parameters */
57 
59  uint8_t vq_indexes_bits[5];
60 
62  uint8_t pitch_delay_bits[5];
63 
65  uint8_t fc_index_bits[10];
68 
69 static const SiprModeParam modes[MODE_COUNT] = {
70  [MODE_16k] = {
71  .mode_name = "16k",
72  .bits_per_frame = 160,
73  .subframe_count = SUBFRAME_COUNT_16k,
74  .frames_per_packet = 1,
75  .pitch_sharp_factor = 0.00,
76 
77  .number_of_fc_indexes = 10,
78  .ma_predictor_bits = 1,
79  .vq_indexes_bits = {7, 8, 7, 7, 7},
80  .pitch_delay_bits = {9, 6},
81  .gp_index_bits = 4,
82  .fc_index_bits = {4, 5, 4, 5, 4, 5, 4, 5, 4, 5},
83  .gc_index_bits = 5
84  },
85 
86  [MODE_8k5] = {
87  .mode_name = "8k5",
88  .bits_per_frame = 152,
89  .subframe_count = 3,
90  .frames_per_packet = 1,
91  .pitch_sharp_factor = 0.8,
92 
93  .number_of_fc_indexes = 3,
94  .ma_predictor_bits = 0,
95  .vq_indexes_bits = {6, 7, 7, 7, 5},
96  .pitch_delay_bits = {8, 5, 5},
97  .gp_index_bits = 0,
98  .fc_index_bits = {9, 9, 9},
99  .gc_index_bits = 7
100  },
101 
102  [MODE_6k5] = {
103  .mode_name = "6k5",
104  .bits_per_frame = 232,
105  .subframe_count = 3,
106  .frames_per_packet = 2,
107  .pitch_sharp_factor = 0.8,
108 
109  .number_of_fc_indexes = 3,
110  .ma_predictor_bits = 0,
111  .vq_indexes_bits = {6, 7, 7, 7, 5},
112  .pitch_delay_bits = {8, 5, 5},
113  .gp_index_bits = 0,
114  .fc_index_bits = {5, 5, 5},
115  .gc_index_bits = 7
116  },
117 
118  [MODE_5k0] = {
119  .mode_name = "5k0",
120  .bits_per_frame = 296,
121  .subframe_count = 5,
122  .frames_per_packet = 2,
123  .pitch_sharp_factor = 0.85,
124 
125  .number_of_fc_indexes = 1,
126  .ma_predictor_bits = 0,
127  .vq_indexes_bits = {6, 7, 7, 7, 5},
128  .pitch_delay_bits = {8, 5, 8, 5, 5},
129  .gp_index_bits = 0,
130  .fc_index_bits = {10},
131  .gc_index_bits = 7
132  }
133 };
134 
135 const float ff_pow_0_5[] = {
136  1.0/(1 << 1), 1.0/(1 << 2), 1.0/(1 << 3), 1.0/(1 << 4),
137  1.0/(1 << 5), 1.0/(1 << 6), 1.0/(1 << 7), 1.0/(1 << 8),
138  1.0/(1 << 9), 1.0/(1 << 10), 1.0/(1 << 11), 1.0/(1 << 12),
139  1.0/(1 << 13), 1.0/(1 << 14), 1.0/(1 << 15), 1.0/(1 << 16)
140 };
141 
142 static void dequant(float *out, const int *idx, const float *cbs[])
143 {
144  int i;
145  int stride = 2;
146  int num_vec = 5;
147 
148  for (i = 0; i < num_vec; i++)
149  memcpy(out + stride*i, cbs[i] + stride*idx[i], stride*sizeof(float));
150 
151 }
152 
153 static void lsf_decode_fp(float *lsfnew, float *lsf_history,
154  const SiprParameters *parm)
155 {
156  int i;
157  float lsf_tmp[LP_FILTER_ORDER];
158 
159  dequant(lsf_tmp, parm->vq_indexes, lsf_codebooks);
160 
161  for (i = 0; i < LP_FILTER_ORDER; i++)
162  lsfnew[i] = lsf_history[i] * 0.33 + lsf_tmp[i] + mean_lsf[i];
163 
164  ff_sort_nearly_sorted_floats(lsfnew, LP_FILTER_ORDER - 1);
165 
166  /* Note that a minimum distance is not enforced between the last value and
167  the previous one, contrary to what is done in ff_acelp_reorder_lsf() */
168  ff_set_min_dist_lsf(lsfnew, LSFQ_DIFF_MIN, LP_FILTER_ORDER - 1);
169  lsfnew[9] = FFMIN(lsfnew[LP_FILTER_ORDER - 1], 1.3 * M_PI);
170 
171  memcpy(lsf_history, lsf_tmp, LP_FILTER_ORDER * sizeof(*lsf_history));
172 
173  for (i = 0; i < LP_FILTER_ORDER - 1; i++)
174  lsfnew[i] = cos(lsfnew[i]);
175  lsfnew[LP_FILTER_ORDER - 1] *= 6.153848 / M_PI;
176 }
177 
179 static void pitch_sharpening(int pitch_lag_int, float beta,
180  float *fixed_vector)
181 {
182  int i;
183 
184  for (i = pitch_lag_int; i < SUBFR_SIZE; i++)
185  fixed_vector[i] += beta * fixed_vector[i - pitch_lag_int];
186 }
187 
194  const SiprModeParam *p)
195 {
196  int i, j;
197 
198  if (p->ma_predictor_bits)
199  parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits);
200 
201  for (i = 0; i < 5; i++)
202  parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]);
203 
204  for (i = 0; i < p->subframe_count; i++) {
205  parms->pitch_delay[i] = get_bits(pgb, p->pitch_delay_bits[i]);
206  if (p->gp_index_bits)
207  parms->gp_index[i] = get_bits(pgb, p->gp_index_bits);
208 
209  for (j = 0; j < p->number_of_fc_indexes; j++)
210  parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]);
211 
212  parms->gc_index[i] = get_bits(pgb, p->gc_index_bits);
213  }
214 }
215 
216 static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az,
217  int num_subfr)
218 {
219  double lsfint[LP_FILTER_ORDER];
220  int i,j;
221  float t, t0 = 1.0 / num_subfr;
222 
223  t = t0 * 0.5;
224  for (i = 0; i < num_subfr; i++) {
225  for (j = 0; j < LP_FILTER_ORDER; j++)
226  lsfint[j] = lsfold[j] * (1 - t) + t * lsfnew[j];
227 
228  ff_amrwb_lsp2lpc(lsfint, Az, LP_FILTER_ORDER);
229  Az += LP_FILTER_ORDER;
230  t += t0;
231  }
232 }
233 
237 static void eval_ir(const float *Az, int pitch_lag, float *freq,
238  float pitch_sharp_factor)
239 {
240  float tmp1[SUBFR_SIZE+1], tmp2[LP_FILTER_ORDER+1];
241  int i;
242 
243  tmp1[0] = 1.;
244  for (i = 0; i < LP_FILTER_ORDER; i++) {
245  tmp1[i+1] = Az[i] * ff_pow_0_55[i];
246  tmp2[i ] = Az[i] * ff_pow_0_7 [i];
247  }
248  memset(tmp1 + 11, 0, 37 * sizeof(float));
249 
250  ff_celp_lp_synthesis_filterf(freq, tmp2, tmp1, SUBFR_SIZE,
251  LP_FILTER_ORDER);
252 
253  pitch_sharpening(pitch_lag, pitch_sharp_factor, freq);
254 }
255 
259 static void convolute_with_sparse(float *out, const AMRFixed *pulses,
260  const float *shape, int length)
261 {
262  int i, j;
263 
264  memset(out, 0, length*sizeof(float));
265  for (i = 0; i < pulses->n; i++)
266  for (j = pulses->x[i]; j < length; j++)
267  out[j] += pulses->y[i] * shape[j - pulses->x[i]];
268 }
269 
273 static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples)
274 {
275  float buf[SUBFR_SIZE + LP_FILTER_ORDER];
276  float *pole_out = buf + LP_FILTER_ORDER;
277  float lpc_n[LP_FILTER_ORDER];
278  float lpc_d[LP_FILTER_ORDER];
279  int i;
280 
281  for (i = 0; i < LP_FILTER_ORDER; i++) {
282  lpc_d[i] = lpc[i] * ff_pow_0_75[i];
283  lpc_n[i] = lpc[i] * ff_pow_0_5 [i];
284  };
285 
286  memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem,
287  LP_FILTER_ORDER*sizeof(float));
288 
289  ff_celp_lp_synthesis_filterf(pole_out, lpc_d, samples, SUBFR_SIZE,
290  LP_FILTER_ORDER);
291 
292  memcpy(ctx->postfilter_mem, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
293  LP_FILTER_ORDER*sizeof(float));
294 
295  ff_tilt_compensation(&ctx->tilt_mem, 0.4, pole_out, SUBFR_SIZE);
296 
297  memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem5k0,
298  LP_FILTER_ORDER*sizeof(*pole_out));
299 
300  memcpy(ctx->postfilter_mem5k0, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
301  LP_FILTER_ORDER*sizeof(*pole_out));
302 
303  ff_celp_lp_zero_synthesis_filterf(samples, lpc_n, pole_out, SUBFR_SIZE,
304  LP_FILTER_ORDER);
305 
306 }
307 
308 static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses,
309  SiprMode mode, int low_gain)
310 {
311  int i;
312 
313  switch (mode) {
314  case MODE_6k5:
315  for (i = 0; i < 3; i++) {
316  fixed_sparse->x[i] = 3 * (pulses[i] & 0xf) + i;
317  fixed_sparse->y[i] = pulses[i] & 0x10 ? -1 : 1;
318  }
319  fixed_sparse->n = 3;
320  break;
321  case MODE_8k5:
322  for (i = 0; i < 3; i++) {
323  fixed_sparse->x[2*i ] = 3 * ((pulses[i] >> 4) & 0xf) + i;
324  fixed_sparse->x[2*i + 1] = 3 * ( pulses[i] & 0xf) + i;
325 
326  fixed_sparse->y[2*i ] = (pulses[i] & 0x100) ? -1.0: 1.0;
327 
328  fixed_sparse->y[2*i + 1] =
329  (fixed_sparse->x[2*i + 1] < fixed_sparse->x[2*i]) ?
330  -fixed_sparse->y[2*i ] : fixed_sparse->y[2*i];
331  }
332 
333  fixed_sparse->n = 6;
334  break;
335  case MODE_5k0:
336  default:
337  if (low_gain) {
338  int offset = (pulses[0] & 0x200) ? 2 : 0;
339  int val = pulses[0];
340 
341  for (i = 0; i < 3; i++) {
342  int index = (val & 0x7) * 6 + 4 - i*2;
343 
344  fixed_sparse->y[i] = (offset + index) & 0x3 ? -1 : 1;
345  fixed_sparse->x[i] = index;
346 
347  val >>= 3;
348  }
349  fixed_sparse->n = 3;
350  } else {
351  int pulse_subset = (pulses[0] >> 8) & 1;
352 
353  fixed_sparse->x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
354  fixed_sparse->x[1] = ( pulses[0] & 15) * 3 + pulse_subset + 1;
355 
356  fixed_sparse->y[0] = pulses[0] & 0x200 ? -1 : 1;
357  fixed_sparse->y[1] = -fixed_sparse->y[0];
358  fixed_sparse->n = 2;
359  }
360  break;
361  }
362 }
363 
364 static void decode_frame(SiprContext *ctx, SiprParameters *params,
365  float *out_data)
366 {
367  int i, j;
368  int subframe_count = modes[ctx->mode].subframe_count;
369  int frame_size = subframe_count * SUBFR_SIZE;
371  float *excitation;
372  float ir_buf[SUBFR_SIZE + LP_FILTER_ORDER];
373  float lsf_new[LP_FILTER_ORDER];
374  float *impulse_response = ir_buf + LP_FILTER_ORDER;
375  float *synth = ctx->synth_buf + 16; // 16 instead of LP_FILTER_ORDER for
376  // memory alignment
377  int t0_first = 0;
378  AMRFixed fixed_cb;
379 
380  memset(ir_buf, 0, LP_FILTER_ORDER * sizeof(float));
381  lsf_decode_fp(lsf_new, ctx->lsf_history, params);
382 
383  sipr_decode_lp(lsf_new, ctx->lsp_history, Az, subframe_count);
384 
385  memcpy(ctx->lsp_history, lsf_new, LP_FILTER_ORDER * sizeof(float));
386 
387  excitation = ctx->excitation + PITCH_DELAY_MAX + L_INTERPOL;
388 
389  for (i = 0; i < subframe_count; i++) {
390  float *pAz = Az + i*LP_FILTER_ORDER;
391  float fixed_vector[SUBFR_SIZE];
392  int T0,T0_frac;
393  float pitch_gain, gain_code, avg_energy;
394 
395  ff_decode_pitch_lag(&T0, &T0_frac, params->pitch_delay[i], t0_first, i,
396  ctx->mode == MODE_5k0, 6);
397 
398  if (i == 0 || (i == 2 && ctx->mode == MODE_5k0))
399  t0_first = T0;
400 
401  ff_acelp_interpolatef(excitation, excitation - T0 + (T0_frac <= 0),
402  ff_b60_sinc, 6,
403  2 * ((2 + T0_frac)%3 + 1), LP_FILTER_ORDER,
404  SUBFR_SIZE);
405 
406  decode_fixed_sparse(&fixed_cb, params->fc_indexes[i], ctx->mode,
407  ctx->past_pitch_gain < 0.8);
408 
409  eval_ir(pAz, T0, impulse_response, modes[ctx->mode].pitch_sharp_factor);
410 
411  convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
412  SUBFR_SIZE);
413 
414  avg_energy =
415  (0.01 + ff_scalarproduct_float_c(fixed_vector, fixed_vector, SUBFR_SIZE)) /
416  SUBFR_SIZE;
417 
418  ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
419 
420  gain_code = ff_amr_set_fixed_gain(gain_cb[params->gc_index[i]][1],
421  avg_energy, ctx->energy_history,
422  34 - 15.0/(0.05*M_LN10/M_LN2),
423  pred);
424 
425  ff_weighted_vector_sumf(excitation, excitation, fixed_vector,
426  pitch_gain, gain_code, SUBFR_SIZE);
427 
428  pitch_gain *= 0.5 * pitch_gain;
429  pitch_gain = FFMIN(pitch_gain, 0.4);
430 
431  ctx->gain_mem = 0.7 * ctx->gain_mem + 0.3 * pitch_gain;
432  ctx->gain_mem = FFMIN(ctx->gain_mem, pitch_gain);
433  gain_code *= ctx->gain_mem;
434 
435  for (j = 0; j < SUBFR_SIZE; j++)
436  fixed_vector[j] = excitation[j] - gain_code * fixed_vector[j];
437 
438  if (ctx->mode == MODE_5k0) {
439  postfilter_5k0(ctx, pAz, fixed_vector);
440 
441  ff_celp_lp_synthesis_filterf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
442  pAz, excitation, SUBFR_SIZE,
443  LP_FILTER_ORDER);
444  }
445 
446  ff_celp_lp_synthesis_filterf(synth + i*SUBFR_SIZE, pAz, fixed_vector,
447  SUBFR_SIZE, LP_FILTER_ORDER);
448 
449  excitation += SUBFR_SIZE;
450  }
451 
452  memcpy(synth - LP_FILTER_ORDER, synth + frame_size - LP_FILTER_ORDER,
453  LP_FILTER_ORDER * sizeof(float));
454 
455  if (ctx->mode == MODE_5k0) {
456  for (i = 0; i < subframe_count; i++) {
457  float energy = ff_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
458  ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
459  SUBFR_SIZE);
460  ff_adaptive_gain_control(&synth[i * SUBFR_SIZE],
461  &synth[i * SUBFR_SIZE], energy,
462  SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
463  }
464 
465  memcpy(ctx->postfilter_syn5k0, ctx->postfilter_syn5k0 + frame_size,
466  LP_FILTER_ORDER*sizeof(float));
467  }
468  memmove(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL,
469  (PITCH_DELAY_MAX + L_INTERPOL) * sizeof(float));
470 
472  (const float[2]) {-1.99997 , 1.000000000},
473  (const float[2]) {-1.93307352, 0.935891986},
474  0.939805806,
475  ctx->highpass_filt_mem,
476  frame_size);
477 }
478 
480 {
481  SiprContext *ctx = avctx->priv_data;
482  int i;
483 
484  switch (avctx->block_align) {
485  case 20: ctx->mode = MODE_16k; break;
486  case 19: ctx->mode = MODE_8k5; break;
487  case 29: ctx->mode = MODE_6k5; break;
488  case 37: ctx->mode = MODE_5k0; break;
489  default:
490  if (avctx->bit_rate > 12200) ctx->mode = MODE_16k;
491  else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5;
492  else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5;
493  else ctx->mode = MODE_5k0;
494  av_log(avctx, AV_LOG_WARNING,
495  "Invalid block_align: %d. Mode %s guessed based on bitrate: %d\n",
496  avctx->block_align, modes[ctx->mode].mode_name, avctx->bit_rate);
497  }
498 
499  av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name);
500 
501  if (ctx->mode == MODE_16k) {
502  ff_sipr_init_16k(ctx);
504  } else {
505  ctx->decode_frame = decode_frame;
506  }
507 
508  for (i = 0; i < LP_FILTER_ORDER; i++)
509  ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1));
510 
511  for (i = 0; i < 4; i++)
512  ctx->energy_history[i] = -14;
513 
514  avctx->channels = 1;
516  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
517 
519  avctx->coded_frame = &ctx->frame;
520 
521  return 0;
522 }
523 
524 static int sipr_decode_frame(AVCodecContext *avctx, void *data,
525  int *got_frame_ptr, AVPacket *avpkt)
526 {
527  SiprContext *ctx = avctx->priv_data;
528  const uint8_t *buf=avpkt->data;
529  SiprParameters parm;
530  const SiprModeParam *mode_par = &modes[ctx->mode];
531  GetBitContext gb;
532  float *samples;
533  int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE;
534  int i, ret;
535 
536  ctx->avctx = avctx;
537  if (avpkt->size < (mode_par->bits_per_frame >> 3)) {
538  av_log(avctx, AV_LOG_ERROR,
539  "Error processing packet: packet size (%d) too small\n",
540  avpkt->size);
541  return -1;
542  }
543 
544  /* get output buffer */
545  ctx->frame.nb_samples = mode_par->frames_per_packet * subframe_size *
546  mode_par->subframe_count;
547  if ((ret = ff_get_buffer(avctx, &ctx->frame)) < 0) {
548  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
549  return ret;
550  }
551  samples = (float *)ctx->frame.data[0];
552 
553  init_get_bits(&gb, buf, mode_par->bits_per_frame);
554 
555  for (i = 0; i < mode_par->frames_per_packet; i++) {
556  decode_parameters(&parm, &gb, mode_par);
557 
558  ctx->decode_frame(ctx, &parm, samples);
559 
560  samples += subframe_size * mode_par->subframe_count;
561  }
562 
563  *got_frame_ptr = 1;
564  *(AVFrame *)data = ctx->frame;
565 
566  return mode_par->bits_per_frame >> 3;
567 }
568 
570  .name = "sipr",
571  .type = AVMEDIA_TYPE_AUDIO,
572  .id = AV_CODEC_ID_SIPR,
573  .priv_data_size = sizeof(SiprContext),
576  .capabilities = CODEC_CAP_DR1,
577  .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"),
578 };
struct SiprContext SiprContext
int gp_index[5]
adaptive-codebook gain indexes
Definition: sipr.h:61
void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index, const int prev_lag_int, const int subframe, int third_as_first, int resolution)
Decode the adaptive codebook index to the integer and fractional parts of the pitch lag for one subfr...
int pitch_delay[5]
pitch delay
Definition: sipr.h:60
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
Definition: celp_filters.c:83
static int16_t * samples
int vq_indexes[5]
Definition: sipr.h:59
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
uint8_t gp_index_bits
Definition: sipr.c:64
uint8_t vq_indexes_bits[5]
size in bits of the i-th stage vector of quantizer
Definition: sipr.c:59
Definition: sipr.h:51
#define SUBFR_SIZE
Subframe size for all modes except 16k.
Definition: sipr.h:45
void ff_acelp_apply_order_2_transfer_function(float *out, const float *in, const float zero_coeffs[2], const float pole_coeffs[2], float gain, float mem[2], int n)
Apply an order 2 rational transfer function in-place.
static av_cold int sipr_decoder_init(AVCodecContext *avctx)
Definition: sipr.c:479
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:237
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.
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
static void lsf_decode_fp(float *lsfnew, float *lsf_history, const SiprParameters *parm)
Definition: sipr.c:153
int x[10]
Definition: acelp_vectors.h:31
int size
Definition: avcodec.h:916
#define SUBFRAME_COUNT_16k
Definition: sipr.h:47
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2960
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2141
float synth_buf[LP_FILTER_ORDER+5 *SUBFR_SIZE+6]
Definition: sipr.h:77
float postfilter_syn5k0[LP_FILTER_ORDER+SUBFR_SIZE *5]
Definition: sipr.h:89
uint8_t number_of_fc_indexes
Definition: sipr.c:55
#define LSFQ_DIFF_MIN
Definition: sipr.h:37
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
float lsf_history[LP_FILTER_ORDER_16k]
Definition: sipr.h:73
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2112
uint8_t
Sparse representation for the algebraic codebook (fixed) vector.
Definition: acelp_vectors.h:29
uint8_t fc_index_bits[10]
size in bits of the fixed codebook indexes
Definition: sipr.c:65
void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order)
LSP to LP conversion (5.2.4 of AMR-WB)
Definition: lsp.c:143
static const float gain_cb[128][2]
Definition: siprdata.h:213
SiprMode
Definition: sipr.h:49
#define PITCH_DELAY_MAX
#define L_INTERPOL
Number of past samples needed for excitation interpolation.
Definition: sipr.h:42
#define t0
Definition: regdef.h:28
const char data[16]
Definition: mxf.c:66
static void eval_ir(const float *Az, int pitch_lag, float *freq, float pitch_sharp_factor)
Evaluate the adaptive impulse response.
Definition: sipr.c:237
uint8_t * data
Definition: avcodec.h:915
Definition: sipr.h:50
float highpass_filt_mem[2]
Definition: sipr.h:82
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, int size, float alpha, float *gain_mem)
Adaptive gain control (as used in AMR postfiltering)
bitstream reader API header.
float pitch_sharp_factor
Definition: sipr.c:52
#define MAX_SUBFRAME_COUNT
Definition: sipr.c:42
static float t
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
uint8_t ma_predictor_bits
size in bits of the switched MA predictor
Definition: sipr.c:56
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
float lsp_history[LP_FILTER_ORDER]
Definition: sipr.h:79
uint16_t bits_per_frame
Definition: sipr.c:49
Definition: sipr.h:53
uint8_t pitch_delay_bits[5]
size in bits of the adaptive-codebook index for every subframe
Definition: sipr.c:62
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
AVCodecContext * avctx
Definition: sipr.h:67
const float ff_pow_0_7[10]
Table of pow(0.7,n)
Definition: acelp_vectors.c:78
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
float ff_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors.
Definition: dsputil.c:2418
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
const float ff_pow_0_75[10]
Table of pow(0.75,n)
Definition: acelp_vectors.c:83
#define LP_FILTER_ORDER
linear predictive coding filter order
Definition: amrnbdata.h:53
static void decode_parameters(SiprParameters *parms, GetBitContext *pgb, const SiprModeParam *p)
Extract decoding parameters from the input bitstream.
Definition: sipr.c:193
static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples)
Apply postfilter, very similar to AMR one.
Definition: sipr.c:273
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2165
Definition: sipr.h:52
int bit_rate
the average bitrate
Definition: avcodec.h:1404
audio channel layout utility functions
const char * mode_name
Definition: sipr.c:48
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
float y[10]
Definition: acelp_vectors.h:32
static void decode_frame(SiprContext *ctx, SiprParameters *params, float *out_data)
Definition: sipr.c:364
#define L_SUBFR_16k
Definition: sipr.h:33
int16_t fc_indexes[5][10]
fixed-codebook indexes
Definition: sipr.h:62
float energy_history[4]
Definition: sipr.h:81
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
Apply tilt compensation filter, 1 - tilt * z-1.
static const float pred[4]
Definition: siprdata.h:259
AVCodec ff_sipr_decoder
Definition: sipr.c:569
external API header
static const float * lsf_codebooks[]
Definition: siprdata.h:209
main external API structure.
Definition: avcodec.h:1339
uint8_t subframe_count
Definition: sipr.c:50
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:604
void(* decode_frame)(struct SiprContext *ctx, SiprParameters *params, float *out_data)
Definition: sipr.h:100
int index
Definition: gxfenc.c:72
float postfilter_mem5k0[PITCH_DELAY_MAX+LP_FILTER_ORDER]
Definition: sipr.h:88
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:372
void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP zero synthesis filter.
Definition: celp_filters.c:196
static void dequant(float *out, const int *idx, const float *cbs[])
Definition: sipr.c:142
static const float mean_lsf[10]
Definition: siprdata.h:27
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
float postfilter_mem[PITCH_DELAY_MAX+LP_FILTER_ORDER]
Definition: sipr.h:83
AVFrame frame
Definition: sipr.h:68
static int sipr_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: sipr.c:524
common internal api header.
int gc_index[5]
fixed-codebook gain indexes
Definition: sipr.h:63
static void pitch_sharpening(int pitch_lag_int, float beta, float *fixed_vector)
Apply pitch lag to the fixed vector (AMR section 6.1.2).
Definition: sipr.c:179
static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses, SiprMode mode, int low_gain)
Definition: sipr.c:308
float gain_mem
Definition: sipr.h:80
float excitation[L_INTERPOL+PITCH_MAX+2 *L_SUBFR_16k]
Definition: sipr.h:75
void ff_set_min_dist_lsf(float *lsf, double min_spacing, int size)
Adjust the quantized LSFs so they are increasing and not too close.
Definition: lsp.c:49
void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params, float *out_data)
Definition: sipr16k.c:176
void ff_sort_nearly_sorted_floats(float *vals, int len)
Sort values in ascending order.
Definition: lsp.c:220
float postfilter_agc
Definition: sipr.h:87
DSP utils.
static const SiprModeParam modes[MODE_COUNT]
Definition: sipr.c:69
uint8_t frames_per_packet
Definition: sipr.c:51
void * priv_data
Definition: avcodec.h:1382
const float ff_b60_sinc[61]
b60 hamming windowed sinc function coefficients
Definition: acelp_vectors.c:93
int channels
number of audio channels
Definition: avcodec.h:2105
const float ff_pow_0_5[]
Definition: sipr.c:135
void ff_acelp_interpolatef(float *out, const float *in, const float *filter_coeffs, int precision, int frac_pos, int filter_length, int length)
Floating point version of ff_acelp_interpolate()
Definition: acelp_filters.c:77
static const int8_t pulses[4]
Definition: g723_1_data.h:531
int ma_pred_switch
switched moving average predictor
Definition: sipr.h:58
float past_pitch_gain
Definition: sipr.h:72
SiprMode mode
Definition: sipr.h:70
#define AV_CH_LAYOUT_MONO
static void convolute_with_sparse(float *out, const AMRFixed *pulses, const float *shape, int length)
Evaluate the convolution of a vector with a sparse vector.
Definition: sipr.c:259
This structure stores compressed data.
Definition: avcodec.h:898
uint8_t gc_index_bits
size in bits of the gain codebook indexes
Definition: sipr.c:66
const float ff_pow_0_55[10]
Table of pow(0.55,n)
Definition: acelp_vectors.c:88
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1042
float tilt_mem
Definition: sipr.h:86
static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az, int num_subfr)
Definition: sipr.c:216
void ff_sipr_init_16k(SiprContext *ctx)
Definition: sipr16k.c:271
float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, float *prediction_error, float energy_mean, const float *pred_table)
Calculate fixed gain (part of section 6.1.3 of AMR spec)