comparison ac3dec.c @ 5452:190d793a22e7 libavcodec

merge decoding of coupling channel coefficients and regular channel coefficients
author jbr
date Sat, 04 Aug 2007 00:04:17 +0000
parents 19bb5e64a57c
children d3a265cd395c
comparison
equal deleted inserted replaced
5451:19bb5e64a57c 5452:190d793a22e7
454 int l3ptr; 454 int l3ptr;
455 int l5ptr; 455 int l5ptr;
456 int l11ptr; 456 int l11ptr;
457 } mant_groups; 457 } mant_groups;
458 458
459 /* Get the transform coefficients for coupling channel and uncouple channels.
460 * The coupling transform coefficients starts at the the cplstrtmant, which is
461 * equal to endmant[ch] for fbw channels. Hence we can uncouple channels before
462 * getting transform coefficients for the channel.
463 */
464 static int get_transform_coeffs_cpling(AC3DecodeContext *ctx, mant_groups *m)
465 {
466 GetBitContext *gb = &ctx->gb;
467 int start, gcode, tbap;
468 float cplcoeff;
469 uint8_t *exps = ctx->dcplexps;
470 uint8_t *bap = ctx->cplbap;
471 start = ctx->cplstrtmant;
472
473 while (start < ctx->cplendmant) {
474 tbap = bap[start];
475 switch(tbap) {
476 case 0:
477 cplcoeff = (av_random(&ctx->dith_state) & 0xFFFF);
478 break;
479 case 1:
480 if (m->l3ptr > 2) {
481 gcode = get_bits(gb, 5);
482 m->l3_quantizers[0] = l3_quantizers_1[gcode];
483 m->l3_quantizers[1] = l3_quantizers_2[gcode];
484 m->l3_quantizers[2] = l3_quantizers_3[gcode];
485 m->l3ptr = 0;
486 }
487 cplcoeff = m->l3_quantizers[m->l3ptr++];
488 break;
489
490 case 2:
491 if (m->l5ptr > 2) {
492 gcode = get_bits(gb, 7);
493 m->l5_quantizers[0] = l5_quantizers_1[gcode];
494 m->l5_quantizers[1] = l5_quantizers_2[gcode];
495 m->l5_quantizers[2] = l5_quantizers_3[gcode];
496 m->l5ptr = 0;
497 }
498 cplcoeff = m->l5_quantizers[m->l5ptr++];
499 break;
500
501 case 3:
502 cplcoeff = l7_quantizers[get_bits(gb, 3)];
503 break;
504
505 case 4:
506 if (m->l11ptr > 1) {
507 gcode = get_bits(gb, 7);
508 m->l11_quantizers[0] = l11_quantizers_1[gcode];
509 m->l11_quantizers[1] = l11_quantizers_2[gcode];
510 m->l11ptr = 0;
511 }
512 cplcoeff = m->l11_quantizers[m->l11ptr++];
513 break;
514
515 case 5:
516 cplcoeff = l15_quantizers[get_bits(gb, 4)];
517 break;
518
519 default:
520 cplcoeff = get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap]);
521 }
522 ctx->transform_coeffs_cpl[start] = cplcoeff * scale_factors[exps[start]];
523 start++;
524 }
525
526 return 0;
527 }
528
529 /* Get the transform coefficients for particular channel */ 459 /* Get the transform coefficients for particular channel */
530 static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m) 460 static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m)
531 { 461 {
532 GetBitContext *gb = &ctx->gb; 462 GetBitContext *gb = &ctx->gb;
533 int i, gcode, tbap, dithflag, end; 463 int i, gcode, tbap, dithflag, start, end;
534 uint8_t *exps; 464 uint8_t *exps;
535 uint8_t *bap; 465 uint8_t *bap;
536 float *coeffs; 466 float *coeffs;
537 467
538 if (ch_index != -1) { /* fbw channels */ 468 if (ch_index >= 0) { /* fbw channels */
539 dithflag = ctx->dithflag[ch_index]; 469 dithflag = ctx->dithflag[ch_index];
540 exps = ctx->dexps[ch_index]; 470 exps = ctx->dexps[ch_index];
541 bap = ctx->bap[ch_index]; 471 bap = ctx->bap[ch_index];
542 coeffs = ctx->transform_coeffs[ch_index + 1]; 472 coeffs = ctx->transform_coeffs[ch_index + 1];
473 start = 0;
543 end = ctx->endmant[ch_index]; 474 end = ctx->endmant[ch_index];
544 } else if (ch_index == -1) { 475 } else if (ch_index == -1) {
545 dithflag = 0; 476 dithflag = 0;
546 exps = ctx->dlfeexps; 477 exps = ctx->dlfeexps;
547 bap = ctx->lfebap; 478 bap = ctx->lfebap;
548 coeffs = ctx->transform_coeffs[0]; 479 coeffs = ctx->transform_coeffs[0];
480 start = 0;
549 end = 7; 481 end = 7;
550 } 482 } else {
551 483 dithflag = 0;
552 484 exps = ctx->dcplexps;
553 for (i = 0; i < end; i++) { 485 bap = ctx->cplbap;
486 coeffs = ctx->transform_coeffs_cpl;
487 start = ctx->cplstrtmant;
488 end = ctx->cplendmant;
489 }
490
491
492 for (i = start; i < end; i++) {
554 tbap = bap[i]; 493 tbap = bap[i];
555 switch (tbap) { 494 switch (tbap) {
556 case 0: 495 case 0:
557 if (!dithflag) { 496 if (!dithflag) {
558 coeffs[i] = 0; 497 coeffs[i] = 0;
630 if (get_transform_coeffs_ch(ctx, i, &m)) 569 if (get_transform_coeffs_ch(ctx, i, &m))
631 return -1; 570 return -1;
632 /* tranform coefficients for coupling channels */ 571 /* tranform coefficients for coupling channels */
633 if (ctx->chincpl[i]) { 572 if (ctx->chincpl[i]) {
634 if (!got_cplchan) { 573 if (!got_cplchan) {
635 if (get_transform_coeffs_cpling(ctx, &m)) { 574 if (get_transform_coeffs_ch(ctx, -2, &m)) {
636 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n"); 575 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
637 return -1; 576 return -1;
638 } 577 }
639 uncouple_channels(ctx); 578 uncouple_channels(ctx);
640 got_cplchan = 1; 579 got_cplchan = 1;