Revision e86ea34d

View differences:

libavcodec/ac3enc.c
76 76
    int16_t  **band_psd;                        ///< psd per critical band
77 77
    int16_t  **mask;                            ///< masking curve
78 78
    uint16_t **qmant;                           ///< quantized mantissas
79
    uint8_t  num_exp_groups[AC3_MAX_CHANNELS];  ///< number of exponent groups
80 79
    uint8_t  exp_strategy[AC3_MAX_CHANNELS];    ///< exponent strategies
81 80
    int8_t   exp_shift[AC3_MAX_CHANNELS];       ///< exponent shift values
82 81
} AC3Block;
......
151 150
static int16_t xcos1[128];
152 151
static int16_t xsin1[128];
153 152

  
153
/**
154
 * LUT for number of exponent groups.
155
 * exponent_group_tab[exponent strategy-1][number of coefficients]
156
 */
157
uint8_t exponent_group_tab[3][256];
158

  
154 159

  
155 160
/**
156 161
 * Adjust the frame size to make the average bit rate match the target bit rate.
......
484 489

  
485 490

  
486 491
/**
492
 * Initialize exponent tables.
493
 */
494
static av_cold void exponent_init(AC3EncodeContext *s)
495
{
496
    int i;
497
    for (i = 73; i < 256; i++) {
498
        exponent_group_tab[0][i] = (i - 1) /  3;
499
        exponent_group_tab[1][i] = (i + 2) /  6;
500
        exponent_group_tab[2][i] = (i + 8) / 12;
501
    }
502
}
503

  
504

  
505
/**
487 506
 * Extract exponents from the MDCT coefficients.
488 507
 * This takes into account the normalization that was done to the input samples
489 508
 * by adjusting the exponents by the exponent shift values.
......
607 626
 * Update the exponents so that they are the ones the decoder will decode.
608 627
 */
609 628
static void encode_exponents_blk_ch(uint8_t *exp,
610
                                    int nb_exps, int exp_strategy,
611
                                    uint8_t *num_exp_groups)
629
                                    int nb_exps, int exp_strategy)
612 630
{
613
    int group_size, nb_groups, i, k;
631
    int nb_groups, i, k;
614 632

  
615
    group_size = exp_strategy + (exp_strategy == EXP_D45);
616
    *num_exp_groups = (nb_exps + (group_size * 3) - 4) / (3 * group_size);
617
    nb_groups = *num_exp_groups * 3;
633
    nb_groups = exponent_group_tab[exp_strategy-1][nb_exps] * 3;
618 634

  
619 635
    /* for each group, compute the minimum exponent */
620 636
    switch(exp_strategy) {
......
697 713
                block1++;
698 714
            }
699 715
            encode_exponents_blk_ch(block->exp[ch], s->nb_coefs[ch],
700
                                    block->exp_strategy[ch],
701
                                    &block->num_exp_groups[ch]);
716
                                    block->exp_strategy[ch]);
702 717
            /* copy encoded exponents for reuse case */
703 718
            block2 = block + 1;
704 719
            for (blk2 = blk+1; blk2 < blk1; blk2++, block2++) {
......
720 735
static void group_exponents(AC3EncodeContext *s)
721 736
{
722 737
    int blk, ch, i;
723
    int group_size, bit_count;
738
    int group_size, nb_groups, bit_count;
724 739
    uint8_t *p;
725 740
    int delta0, delta1, delta2;
726 741
    int exp0, exp1;
......
730 745
        AC3Block *block = &s->blocks[blk];
731 746
        for (ch = 0; ch < s->channels; ch++) {
732 747
            if (block->exp_strategy[ch] == EXP_REUSE) {
733
                block->num_exp_groups[ch] = 0;
734 748
                continue;
735 749
            }
736 750
            group_size = block->exp_strategy[ch] + (block->exp_strategy[ch] == EXP_D45);
737
            bit_count += 4 + (block->num_exp_groups[ch] * 7);
751
            nb_groups = exponent_group_tab[block->exp_strategy[ch]-1][s->nb_coefs[ch]];
752
            bit_count += 4 + (nb_groups * 7);
738 753
            p = block->exp[ch];
739 754

  
740 755
            /* DC exponent */
......
742 757
            block->grouped_exp[ch][0] = exp1;
743 758

  
744 759
            /* remaining exponents are delta encoded */
745
            for (i = 1; i <= block->num_exp_groups[ch]; i++) {
760
            for (i = 1; i <= nb_groups; i++) {
746 761
                /* merge three delta in one code */
747 762
                exp0   = exp1;
748 763
                exp1   = p[0];
......
1317 1332

  
1318 1333
    /* exponents */
1319 1334
    for (ch = 0; ch < s->channels; ch++) {
1335
        int nb_groups;
1336

  
1320 1337
        if (block->exp_strategy[ch] == EXP_REUSE)
1321 1338
            continue;
1322 1339

  
......
1324 1341
        put_bits(&s->pb, 4, block->grouped_exp[ch][0]);
1325 1342

  
1326 1343
        /* exponent groups */
1327
        for (i = 1; i <= block->num_exp_groups[ch]; i++)
1344
        nb_groups = exponent_group_tab[block->exp_strategy[ch]-1][s->nb_coefs[ch]];
1345
        for (i = 1; i <= nb_groups; i++)
1328 1346
            put_bits(&s->pb, 7, block->grouped_exp[ch][i]);
1329 1347

  
1330 1348
        /* gain range info */
......
1757 1775

  
1758 1776
    set_bandwidth(s, avctx->cutoff);
1759 1777

  
1778
    exponent_init(s);
1779

  
1760 1780
    bit_alloc_init(s);
1761 1781

  
1762 1782
    s->mdct.avctx = avctx;

Also available in: Unified diff