comparison ra144.c @ 7128:614bc53e67a8 libavcodec

Use lpc_coef[2] instead of lpc_coef and lpc_coef_old
author vitor
date Tue, 24 Jun 2008 18:38:55 +0000
parents 8ab2d77fd502
children 22788bf6502a
comparison
equal deleted inserted replaced
7127:8ab2d77fd502 7128:614bc53e67a8
30 30
31 typedef struct { 31 typedef struct {
32 unsigned int old_energy; ///< previous frame energy 32 unsigned int old_energy; ///< previous frame energy
33 33
34 unsigned int lpc_tables[2][10]; 34 unsigned int lpc_tables[2][10];
35 unsigned int *lpc_coef; ///< LPC coefficients 35
36 unsigned int *lpc_coef_old; ///< previous frame LPC coefficients 36 /** LPC coefficients: lpc_coef[0] is the coefficients of the current frame
37 unsigned int lpc_refl_rms; 37 * and lpc_coef[1] of the previous one */
38 unsigned int lpc_refl_rms_old; 38 unsigned int *lpc_coef[2];
39
40 unsigned int lpc_refl_rms[2];
39 41
40 /** the current subblock padded by the last 10 values of the previous one*/ 42 /** the current subblock padded by the last 10 values of the previous one*/
41 int16_t curr_sblock[50]; 43 int16_t curr_sblock[50];
42 44
43 /** adaptive codebook. Its size is two units bigger to avoid a 45 /** adaptive codebook. Its size is two units bigger to avoid a
47 49
48 static int ra144_decode_init(AVCodecContext * avctx) 50 static int ra144_decode_init(AVCodecContext * avctx)
49 { 51 {
50 RA144Context *ractx = avctx->priv_data; 52 RA144Context *ractx = avctx->priv_data;
51 53
52 ractx->lpc_coef = ractx->lpc_tables[0]; 54 ractx->lpc_coef[0] = ractx->lpc_tables[0];
53 ractx->lpc_coef_old = ractx->lpc_tables[1]; 55 ractx->lpc_coef[1] = ractx->lpc_tables[1];
54 56
55 return 0; 57 return 0;
56 } 58 }
57 59
58 /** 60 /**
308 int x; 310 int x;
309 311
310 // Interpolate block coefficients from the this frame forth block and 312 // Interpolate block coefficients from the this frame forth block and
311 // last frame forth block 313 // last frame forth block
312 for (x=0; x<30; x++) 314 for (x=0; x<30; x++)
313 out[x] = (a * ractx->lpc_coef[x] + b * ractx->lpc_coef_old[x])>> 2; 315 out[x] = (a * ractx->lpc_coef[0][x] + b * ractx->lpc_coef[1][x])>> 2;
314 316
315 if (eval_refl(work, out, ractx)) { 317 if (eval_refl(work, out, ractx)) {
316 // The interpolated coefficients are unstable, copy either new or old 318 // The interpolated coefficients are unstable, copy either new or old
317 // coefficients 319 // coefficients
318 if (copynew) { 320 if (copynew) {
319 int_to_int16(out, ractx->lpc_coef); 321 int_to_int16(out, ractx->lpc_coef[0]);
320 return rescale_rms(ractx->lpc_refl_rms, energy); 322 return rescale_rms(ractx->lpc_refl_rms[0], energy);
321 } else { 323 } else {
322 int_to_int16(out, ractx->lpc_coef_old); 324 int_to_int16(out, ractx->lpc_coef[1]);
323 return rescale_rms(ractx->lpc_refl_rms_old, energy); 325 return rescale_rms(ractx->lpc_refl_rms[1], energy);
324 } 326 }
325 } else { 327 } else {
326 return rescale_rms(rms(work), energy); 328 return rescale_rms(rms(work), energy);
327 } 329 }
328 } 330 }
352 init_get_bits(&gb, buf, 20 * 8); 354 init_get_bits(&gb, buf, 20 * 8);
353 355
354 for (i=0; i<10; i++) 356 for (i=0; i<10; i++)
355 lpc_refl[i] = lpc_refl_cb[i][get_bits(&gb, sizes[i])]; 357 lpc_refl[i] = lpc_refl_cb[i][get_bits(&gb, sizes[i])];
356 358
357 eval_coefs(ractx->lpc_coef, lpc_refl); 359 eval_coefs(ractx->lpc_coef[0], lpc_refl);
358 ractx->lpc_refl_rms = rms(lpc_refl); 360 ractx->lpc_refl_rms[0] = rms(lpc_refl);
359 361
360 energy = energy_tab[get_bits(&gb, 5)]; 362 energy = energy_tab[get_bits(&gb, 5)];
361 363
362 refl_rms[0] = interp(ractx, block_coefs[0], 0, 0, ractx->old_energy); 364 refl_rms[0] = interp(ractx, block_coefs[0], 0, 0, ractx->old_energy);
363 refl_rms[1] = interp(ractx, block_coefs[1], 1, energy > ractx->old_energy, 365 refl_rms[1] = interp(ractx, block_coefs[1], 1, energy > ractx->old_energy,
364 t_sqrt(energy*ractx->old_energy) >> 12); 366 t_sqrt(energy*ractx->old_energy) >> 12);
365 refl_rms[2] = interp(ractx, block_coefs[2], 2, 1, energy); 367 refl_rms[2] = interp(ractx, block_coefs[2], 2, 1, energy);
366 refl_rms[3] = rescale_rms(ractx->lpc_refl_rms, energy); 368 refl_rms[3] = rescale_rms(ractx->lpc_refl_rms[0], energy);
367 369
368 int_to_int16(block_coefs[3], ractx->lpc_coef); 370 int_to_int16(block_coefs[3], ractx->lpc_coef[0]);
369 371
370 for (c=0; c<4; c++) { 372 for (c=0; c<4; c++) {
371 do_output_subblock(ractx, block_coefs[c], refl_rms[c], &gb); 373 do_output_subblock(ractx, block_coefs[c], refl_rms[c], &gb);
372 374
373 for (i=0; i<BLOCKSIZE; i++) 375 for (i=0; i<BLOCKSIZE; i++)
374 *data++ = av_clip_int16(ractx->curr_sblock[i + 10] << 2); 376 *data++ = av_clip_int16(ractx->curr_sblock[i + 10] << 2);
375 } 377 }
376 378
377 ractx->old_energy = energy; 379 ractx->old_energy = energy;
378 ractx->lpc_refl_rms_old = ractx->lpc_refl_rms; 380 ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];
379 381
380 FFSWAP(unsigned int *, ractx->lpc_coef_old, ractx->lpc_coef); 382 FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
381 383
382 *data_size = 2*160; 384 *data_size = 2*160;
383 return 20; 385 return 20;
384 } 386 }
385 387