Revision dda3f0ef libavcodec/ac3enc.c

View differences:

libavcodec/ac3enc.c
33 33
#include "avcodec.h"
34 34
#include "put_bits.h"
35 35
#include "dsputil.h"
36
#include "ac3dsp.h"
36 37
#include "ac3.h"
37 38
#include "audioconvert.h"
38 39

  
......
86 87
typedef struct AC3EncodeContext {
87 88
    PutBitContext pb;                       ///< bitstream writer context
88 89
    DSPContext dsp;
90
    AC3DSPContext ac3dsp;                   ///< AC-3 optimized functions
89 91
    AC3MDCTContext mdct;                    ///< MDCT context
90 92

  
91 93
    AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
......
458 460
            exp_strategy[blk] = EXP_REUSE;
459 461
        exp += AC3_MAX_COEFS;
460 462
    }
461
    emms_c();
462 463

  
463 464
    /* now select the encoding strategy type : if exponents are often
464 465
       recoded, we use a coarse encoding */
......
499 500

  
500 501

  
501 502
/**
502
 * Set each encoded exponent in a block to the minimum of itself and the
503
 * exponents in the same frequency bin of up to 5 following blocks.
504
 */
505
static void exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
506
{
507
    int blk, i;
508

  
509
    if (!num_reuse_blocks)
510
        return;
511

  
512
    for (i = 0; i < nb_coefs; i++) {
513
        uint8_t min_exp = *exp;
514
        uint8_t *exp1 = exp + AC3_MAX_COEFS;
515
        for (blk = 0; blk < num_reuse_blocks; blk++) {
516
            uint8_t next_exp = *exp1;
517
            if (next_exp < min_exp)
518
                min_exp = next_exp;
519
            exp1 += AC3_MAX_COEFS;
520
        }
521
        *exp++ = min_exp;
522
    }
523
}
524

  
525

  
526
/**
527 503
 * Update the exponents so that they are the ones the decoder will decode.
528 504
 */
529 505
static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy)
......
616 592
            num_reuse_blocks = blk1 - blk - 1;
617 593

  
618 594
            /* for the EXP_REUSE case we select the min of the exponents */
619
            exponent_min(exp, num_reuse_blocks, nb_coefs);
595
            s->ac3dsp.ac3_exponent_min(exp, num_reuse_blocks, nb_coefs);
620 596

  
621 597
            encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
622 598

  
......
704 680
    encode_exponents(s);
705 681

  
706 682
    group_exponents(s);
683

  
684
    emms_c();
707 685
}
708 686

  
709 687

  
......
1856 1834
    avctx->coded_frame= avcodec_alloc_frame();
1857 1835

  
1858 1836
    dsputil_init(&s->dsp, avctx);
1837
    ff_ac3dsp_init(&s->ac3dsp);
1859 1838

  
1860 1839
    return 0;
1861 1840
init_fail:

Also available in: Unified diff