Libav
ra144enc.c
Go to the documentation of this file.
1 /*
2  * Real Audio 1.0 (14.4K) encoder
3  * Copyright (c) 2010 Francesco Lavra <francescolavra@interfree.it>
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
28 #include <float.h>
29 
30 #include "avcodec.h"
31 #include "audio_frame_queue.h"
32 #include "internal.h"
33 #include "put_bits.h"
34 #include "celp_filters.h"
35 #include "ra144.h"
36 
37 
39 {
40  RA144Context *ractx = avctx->priv_data;
41  ff_lpc_end(&ractx->lpc_ctx);
42  ff_af_queue_close(&ractx->afq);
43  return 0;
44 }
45 
46 
48 {
49  RA144Context *ractx;
50  int ret;
51 
52  if (avctx->channels != 1) {
53  av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
54  avctx->channels);
55  return -1;
56  }
57  avctx->frame_size = NBLOCKS * BLOCKSIZE;
58  avctx->delay = avctx->frame_size;
59  avctx->bit_rate = 8000;
60  ractx = avctx->priv_data;
61  ractx->lpc_coef[0] = ractx->lpc_tables[0];
62  ractx->lpc_coef[1] = ractx->lpc_tables[1];
63  ractx->avctx = avctx;
64  ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER,
66  if (ret < 0)
67  goto error;
68 
69  ff_af_queue_init(avctx, &ractx->afq);
70 
71  return 0;
72 error:
73  ra144_encode_close(avctx);
74  return ret;
75 }
76 
77 
88 static int quantize(int value, const int16_t *table, unsigned int size)
89 {
90  unsigned int low = 0, high = size - 1;
91 
92  while (1) {
93  int index = (low + high) >> 1;
94  int error = table[index] - value;
95 
96  if (index == low)
97  return table[high] + error > value ? low : high;
98  if (error > 0) {
99  high = index;
100  } else {
101  low = index;
102  }
103  }
104 }
105 
106 
113 static void orthogonalize(float *v, const float *u)
114 {
115  int i;
116  float num = 0, den = 0;
117 
118  for (i = 0; i < BLOCKSIZE; i++) {
119  num += v[i] * u[i];
120  den += u[i] * u[i];
121  }
122  num /= den;
123  for (i = 0; i < BLOCKSIZE; i++)
124  v[i] -= num * u[i];
125 }
126 
127 
141 static void get_match_score(float *work, const float *coefs, float *vect,
142  const float *ortho1, const float *ortho2,
143  const float *data, float *score, float *gain)
144 {
145  float c, g;
146  int i;
147 
148  ff_celp_lp_synthesis_filterf(work, coefs, vect, BLOCKSIZE, LPC_ORDER);
149  if (ortho1)
150  orthogonalize(work, ortho1);
151  if (ortho2)
152  orthogonalize(work, ortho2);
153  c = g = 0;
154  for (i = 0; i < BLOCKSIZE; i++) {
155  g += work[i] * work[i];
156  c += data[i] * work[i];
157  }
158  if (c <= 0) {
159  *score = 0;
160  return;
161  }
162  *gain = c / g;
163  *score = *gain * c;
164 }
165 
166 
174 static void create_adapt_vect(float *vect, const int16_t *cb, int lag)
175 {
176  int i;
177 
178  cb += BUFFERSIZE - lag;
179  for (i = 0; i < FFMIN(BLOCKSIZE, lag); i++)
180  vect[i] = cb[i];
181  if (lag < BLOCKSIZE)
182  for (i = 0; i < BLOCKSIZE - lag; i++)
183  vect[lag + i] = cb[i];
184 }
185 
186 
197 static int adaptive_cb_search(const int16_t *adapt_cb, float *work,
198  const float *coefs, float *data)
199 {
200  int i, best_vect;
201  float score, gain, best_score, best_gain;
202  float exc[BLOCKSIZE];
203 
204  gain = best_score = 0;
205  for (i = BLOCKSIZE / 2; i <= BUFFERSIZE; i++) {
206  create_adapt_vect(exc, adapt_cb, i);
207  get_match_score(work, coefs, exc, NULL, NULL, data, &score, &gain);
208  if (score > best_score) {
209  best_score = score;
210  best_vect = i;
211  best_gain = gain;
212  }
213  }
214  if (!best_score)
215  return 0;
216 
221  create_adapt_vect(exc, adapt_cb, best_vect);
223  for (i = 0; i < BLOCKSIZE; i++)
224  data[i] -= best_gain * work[i];
225  return best_vect - BLOCKSIZE / 2 + 1;
226 }
227 
228 
245 static void find_best_vect(float *work, const float *coefs,
246  const int8_t cb[][BLOCKSIZE], const float *ortho1,
247  const float *ortho2, float *data, int *idx,
248  float *gain)
249 {
250  int i, j;
251  float g, score, best_score;
252  float vect[BLOCKSIZE];
253 
254  *idx = *gain = best_score = 0;
255  for (i = 0; i < FIXED_CB_SIZE; i++) {
256  for (j = 0; j < BLOCKSIZE; j++)
257  vect[j] = cb[i][j];
258  get_match_score(work, coefs, vect, ortho1, ortho2, data, &score, &g);
259  if (score > best_score) {
260  best_score = score;
261  *idx = i;
262  *gain = g;
263  }
264  }
265 }
266 
267 
280 static void fixed_cb_search(float *work, const float *coefs, float *data,
281  int cba_idx, int *cb1_idx, int *cb2_idx)
282 {
283  int i, ortho_cb1;
284  float gain;
285  float cba_vect[BLOCKSIZE], cb1_vect[BLOCKSIZE];
286  float vect[BLOCKSIZE];
287 
292  if (cba_idx)
293  memcpy(cba_vect, work, sizeof(cba_vect));
294 
295  find_best_vect(work, coefs, ff_cb1_vects, cba_idx ? cba_vect : NULL, NULL,
296  data, cb1_idx, &gain);
297 
302  if (gain) {
303  for (i = 0; i < BLOCKSIZE; i++)
304  vect[i] = ff_cb1_vects[*cb1_idx][i];
305  ff_celp_lp_synthesis_filterf(work, coefs, vect, BLOCKSIZE, LPC_ORDER);
306  if (cba_idx)
307  orthogonalize(work, cba_vect);
308  for (i = 0; i < BLOCKSIZE; i++)
309  data[i] -= gain * work[i];
310  memcpy(cb1_vect, work, sizeof(cb1_vect));
311  ortho_cb1 = 1;
312  } else
313  ortho_cb1 = 0;
314 
315  find_best_vect(work, coefs, ff_cb2_vects, cba_idx ? cba_vect : NULL,
316  ortho_cb1 ? cb1_vect : NULL, data, cb2_idx, &gain);
317 }
318 
319 
330  const int16_t *sblock_data,
331  const int16_t *lpc_coefs, unsigned int rms,
332  PutBitContext *pb)
333 {
334  float data[BLOCKSIZE] = { 0 }, work[LPC_ORDER + BLOCKSIZE];
335  float coefs[LPC_ORDER];
336  float zero[BLOCKSIZE], cba[BLOCKSIZE], cb1[BLOCKSIZE], cb2[BLOCKSIZE];
337  int16_t cba_vect[BLOCKSIZE];
338  int cba_idx, cb1_idx, cb2_idx, gain;
339  int i, n, m[3];
340  float g[3];
341  float error, best_error;
342 
343  for (i = 0; i < LPC_ORDER; i++) {
344  work[i] = ractx->curr_sblock[BLOCKSIZE + i];
345  coefs[i] = lpc_coefs[i] * (1/4096.0);
346  }
347 
352  ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, data, BLOCKSIZE,
353  LPC_ORDER);
354  for (i = 0; i < BLOCKSIZE; i++) {
355  zero[i] = work[LPC_ORDER + i];
356  data[i] = sblock_data[i] - zero[i];
357  }
358 
364  memset(work, 0, LPC_ORDER * sizeof(*work));
365 
366  cba_idx = adaptive_cb_search(ractx->adapt_cb, work + LPC_ORDER, coefs,
367  data);
368  if (cba_idx) {
373  memcpy(cba, work + LPC_ORDER, sizeof(cba));
374 
375  ff_copy_and_dup(cba_vect, ractx->adapt_cb, cba_idx + BLOCKSIZE / 2 - 1);
376  m[0] = (ff_irms(cba_vect) * rms) >> 12;
377  }
378  fixed_cb_search(work + LPC_ORDER, coefs, data, cba_idx, &cb1_idx, &cb2_idx);
379  for (i = 0; i < BLOCKSIZE; i++) {
380  cb1[i] = ff_cb1_vects[cb1_idx][i];
381  cb2[i] = ff_cb2_vects[cb2_idx][i];
382  }
383  ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, cb1, BLOCKSIZE,
384  LPC_ORDER);
385  memcpy(cb1, work + LPC_ORDER, sizeof(cb1));
386  m[1] = (ff_cb1_base[cb1_idx] * rms) >> 8;
387  ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, cb2, BLOCKSIZE,
388  LPC_ORDER);
389  memcpy(cb2, work + LPC_ORDER, sizeof(cb2));
390  m[2] = (ff_cb2_base[cb2_idx] * rms) >> 8;
391  best_error = FLT_MAX;
392  gain = 0;
393  for (n = 0; n < 256; n++) {
394  g[1] = ((ff_gain_val_tab[n][1] * m[1]) >> ff_gain_exp_tab[n]) *
395  (1/4096.0);
396  g[2] = ((ff_gain_val_tab[n][2] * m[2]) >> ff_gain_exp_tab[n]) *
397  (1/4096.0);
398  error = 0;
399  if (cba_idx) {
400  g[0] = ((ff_gain_val_tab[n][0] * m[0]) >> ff_gain_exp_tab[n]) *
401  (1/4096.0);
402  for (i = 0; i < BLOCKSIZE; i++) {
403  data[i] = zero[i] + g[0] * cba[i] + g[1] * cb1[i] +
404  g[2] * cb2[i];
405  error += (data[i] - sblock_data[i]) *
406  (data[i] - sblock_data[i]);
407  }
408  } else {
409  for (i = 0; i < BLOCKSIZE; i++) {
410  data[i] = zero[i] + g[1] * cb1[i] + g[2] * cb2[i];
411  error += (data[i] - sblock_data[i]) *
412  (data[i] - sblock_data[i]);
413  }
414  }
415  if (error < best_error) {
416  best_error = error;
417  gain = n;
418  }
419  }
420  put_bits(pb, 7, cba_idx);
421  put_bits(pb, 8, gain);
422  put_bits(pb, 7, cb1_idx);
423  put_bits(pb, 7, cb2_idx);
424  ff_subblock_synthesis(ractx, lpc_coefs, cba_idx, cb1_idx, cb2_idx, rms,
425  gain);
426 }
427 
428 
429 static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
430  const AVFrame *frame, int *got_packet_ptr)
431 {
432  static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};
433  static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
434  RA144Context *ractx = avctx->priv_data;
435  PutBitContext pb;
436  int32_t lpc_data[NBLOCKS * BLOCKSIZE];
437  int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER];
438  int shift[LPC_ORDER];
439  int16_t block_coefs[NBLOCKS][LPC_ORDER];
440  int lpc_refl[LPC_ORDER];
441  unsigned int refl_rms[NBLOCKS];
442  const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
443  int energy = 0;
444  int i, idx, ret;
445 
446  if (ractx->last_frame)
447  return 0;
448 
449  if ((ret = ff_alloc_packet(avpkt, FRAMESIZE))) {
450  av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
451  return ret;
452  }
453 
461  for (i = 0; i < (2 * BLOCKSIZE + BLOCKSIZE / 2); i++) {
462  lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i];
463  energy += (lpc_data[i] * lpc_data[i]) >> 4;
464  }
465  if (frame) {
466  int j;
467  for (j = 0; j < frame->nb_samples && i < NBLOCKS * BLOCKSIZE; i++, j++) {
468  lpc_data[i] = samples[j] >> 2;
469  energy += (lpc_data[i] * lpc_data[i]) >> 4;
470  }
471  }
472  if (i < NBLOCKS * BLOCKSIZE)
473  memset(&lpc_data[i], 0, (NBLOCKS * BLOCKSIZE - i) * sizeof(*lpc_data));
474  energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab,
475  32)];
476 
477  ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,
478  LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON,
479  0, ORDER_METHOD_EST, 12, 0);
480  for (i = 0; i < LPC_ORDER; i++)
481  block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<
482  (12 - shift[LPC_ORDER - 1]));
483 
489  if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {
493  ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);
494  if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {
495  /* the filter is still unstable. set reflection coeffs to zero. */
496  memset(lpc_refl, 0, sizeof(lpc_refl));
497  }
498  }
499  init_put_bits(&pb, avpkt->data, avpkt->size);
500  for (i = 0; i < LPC_ORDER; i++) {
501  idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]);
502  put_bits(&pb, bit_sizes[i], idx);
503  lpc_refl[i] = ff_lpc_refl_cb[i][idx];
504  }
505  ractx->lpc_refl_rms[0] = ff_rms(lpc_refl);
506  ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);
507  refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy);
508  refl_rms[1] = ff_interp(ractx, block_coefs[1], 2,
509  energy <= ractx->old_energy,
510  ff_t_sqrt(energy * ractx->old_energy) >> 12);
511  refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy);
512  refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy);
513  ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]);
514  put_bits(&pb, 5, quantize(energy, ff_energy_tab, 32));
515  for (i = 0; i < NBLOCKS; i++)
516  ra144_encode_subblock(ractx, ractx->curr_block + i * BLOCKSIZE,
517  block_coefs[i], refl_rms[i], &pb);
518  flush_put_bits(&pb);
519  ractx->old_energy = energy;
520  ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];
521  FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
522 
523  /* copy input samples to current block for processing in next call */
524  i = 0;
525  if (frame) {
526  for (; i < frame->nb_samples; i++)
527  ractx->curr_block[i] = samples[i] >> 2;
528 
529  if ((ret = ff_af_queue_add(&ractx->afq, frame)) < 0)
530  return ret;
531  } else
532  ractx->last_frame = 1;
533  memset(&ractx->curr_block[i], 0,
534  (NBLOCKS * BLOCKSIZE - i) * sizeof(*ractx->curr_block));
535 
536  /* Get the next frame pts/duration */
537  ff_af_queue_remove(&ractx->afq, avctx->frame_size, &avpkt->pts,
538  &avpkt->duration);
539 
540  avpkt->size = FRAMESIZE;
541  *got_packet_ptr = 1;
542  return 0;
543 }
544 
545 
547  .name = "real_144",
548  .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
549  .type = AVMEDIA_TYPE_AUDIO,
550  .id = AV_CODEC_ID_RA_144,
551  .priv_data_size = sizeof(RA144Context),
553  .encode2 = ra144_encode_frame,
556  .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
558 };
unsigned int lpc_tables[2][10]
Definition: ra144.h:44
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
int size
int ff_t_sqrt(unsigned int x)
Evaluate sqrt(x << 24).
Definition: ra144.c:1618
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
const int16_t *const ff_lpc_refl_cb[10]
Definition: ra144.c:1502
static int adaptive_cb_search(const int16_t *adapt_cb, float *work, const float *coefs, float *data)
Search the adaptive codebook for the best entry and gain and remove its contribution from input data...
Definition: ra144enc.c:197
#define MAX_LPC_ORDER
Definition: lpc.h:35
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
Definition: lpc.c:169
static int quantize(int value, const int16_t *table, unsigned int size)
Quantize a value by searching a sorted table for the element with the nearest value.
Definition: ra144enc.c:88
int size
Definition: avcodec.h:974
static av_cold int ra144_encode_close(AVCodecContext *avctx)
Definition: ra144enc.c:38
static void orthogonalize(float *v, const float *u)
Orthogonalize a vector to another vector.
Definition: ra144enc.c:113
static int16_t * samples
Definition: output.c:53
uint16_t adapt_cb[146+2]
Adaptive codebook, its size is two units bigger to avoid a buffer overflow.
Definition: ra144.h:59
signed 16 bits
Definition: samplefmt.h:52
static void get_match_score(float *work, const float *coefs, float *vect, const float *ortho1, const float *ortho2, const float *data, float *score, float *gain)
Calculate match score and gain of an LPC-filtered vector with respect to input data, possibly othogonalizing it to up to 2 other vectors.
Definition: ra144enc.c:141
AVCodec.
Definition: avcodec.h:2755
AVCodec ff_ra_144_encoder
Definition: ra144enc.c:546
static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: ra144enc.c:429
#define NBLOCKS
number of subblocks within a block
Definition: ra144.h:29
uint8_t
#define av_cold
Definition: attributes.h:66
unsigned int lpc_refl_rms[2]
Definition: ra144.h:50
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
unsigned int ff_rms(const int *data)
Definition: ra144.c:1629
#define FIXED_CB_SIZE
size of fixed codebooks
Definition: ra144.h:32
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
const uint16_t ff_cb2_base[128]
Definition: ra144.c:1421
#define FRAMESIZE
size of encoded frame
Definition: ra144.h:33
void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs, int cba_idx, int cb1_idx, int cb2_idx, int gval, int gain)
Definition: ra144.c:1690
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:995
AVCodecContext * avctx
Definition: ra144.h:37
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
unsigned int * lpc_coef[2]
LPC coefficients: lpc_coef[0] is the coefficients of the current frame and lpc_coef[1] of the previou...
Definition: ra144.h:48
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:740
static const int sizes[][2]
Definition: img2dec.c:46
const int8_t ff_cb1_vects[128][40]
Definition: ra144.c:114
sample_fmts
Definition: avconv_filter.c:68
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:745
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
g
Definition: yuv2rgb.c:535
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:139
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
static void fixed_cb_search(float *work, const float *coefs, float *data, int cba_idx, int *cb1_idx, int *cb2_idx)
Search the two fixed codebooks for the best entry and gain.
Definition: ra144enc.c:280
AudioFrameQueue afq
Definition: ra144.h:39
int bit_rate
the average bitrate
Definition: avcodec.h:1112
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
Definition: lpc.c:284
#define FFMIN(a, b)
Definition: common.h:57
int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy)
Definition: ra144.c:1650
int32_t
void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset)
Copy the last offset values of *source to *target.
Definition: ra144.c:1530
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1125
int last_frame
Definition: ra144.h:40
void ff_int_to_int16(int16_t *out, const int *inp)
Definition: ra144.c:1606
const int16_t ff_gain_val_tab[256][3]
Definition: ra144.c:28
if(ac->has_optimized_func)
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1799
NULL
Definition: eval.c:55
#define BLOCKSIZE
subblock size in 16-bit words
Definition: ra144.h:30
void ff_eval_coefs(int *coefs, const int *refl)
Evaluate the LPC filter coefficients from the reflection coefficients.
Definition: ra144.c:1586
Libavcodec external API header.
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:68
main external API structure.
Definition: avcodec.h:1054
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
int ff_irms(const int16_t *data)
inverse root mean square
Definition: ra144.c:1677
static av_cold int ra144_encode_init(AVCodecContext *avctx)
Definition: ra144enc.c:47
Levinson-Durbin recursion.
Definition: lpc.h:44
#define ORDER_METHOD_EST
Definition: lpc.h:27
LPCContext lpc_ctx
Definition: ra144.h:38
int index
Definition: gxfenc.c:72
int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
Evaluate the reflection coefficients from the filter coefficients.
Definition: ra144.c:1545
#define BUFFERSIZE
the size of the adaptive codebook
Definition: ra144.h:31
unsigned int ff_rescale_rms(unsigned int rms, unsigned int energy)
Definition: ra144.c:1671
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
Definition: lpc.c:262
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
#define LPC_ORDER
Definition: g723_1_data.h:36
static void find_best_vect(float *work, const float *coefs, const int8_t cb[][BLOCKSIZE], const float *ortho1, const float *ortho2, float *data, int *idx, float *gain)
Find the best vector of a fixed codebook by applying an LPC filter to codebook entries, possibly othogonalizing them to up to 2 other vectors and matching the results with input data.
Definition: ra144enc.c:245
const int8_t ff_cb2_vects[128][40]
Definition: ra144.c:758
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:88
unsigned int old_energy
previous frame energy
Definition: ra144.h:42
const int16_t ff_energy_tab[32]
Definition: ra144.c:1440
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
const uint8_t ff_gain_exp_tab[256]
Definition: ra144.c:95
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:53
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:498
int16_t curr_sblock[50]
The current subblock padded by the last 10 values of the previous one.
Definition: ra144.h:55
void * priv_data
Definition: avcodec.h:1090
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int *duration)
Remove frame(s) from the queue.
int channels
number of audio channels
Definition: avcodec.h:1780
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
const uint16_t ff_cb1_base[128]
Definition: ra144.c:1402
int16_t curr_block[NBLOCKS *BLOCKSIZE]
Definition: ra144.h:52
#define FFSWAP(type, a, b)
Definition: common.h:60
static void create_adapt_vect(float *vect, const int16_t *cb, int lag)
Create a vector from the adaptive codebook at a given lag value.
Definition: ra144enc.c:174
This structure stores compressed data.
Definition: avcodec.h:950
int delay
Codec delay.
Definition: avcodec.h:1205
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:151
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
static void ra144_encode_subblock(RA144Context *ractx, const int16_t *sblock_data, const int16_t *lpc_coefs, unsigned int rms, PutBitContext *pb)
Encode a subblock of the current frame.
Definition: ra144enc.c:329
bitstream writer API