Revision d7da8080 libavcodec/ac3enc.c

View differences:

libavcodec/ac3enc.c
485 485
/**
486 486
 * Calculate exponent strategies for all blocks in a single channel.
487 487
 */
488
static void compute_exp_strategy_ch(uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
489
                                    uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
490
                                    int ch, int is_lfe)
488
static void compute_exp_strategy_ch(uint8_t *exp_strategy, uint8_t **exp)
491 489
{
492 490
    int blk, blk1;
493 491
    int exp_diff;
494 492

  
495 493
    /* estimate if the exponent variation & decide if they should be
496 494
       reused in the next frame */
497
    exp_strategy[0][ch] = EXP_NEW;
495
    exp_strategy[0] = EXP_NEW;
498 496
    for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) {
499
        exp_diff = calc_exp_diff(exp[blk][ch], exp[blk-1][ch], AC3_MAX_COEFS);
497
        exp_diff = calc_exp_diff(exp[blk], exp[blk-1], AC3_MAX_COEFS);
500 498
        if (exp_diff > EXP_DIFF_THRESHOLD)
501
            exp_strategy[blk][ch] = EXP_NEW;
499
            exp_strategy[blk] = EXP_NEW;
502 500
        else
503
            exp_strategy[blk][ch] = EXP_REUSE;
501
            exp_strategy[blk] = EXP_REUSE;
504 502
    }
505
    if (is_lfe)
506
        return;
507 503

  
508 504
    /* now select the encoding strategy type : if exponents are often
509 505
       recoded, we use a coarse encoding */
510 506
    blk = 0;
511 507
    while (blk < AC3_MAX_BLOCKS) {
512 508
        blk1 = blk + 1;
513
        while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1][ch] == EXP_REUSE)
509
        while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
514 510
            blk1++;
515 511
        switch (blk1 - blk) {
516
        case 1:  exp_strategy[blk][ch] = EXP_D45; break;
512
        case 1:  exp_strategy[blk] = EXP_D45; break;
517 513
        case 2:
518
        case 3:  exp_strategy[blk][ch] = EXP_D25; break;
519
        default: exp_strategy[blk][ch] = EXP_D15; break;
514
        case 3:  exp_strategy[blk] = EXP_D25; break;
515
        default: exp_strategy[blk] = EXP_D15; break;
520 516
        }
521 517
        blk = blk1;
522 518
    }
......
525 521

  
526 522
/**
527 523
 * Calculate exponent strategies for all channels.
524
 * Array arrangement is reversed to simplify the per-channel calculation.
528 525
 */
529 526
static void compute_exp_strategy(AC3EncodeContext *s,
530 527
                                 uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
531 528
                                 uint8_t exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS])
532 529
{
533
    int ch;
530
    uint8_t *exp1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
531
    uint8_t exp_str1[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS];
532
    int ch, blk;
534 533

  
535
    for (ch = 0; ch < s->channels; ch++) {
536
        compute_exp_strategy_ch(exp_strategy, exp, ch, ch == s->lfe_channel);
534
    for (ch = 0; ch < s->fbw_channels; ch++) {
535
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
536
            exp1[ch][blk]     = exp[blk][ch];
537
            exp_str1[ch][blk] = exp_strategy[blk][ch];
538
        }
539

  
540
        compute_exp_strategy_ch(exp_str1[ch], exp1[ch]);
541

  
542
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
543
            exp_strategy[blk][ch] = exp_str1[ch][blk];
544
    }
545
    if (s->lfe_on) {
546
        ch = s->lfe_channel;
547
        exp_strategy[0][ch] = EXP_D15;
548
        for (blk = 1; blk < 5; blk++)
549
            exp_strategy[blk][ch] = EXP_REUSE;
537 550
    }
538 551
}
539 552

  

Also available in: Unified diff