void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,

                                int start, int end, int fast_gain, int is_lfe,

                                int dba_mode, int dba_nsegs, uint8_t *dba_offsets,

                                uint8_t *dba_lengths, uint8_t *dba_values,

                                int16_t *mask)

{

    int16_t excite[50]; /* excitation */

    int bin, k;

    int bndstrt, bndend, begin, end1, tmp;

    int lowcomp, fastleak, slowleak;



    /* excitation function */

    bndstrt = bin_to_band_tab[start];

    bndend = bin_to_band_tab[end-1] + 1;



    if (bndstrt == 0) {

        lowcomp = 0;

        lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);

        excite[0] = band_psd[0] - fast_gain - lowcomp;

        lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);

        excite[1] = band_psd[1] - fast_gain - lowcomp;

        begin = 7;

        for (bin = 2; bin < 7; bin++) {

            if (!(is_lfe && bin == 6))

                lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);

            fastleak = band_psd[bin] - fast_gain;

            slowleak = band_psd[bin] - s->slow_gain;

            excite[bin] = fastleak - lowcomp;

            if (!(is_lfe && bin == 6)) {

                if (band_psd[bin] <= band_psd[bin+1]) {

                    begin = bin + 1;

                    break;

                }

            }

        }



        end1=bndend;

        if (end1 > 22) end1=22;



        for (bin = begin; bin < end1; bin++) {

            if (!(is_lfe && bin == 6))

                lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);



            fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);

            slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);

            excite[bin] = FFMAX(fastleak - lowcomp, slowleak);

        }

        begin = 22;

    } else {

        /* coupling channel */

        begin = bndstrt;



        fastleak = (s->cpl_fast_leak << 8) + 768;

        slowleak = (s->cpl_slow_leak << 8) + 768;

    }



    for (bin = begin; bin < bndend; bin++) {

        fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);

        slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);

        excite[bin] = FFMAX(fastleak, slowleak);

    }



    /* compute masking curve */



    for (bin = bndstrt; bin < bndend; bin++) {

        tmp = s->db_per_bit - band_psd[bin];

        if (tmp > 0) {

            excite[bin] += tmp >> 2;

        }

        mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);

    }



    /* delta bit allocation */



    if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {

        int band, seg, delta;

        band = 0;

        for (seg = 0; seg < FFMIN(8, dba_nsegs); seg++) {

            band = FFMIN(49, band + dba_offsets[seg]);

            if (dba_values[seg] >= 4) {

                delta = (dba_values[seg] - 3) << 7;

            } else {

                delta = (dba_values[seg] - 4) << 7;

            }

            for (k = 0; k < dba_lengths[seg]; k++) {

                mask[band] += delta;

                band++;

            }

        }

    }

}

void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,

                                int start, int end, int fast_gain, int is_lfe,

                                int dba_mode, int dba_nsegs, uint8_t *dba_offsets,

                                uint8_t *dba_lengths, uint8_t *dba_values,

                                int16_t *mask)

{

    int16_t excite[50]; 

    int bin, k;

    int bndstrt, bndend, begin, end1, tmp;

    int lowcomp, fastleak, slowleak;



    

    bndstrt = bin_to_band_tab[start];

    bndend = bin_to_band_tab[end-1] + 1;



    if (bndstrt == 0) {

        lowcomp = 0;

        lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);

        excite[0] = band_psd[0] - fast_gain - lowcomp;

        lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);

        excite[1] = band_psd[1] - fast_gain - lowcomp;

        begin = 7;

        for (bin = 2; bin < 7; bin++) {

            if (!(is_lfe && bin == 6))

                lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);

            fastleak = band_psd[bin] - fast_gain;

            slowleak = band_psd[bin] - s->slow_gain;

            excite[bin] = fastleak - lowcomp;

            if (!(is_lfe && bin == 6)) {

                if (band_psd[bin] <= band_psd[bin+1]) {

                    begin = bin + 1;

                    break;

                }

            }

        }



        end1=bndend;

        if (end1 > 22) end1=22;



        for (bin = begin; bin < end1; bin++) {

            if (!(is_lfe && bin == 6))

                lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);



            fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);

            slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);

            excite[bin] = FFMAX(fastleak - lowcomp, slowleak);

        }

        begin = 22;

    } else {

        

        begin = bndstrt;



        fastleak = (s->cpl_fast_leak << 8) + 768;

        slowleak = (s->cpl_slow_leak << 8) + 768;

    }



    for (bin = begin; bin < bndend; bin++) {

        fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);

        slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);

        excite[bin] = FFMAX(fastleak, slowleak);

    }



    



    for (bin = bndstrt; bin < bndend; bin++) {

        tmp = s->db_per_bit - band_psd[bin];

        if (tmp > 0) {

            excite[bin] += tmp >> 2;

        }

        mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);

    }



    



    if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {

        int band, seg, delta;

        band = 0;

        for (seg = 0; seg < FFMIN(8, dba_nsegs); seg++) {

            band = FFMIN(49, band + dba_offsets[seg]);

            if (dba_values[seg] >= 4) {

                delta = (dba_values[seg] - 3) << 7;

            } else {

                delta = (dba_values[seg] - 4) << 7;

            }

            for (k = 0; k < dba_lengths[seg]; k++) {

                mask[band] += delta;

                band++;

            }

        }

    }

}

void FUNC_0(AC3BitAllocParameters *VAR_0, int16_t *VAR_1,

                                int VAR_2, int VAR_3, int VAR_4, int VAR_5,

                                int VAR_6, int VAR_7, uint8_t *VAR_8,

                                uint8_t *VAR_9, uint8_t *VAR_10,

                                int16_t *VAR_11)

{

    int16_t excite[50]; 

    int VAR_12, VAR_13;

    int VAR_14, VAR_15, VAR_16, VAR_17, VAR_18;

    int VAR_19, VAR_20, VAR_21;



    

    VAR_14 = bin_to_band_tab[VAR_2];

    VAR_15 = bin_to_band_tab[VAR_3-1] + 1;



    if (VAR_14 == 0) {

        VAR_19 = 0;

        VAR_19 = calc_lowcomp1(VAR_19, VAR_1[0], VAR_1[1], 384);

        excite[0] = VAR_1[0] - VAR_4 - VAR_19;

        VAR_19 = calc_lowcomp1(VAR_19, VAR_1[1], VAR_1[2], 384);

        excite[1] = VAR_1[1] - VAR_4 - VAR_19;

        VAR_16 = 7;

        for (VAR_12 = 2; VAR_12 < 7; VAR_12++) {

            if (!(VAR_5 && VAR_12 == 6))

                VAR_19 = calc_lowcomp1(VAR_19, VAR_1[VAR_12], VAR_1[VAR_12+1], 384);

            VAR_20 = VAR_1[VAR_12] - VAR_4;

            VAR_21 = VAR_1[VAR_12] - VAR_0->slow_gain;

            excite[VAR_12] = VAR_20 - VAR_19;

            if (!(VAR_5 && VAR_12 == 6)) {

                if (VAR_1[VAR_12] <= VAR_1[VAR_12+1]) {

                    VAR_16 = VAR_12 + 1;

                    break;

                }

            }

        }



        VAR_17=VAR_15;

        if (VAR_17 > 22) VAR_17=22;



        for (VAR_12 = VAR_16; VAR_12 < VAR_17; VAR_12++) {

            if (!(VAR_5 && VAR_12 == 6))

                VAR_19 = calc_lowcomp(VAR_19, VAR_1[VAR_12], VAR_1[VAR_12+1], VAR_12);



            VAR_20 = FFMAX(VAR_20 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4);

            VAR_21 = FFMAX(VAR_21 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain);

            excite[VAR_12] = FFMAX(VAR_20 - VAR_19, VAR_21);

        }

        VAR_16 = 22;

    } else {

        

        VAR_16 = VAR_14;



        VAR_20 = (VAR_0->cpl_fast_leak << 8) + 768;

        VAR_21 = (VAR_0->cpl_slow_leak << 8) + 768;

    }



    for (VAR_12 = VAR_16; VAR_12 < VAR_15; VAR_12++) {

        VAR_20 = FFMAX(VAR_20 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4);

        VAR_21 = FFMAX(VAR_21 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain);

        excite[VAR_12] = FFMAX(VAR_20, VAR_21);

    }



    



    for (VAR_12 = VAR_14; VAR_12 < VAR_15; VAR_12++) {

        VAR_18 = VAR_0->db_per_bit - VAR_1[VAR_12];

        if (VAR_18 > 0) {

            excite[VAR_12] += VAR_18 >> 2;

        }

        VAR_11[VAR_12] = FFMAX(ff_ac3_hearing_threshold_tab[VAR_12 >> VAR_0->sr_shift][VAR_0->sr_code], excite[VAR_12]);

    }



    



    if (VAR_6 == DBA_REUSE || VAR_6 == DBA_NEW) {

        int VAR_22, VAR_23, VAR_24;

        VAR_22 = 0;

        for (VAR_23 = 0; VAR_23 < FFMIN(8, VAR_7); VAR_23++) {

            VAR_22 = FFMIN(49, VAR_22 + VAR_8[VAR_23]);

            if (VAR_10[VAR_23] >= 4) {

                VAR_24 = (VAR_10[VAR_23] - 3) << 7;

            } else {

                VAR_24 = (VAR_10[VAR_23] - 4) << 7;

            }

            for (VAR_13 = 0; VAR_13 < VAR_9[VAR_23]; VAR_13++) {

                VAR_11[VAR_22] += VAR_24;

                VAR_22++;

            }

        }

    }

}

void FUNC_0(AC3BitAllocParameters *VAR_0, int16_t *VAR_1,
int VAR_2, int VAR_3, int VAR_4, int VAR_5,
int VAR_6, int VAR_7, uint8_t *VAR_8,
uint8_t *VAR_9, uint8_t *VAR_10,
int16_t *VAR_11)
{ int16_t excite[50]; int VAR_12, VAR_13; int VAR_14, VAR_15, VAR_16, VAR_17, VAR_18; int VAR_19, VAR_20, VAR_21; VAR_14 = bin_to_band_tab[VAR_2]; VAR_15 = bin_to_band_tab[VAR_3-1] + 1; if (VAR_14 == 0) { VAR_19 = 0; VAR_19 = calc_lowcomp1(VAR_19, VAR_1[0], VAR_1[1], 384); excite[0] = VAR_1[0] - VAR_4 - VAR_19; VAR_19 = calc_lowcomp1(VAR_19, VAR_1[1], VAR_1[2], 384); excite[1] = VAR_1[1] - VAR_4 - VAR_19; VAR_16 = 7; for (VAR_12 = 2; VAR_12 < 7; VAR_12++) { if (!(VAR_5 && VAR_12 == 6))
VAR_19 = calc_lowcomp1(VAR_19, VAR_1[VAR_12], VAR_1[VAR_12+1], 384); VAR_20 = VAR_1[VAR_12] - VAR_4; VAR_21 = VAR_1[VAR_12] - VAR_0->slow_gain; excite[VAR_12] = VAR_20 - VAR_19; if (!(VAR_5 && VAR_12 == 6)) { if (VAR_1[VAR_12] <= VAR_1[VAR_12+1]) { VAR_16 = VAR_12 + 1; break; } } } VAR_17=VAR_15; if (VAR_17 > 22) VAR_17=22; for (VAR_12 = VAR_16; VAR_12 < VAR_17; VAR_12++) { if (!(VAR_5 && VAR_12 == 6))
VAR_19 = calc_lowcomp(VAR_19, VAR_1[VAR_12], VAR_1[VAR_12+1], VAR_12); VAR_20 = FFMAX(VAR_20 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4); VAR_21 = FFMAX(VAR_21 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain); excite[VAR_12] = FFMAX(VAR_20 - VAR_19, VAR_21); } VAR_16 = 22; } else { VAR_16 = VAR_14; VAR_20 = (VAR_0->cpl_fast_leak << 8) + 768; VAR_21 = (VAR_0->cpl_slow_leak << 8) + 768; } for (VAR_12 = VAR_16; VAR_12 < VAR_15; VAR_12++) { VAR_20 = FFMAX(VAR_20 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4); VAR_21 = FFMAX(VAR_21 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain); excite[VAR_12] = FFMAX(VAR_20, VAR_21); } for (VAR_12 = VAR_14; VAR_12 < VAR_15; VAR_12++) { VAR_18 = VAR_0->db_per_bit - VAR_1[VAR_12]; if (VAR_18 > 0) { excite[VAR_12] += VAR_18 >> 2; } VAR_11[VAR_12] = FFMAX(ff_ac3_hearing_threshold_tab[VAR_12 >> VAR_0->sr_shift][VAR_0->sr_code], excite[VAR_12]); } if (VAR_6 == DBA_REUSE || VAR_6 == DBA_NEW) { int VAR_22, VAR_23, VAR_24; VAR_22 = 0; for (VAR_23 = 0; VAR_23 < FFMIN(8, VAR_7); VAR_23++) { VAR_22 = FFMIN(49, VAR_22 + VAR_8[VAR_23]); if (VAR_10[VAR_23] >= 4) { VAR_24 = (VAR_10[VAR_23] - 3) << 7; } else { VAR_24 = (VAR_10[VAR_23] - 4) << 7; } for (VAR_13 = 0; VAR_13 < VAR_9[VAR_23]; VAR_13++) { VAR_11[VAR_22] += VAR_24; VAR_22++; } } } }