Mercurial > libavcodec.hg
comparison ra144.c @ 7005:6e374f47da64 libavcodec
Remove *lpc_refl from the context. Only the value
calculated in rms() is actually needed. It also avoid
recalculating it later.
author | vitor |
---|---|
date | Thu, 05 Jun 2008 16:15:44 +0000 |
parents | 5bad976fae7b |
children | e943e1409077 |
comparison
equal
deleted
inserted
replaced
7004:5bad976fae7b | 7005:6e374f47da64 |
---|---|
32 /* internal globals */ | 32 /* internal globals */ |
33 typedef struct { | 33 typedef struct { |
34 unsigned int old_energy; ///< previous frame energy | 34 unsigned int old_energy; ///< previous frame energy |
35 | 35 |
36 /* the swapped buffers */ | 36 /* the swapped buffers */ |
37 unsigned int lpc_tables[4][10]; | 37 unsigned int lpc_tables[2][10]; |
38 unsigned int *lpc_refl; ///< LPC reflection coefficients | |
39 unsigned int *lpc_coef; ///< LPC coefficients | 38 unsigned int *lpc_coef; ///< LPC coefficients |
40 unsigned int *lpc_refl_old; ///< previous frame LPC reflection coefs | |
41 unsigned int *lpc_coef_old; ///< previous frame LPC coefficients | 39 unsigned int *lpc_coef_old; ///< previous frame LPC coefficients |
40 unsigned int lpc_refl_rms; | |
41 unsigned int lpc_refl_rms_old; | |
42 | 42 |
43 unsigned int buffer[5]; | 43 unsigned int buffer[5]; |
44 uint16_t adapt_cb[148]; ///< adaptive codebook | 44 uint16_t adapt_cb[148]; ///< adaptive codebook |
45 } RA144Context; | 45 } RA144Context; |
46 | 46 |
47 static int ra144_decode_init(AVCodecContext * avctx) | 47 static int ra144_decode_init(AVCodecContext * avctx) |
48 { | 48 { |
49 RA144Context *ractx = avctx->priv_data; | 49 RA144Context *ractx = avctx->priv_data; |
50 | 50 |
51 ractx->lpc_refl = ractx->lpc_tables[0]; | 51 ractx->lpc_coef = ractx->lpc_tables[0]; |
52 ractx->lpc_coef = ractx->lpc_tables[1]; | 52 ractx->lpc_coef_old = ractx->lpc_tables[1]; |
53 ractx->lpc_refl_old = ractx->lpc_tables[2]; | |
54 ractx->lpc_coef_old = ractx->lpc_tables[3]; | |
55 | 53 |
56 return 0; | 54 return 0; |
57 } | 55 } |
58 | 56 |
59 /** | 57 /** |
316 if (eval_refl(decsp, work, ractx)) { | 314 if (eval_refl(decsp, work, ractx)) { |
317 // The interpolated coefficients are unstable, copy either new or old | 315 // The interpolated coefficients are unstable, copy either new or old |
318 // coefficients | 316 // coefficients |
319 if (copynew) { | 317 if (copynew) { |
320 int_to_int16(decsp, ractx->lpc_coef); | 318 int_to_int16(decsp, ractx->lpc_coef); |
321 return rescale_rms(rms(ractx->lpc_refl), energy); | 319 return rescale_rms(ractx->lpc_refl_rms, energy); |
322 } else { | 320 } else { |
323 int_to_int16(decsp, ractx->lpc_coef_old); | 321 int_to_int16(decsp, ractx->lpc_coef_old); |
324 return rescale_rms(rms(ractx->lpc_refl_old), energy); | 322 return rescale_rms(ractx->lpc_refl_rms_old, energy); |
325 } | 323 } |
326 } else { | 324 } else { |
327 return rescale_rms(rms(work), energy); | 325 return rescale_rms(rms(work), energy); |
328 } | 326 } |
329 } | 327 } |
334 const uint8_t * buf, int buf_size) | 332 const uint8_t * buf, int buf_size) |
335 { | 333 { |
336 static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; | 334 static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; |
337 unsigned int refl_rms[4]; // RMS of the reflection coefficients | 335 unsigned int refl_rms[4]; // RMS of the reflection coefficients |
338 uint16_t block_coefs[4][30]; // LPC coefficients of each sub-block | 336 uint16_t block_coefs[4][30]; // LPC coefficients of each sub-block |
337 unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame | |
339 int i, c; | 338 int i, c; |
340 int16_t *data = vdata; | 339 int16_t *data = vdata; |
341 unsigned int energy; | 340 unsigned int energy; |
342 | 341 |
343 RA144Context *ractx = avctx->priv_data; | 342 RA144Context *ractx = avctx->priv_data; |
350 } | 349 } |
351 init_get_bits(&gb, buf, 20 * 8); | 350 init_get_bits(&gb, buf, 20 * 8); |
352 | 351 |
353 for (i=0; i<10; i++) | 352 for (i=0; i<10; i++) |
354 // "<< 1"? Doesn't this make one value out of two of the table useless? | 353 // "<< 1"? Doesn't this make one value out of two of the table useless? |
355 ractx->lpc_refl[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1]; | 354 lpc_refl[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1]; |
356 | 355 |
357 eval_coefs(ractx->lpc_refl, ractx->lpc_coef); | 356 eval_coefs(lpc_refl, ractx->lpc_coef); |
357 ractx->lpc_refl_rms = rms(lpc_refl); | |
358 | 358 |
359 energy = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries? | 359 energy = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries? |
360 | 360 |
361 refl_rms[0] = interp(ractx, block_coefs[0], 0, 0, ractx->old_energy); | 361 refl_rms[0] = interp(ractx, block_coefs[0], 0, 0, ractx->old_energy); |
362 refl_rms[1] = interp(ractx, block_coefs[1], 1, energy > ractx->old_energy, | 362 refl_rms[1] = interp(ractx, block_coefs[1], 1, energy > ractx->old_energy, |
363 t_sqrt(energy*ractx->old_energy) >> 12); | 363 t_sqrt(energy*ractx->old_energy) >> 12); |
364 refl_rms[2] = interp(ractx, block_coefs[2], 2, 1, energy); | 364 refl_rms[2] = interp(ractx, block_coefs[2], 2, 1, energy); |
365 refl_rms[3] = rescale_rms(rms(ractx->lpc_refl), energy); | 365 refl_rms[3] = rescale_rms(ractx->lpc_refl_rms, energy); |
366 | 366 |
367 int_to_int16(block_coefs[3], ractx->lpc_coef); | 367 int_to_int16(block_coefs[3], ractx->lpc_coef); |
368 | 368 |
369 /* do output */ | 369 /* do output */ |
370 for (c=0; c<4; c++) { | 370 for (c=0; c<4; c++) { |
375 data++; | 375 data++; |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 ractx->old_energy = energy; | 379 ractx->old_energy = energy; |
380 | 380 ractx->lpc_refl_rms_old = ractx->lpc_refl_rms; |
381 FFSWAP(unsigned int *, ractx->lpc_refl_old, ractx->lpc_refl); | 381 |
382 FFSWAP(unsigned int *, ractx->lpc_coef_old, ractx->lpc_coef); | 382 FFSWAP(unsigned int *, ractx->lpc_coef_old, ractx->lpc_coef); |
383 | 383 |
384 *data_size = 2*160; | 384 *data_size = 2*160; |
385 return 20; | 385 return 20; |
386 } | 386 } |