Revision 9d10e6e6 libavcodec/ac3dec.c

View differences:

libavcodec/ac3dec.c
154 154
    int center_mix_level;                   ///< Center mix level index
155 155
    int surround_mix_level;                 ///< Surround mix level index
156 156
    float downmix_coeffs[AC3_MAX_CHANNELS][2];  ///< stereo downmix coefficients
157
    float downmix_coeff_sum[2];             ///< sum of downmix coeffs for each output channel
157 158
    float dynamic_range[2];                 ///< dynamic range
158 159
    int   cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates
159 160
    int   num_cpl_bands;                    ///< number of coupling bands
......
402 403
        int nf = s->channel_mode - 4;
403 404
        s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix;
404 405
    }
406

  
407
    s->downmix_coeff_sum[0] = s->downmix_coeff_sum[1] = 0.0f;
408
    for(i=0; i<s->fbw_channels; i++) {
409
        s->downmix_coeff_sum[0] += s->downmix_coeffs[i][0];
410
        s->downmix_coeff_sum[1] += s->downmix_coeffs[i][1];
411
    }
405 412
}
406 413

  
407 414
/**
......
732 739
static void ac3_downmix(AC3DecodeContext *s)
733 740
{
734 741
    int i, j;
735
    float v0, v1, s0, s1;
742
    float v0, v1;
736 743

  
737 744
    for(i=0; i<256; i++) {
738
        v0 = v1 = s0 = s1 = 0.0f;
745
        v0 = v1 = 0.0f;
739 746
        for(j=0; j<s->fbw_channels; j++) {
740 747
            v0 += s->output[j][i] * s->downmix_coeffs[j][0];
741 748
            v1 += s->output[j][i] * s->downmix_coeffs[j][1];
742
            s0 += s->downmix_coeffs[j][0];
743
            s1 += s->downmix_coeffs[j][1];
744 749
        }
745
        v0 /= s0;
746
        v1 /= s1;
750
        v0 /= s->downmix_coeff_sum[0];
751
        v1 /= s->downmix_coeff_sum[1];
747 752
        if(s->output_mode == AC3_CHMODE_MONO) {
748 753
            s->output[0][i] = (v0 + v1) * LEVEL_MINUS_3DB;
749 754
        } else if(s->output_mode == AC3_CHMODE_STEREO) {

Also available in: Unified diff