Revision 0429e4a6 libavcodec/ac3enc.c

View differences:

libavcodec/ac3enc.c
75 75
    int16_t  **band_psd;                        ///< psd per critical band
76 76
    int16_t  **mask;                            ///< masking curve
77 77
    uint16_t **qmant;                           ///< quantized mantissas
78
    uint8_t  exp_strategy[AC3_MAX_CHANNELS];    ///< exponent strategies
79 78
    int8_t   exp_shift[AC3_MAX_CHANNELS];       ///< exponent shift values
80 79
    uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
81 80
    uint8_t  rematrixing_flags[4];              ///< rematrixing flags
......
147 146
    int16_t *mask_buffer;
148 147
    uint16_t *qmant_buffer;
149 148

  
149
    uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies
150

  
150 151
    DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE];
151 152
} AC3EncodeContext;
152 153

  
......
488 489
    for (ch = 0; ch < s->fbw_channels; ch++) {
489 490
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
490 491
            exp1[ch][blk]     = s->blocks[blk].exp[ch];
491
            exp_str1[ch][blk] = s->blocks[blk].exp_strategy[ch];
492
            exp_str1[ch][blk] = s->exp_strategy[ch][blk];
492 493
        }
493 494

  
494 495
        compute_exp_strategy_ch(s, exp_str1[ch], exp1[ch]);
495 496

  
496 497
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
497
            s->blocks[blk].exp_strategy[ch] = exp_str1[ch][blk];
498
            s->exp_strategy[ch][blk] = exp_str1[ch][blk];
498 499
    }
499 500
    if (s->lfe_on) {
500 501
        ch = s->lfe_channel;
501
        s->blocks[0].exp_strategy[ch] = EXP_D15;
502
        s->exp_strategy[ch][0] = EXP_D15;
502 503
        for (blk = 1; blk < AC3_MAX_BLOCKS; blk++)
503
            s->blocks[blk].exp_strategy[ch] = EXP_REUSE;
504
            s->exp_strategy[ch][blk] = EXP_REUSE;
504 505
    }
505 506
}
506 507

  
......
604 605
            blk1 = blk + 1;
605 606
            block1 = block + 1;
606 607
            /* for the EXP_REUSE case we select the min of the exponents */
607
            while (blk1 < AC3_MAX_BLOCKS && block1->exp_strategy[ch] == EXP_REUSE) {
608
            while (blk1 < AC3_MAX_BLOCKS && s->exp_strategy[ch][blk1] == EXP_REUSE) {
608 609
                exponent_min(block->exp[ch], block1->exp[ch], s->nb_coefs[ch]);
609 610
                blk1++;
610 611
                block1++;
611 612
            }
612 613
            encode_exponents_blk_ch(block->exp[ch], s->nb_coefs[ch],
613
                                    block->exp_strategy[ch]);
614
                                    s->exp_strategy[ch][blk]);
614 615
            /* copy encoded exponents for reuse case */
615 616
            block2 = block + 1;
616 617
            for (blk2 = blk+1; blk2 < blk1; blk2++, block2++) {
......
641 642
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
642 643
        AC3Block *block = &s->blocks[blk];
643 644
        for (ch = 0; ch < s->channels; ch++) {
644
            if (block->exp_strategy[ch] == EXP_REUSE) {
645
            if (s->exp_strategy[ch][blk] == EXP_REUSE) {
645 646
                continue;
646 647
            }
647
            group_size = block->exp_strategy[ch] + (block->exp_strategy[ch] == EXP_D45);
648
            nb_groups = exponent_group_tab[block->exp_strategy[ch]-1][s->nb_coefs[ch]];
648
            group_size = s->exp_strategy[ch][blk] + (s->exp_strategy[ch][blk] == EXP_D45);
649
            nb_groups = exponent_group_tab[s->exp_strategy[ch][blk]-1][s->nb_coefs[ch]];
649 650
            bit_count += 4 + (nb_groups * 7);
650 651
            p = block->exp[ch];
651 652

  
......
795 796
    int frame_bits = 0;
796 797

  
797 798
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
798
        uint8_t *exp_strategy = s->blocks[blk].exp_strategy;
799

  
800 799
        /* stereo rematrixing */
801 800
        if (s->channel_mode == AC3_CHMODE_STEREO &&
802 801
            s->blocks[blk].new_rematrixing_strategy) {
......
804 803
        }
805 804

  
806 805
        for (ch = 0; ch < s->fbw_channels; ch++) {
807
            if (exp_strategy[ch] != EXP_REUSE)
806
            if (s->exp_strategy[ch][blk] != EXP_REUSE)
808 807
                frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
809 808
        }
810 809
    }
......
867 866
            /* We only need psd and mask for calculating bap.
868 867
               Since we currently do not calculate bap when exponent
869 868
               strategy is EXP_REUSE we do not need to calculate psd or mask. */
870
            if (block->exp_strategy[ch] != EXP_REUSE) {
869
            if (s->exp_strategy[ch][blk] != EXP_REUSE) {
871 870
                ff_ac3_bit_alloc_calc_psd(block->exp[ch], 0,
872 871
                                          s->nb_coefs[ch],
873 872
                                          block->psd[ch], block->band_psd[ch]);
......
930 929
               blocks within a frame are the exponent values.  We can take
931 930
               advantage of that by reusing the bit allocation pointers
932 931
               whenever we reuse exponents. */
933
            if (block->exp_strategy[ch] == EXP_REUSE) {
932
            if (s->exp_strategy[ch][blk] == EXP_REUSE) {
934 933
                memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS);
935 934
            } else {
936 935
                ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
......
1006 1005

  
1007 1006
    for (ch = 0; ch < s->fbw_channels; ch++) {
1008 1007
        for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) {
1009
            if (s->blocks[blk].exp_strategy[ch] == EXP_D15) {
1010
                s->blocks[blk].exp_strategy[ch] = EXP_D25;
1008
            if (s->exp_strategy[ch][blk] == EXP_D15) {
1009
                s->exp_strategy[ch][blk] = EXP_D25;
1011 1010
                return 0;
1012 1011
            }
1013 1012
        }
1014 1013
    }
1015 1014
    for (ch = 0; ch < s->fbw_channels; ch++) {
1016 1015
        for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) {
1017
            if (s->blocks[blk].exp_strategy[ch] == EXP_D25) {
1018
                s->blocks[blk].exp_strategy[ch] = EXP_D45;
1016
            if (s->exp_strategy[ch][blk] == EXP_D25) {
1017
                s->exp_strategy[ch][blk] = EXP_D45;
1019 1018
                return 0;
1020 1019
            }
1021 1020
        }
......
1024 1023
        /* block 0 cannot reuse exponents, so only downgrade D45 to REUSE if
1025 1024
           the block number > 0 */
1026 1025
        for (blk = AC3_MAX_BLOCKS-1; blk > 0; blk--) {
1027
            if (s->blocks[blk].exp_strategy[ch] > EXP_REUSE) {
1028
                s->blocks[blk].exp_strategy[ch] = EXP_REUSE;
1026
            if (s->exp_strategy[ch][blk] > EXP_REUSE) {
1027
                s->exp_strategy[ch][blk] = EXP_REUSE;
1029 1028
                return 0;
1030 1029
            }
1031 1030
        }
......
1326 1325

  
1327 1326
    /* exponent strategy */
1328 1327
    for (ch = 0; ch < s->fbw_channels; ch++)
1329
        put_bits(&s->pb, 2, block->exp_strategy[ch]);
1328
        put_bits(&s->pb, 2, s->exp_strategy[ch][block_num]);
1330 1329
    if (s->lfe_on)
1331
        put_bits(&s->pb, 1, block->exp_strategy[s->lfe_channel]);
1330
        put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][block_num]);
1332 1331

  
1333 1332
    /* bandwidth */
1334 1333
    for (ch = 0; ch < s->fbw_channels; ch++) {
1335
        if (block->exp_strategy[ch] != EXP_REUSE)
1334
        if (s->exp_strategy[ch][block_num] != EXP_REUSE)
1336 1335
            put_bits(&s->pb, 6, s->bandwidth_code[ch]);
1337 1336
    }
1338 1337

  
......
1340 1339
    for (ch = 0; ch < s->channels; ch++) {
1341 1340
        int nb_groups;
1342 1341

  
1343
        if (block->exp_strategy[ch] == EXP_REUSE)
1342
        if (s->exp_strategy[ch][block_num] == EXP_REUSE)
1344 1343
            continue;
1345 1344

  
1346 1345
        /* DC exponent */
1347 1346
        put_bits(&s->pb, 4, block->grouped_exp[ch][0]);
1348 1347

  
1349 1348
        /* exponent groups */
1350
        nb_groups = exponent_group_tab[block->exp_strategy[ch]-1][s->nb_coefs[ch]];
1349
        nb_groups = exponent_group_tab[s->exp_strategy[ch][block_num]-1][s->nb_coefs[ch]];
1351 1350
        for (i = 1; i <= nb_groups; i++)
1352 1351
            put_bits(&s->pb, 7, block->grouped_exp[ch][i]);
1353 1352

  

Also available in: Unified diff