Revision 285bf28c

View differences:

libavcodec/ac3dec.c
456 456
    int l11ptr;
457 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 459
/* Get the transform coefficients for particular channel */
530 460
static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m)
531 461
{
532 462
    GetBitContext *gb = &ctx->gb;
533
    int i, gcode, tbap, dithflag, end;
463
    int i, gcode, tbap, dithflag, start, end;
534 464
    uint8_t *exps;
535 465
    uint8_t *bap;
536 466
    float *coeffs;
537 467

  
538
    if (ch_index != -1) { /* fbw channels */
468
    if (ch_index >= 0) { /* fbw channels */
539 469
        dithflag = ctx->dithflag[ch_index];
540 470
        exps = ctx->dexps[ch_index];
541 471
        bap = ctx->bap[ch_index];
542 472
        coeffs = ctx->transform_coeffs[ch_index + 1];
473
        start = 0;
543 474
        end = ctx->endmant[ch_index];
544 475
    } else if (ch_index == -1) {
545 476
        dithflag = 0;
546 477
        exps = ctx->dlfeexps;
547 478
        bap = ctx->lfebap;
548 479
        coeffs = ctx->transform_coeffs[0];
480
        start = 0;
549 481
        end = 7;
482
    } else {
483
        dithflag = 0;
484
        exps = ctx->dcplexps;
485
        bap = ctx->cplbap;
486
        coeffs = ctx->transform_coeffs_cpl;
487
        start = ctx->cplstrtmant;
488
        end = ctx->cplendmant;
550 489
    }
551 490

  
552 491

  
553
    for (i = 0; i < end; i++) {
492
    for (i = start; i < end; i++) {
554 493
        tbap = bap[i];
555 494
        switch (tbap) {
556 495
            case 0:
......
632 571
        /* tranform coefficients for coupling channels */
633 572
        if (ctx->chincpl[i])  {
634 573
            if (!got_cplchan) {
635
                if (get_transform_coeffs_cpling(ctx, &m)) {
574
                if (get_transform_coeffs_ch(ctx, -2, &m)) {
636 575
                    av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
637 576
                    return -1;
638 577
                }

Also available in: Unified diff