int 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[AC3_CRITICAL_BANDS]; /* excitation */
    int band;
    int band_start, band_end, begin, end1;
    int lowcomp, fastleak, slowleak;
    /* excitation function */
    band_start = ff_ac3_bin_to_band_tab[start];
    band_end   = ff_ac3_bin_to_band_tab[end-1] + 1;
    if (band_start == 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 (band = 2; band < 7; band++) {
            if (!(is_lfe && band == 6))
                lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);
            fastleak = band_psd[band] - fast_gain;
            slowleak = band_psd[band] - s->slow_gain;
            excite[band] = fastleak - lowcomp;
            if (!(is_lfe && band == 6)) {
                if (band_psd[band] <= band_psd[band+1]) {
                    begin = band + 1;
                    break;
                }
            }
        }
        end1 = FFMIN(band_end, 22);
        for (band = begin; band < end1; band++) {
            if (!(is_lfe && band == 6))
                lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);
            fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
            slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
            excite[band] = FFMAX(fastleak - lowcomp, slowleak);
        }
        begin = 22;
    } else {
        /* coupling channel */
        begin = band_start;
        fastleak = (s->cpl_fast_leak << 8) + 768;
        slowleak = (s->cpl_slow_leak << 8) + 768;
    }
    for (band = begin; band < band_end; band++) {
        fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
        slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
        excite[band] = FFMAX(fastleak, slowleak);
    }
    /* compute masking curve */
    for (band = band_start; band < band_end; band++) {
        int tmp = s->db_per_bit - band_psd[band];
        if (tmp > 0) {
            excite[band] += tmp >> 2;
        }
        mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]);
    }
    /* delta bit allocation */
    if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
        int i, seg, delta;
        if (dba_nsegs > 8)
            return -1;
        band = band_start;
        for (seg = 0; seg < dba_nsegs; seg++) {
            band += dba_offsets[seg];
            if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band)
                return -1;
            if (dba_values[seg] >= 4) {
                delta = (dba_values[seg] - 3) * 128;
            } else {
                delta = (dba_values[seg] - 4) * 128;
            }
            for (i = 0; i < dba_lengths[seg]; i++) {
                mask[band++] += delta;
            }
        }
    }
    return 0;
}
int 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[AC3_CRITICAL_BANDS]; 
    int band;
    int band_start, band_end, begin, end1;
    int lowcomp, fastleak, slowleak;
    
    band_start = ff_ac3_bin_to_band_tab[start];
    band_end   = ff_ac3_bin_to_band_tab[end-1] + 1;
    if (band_start == 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 (band = 2; band < 7; band++) {
            if (!(is_lfe && band == 6))
                lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);
            fastleak = band_psd[band] - fast_gain;
            slowleak = band_psd[band] - s->slow_gain;
            excite[band] = fastleak - lowcomp;
            if (!(is_lfe && band == 6)) {
                if (band_psd[band] <= band_psd[band+1]) {
                    begin = band + 1;
                    break;
                }
            }
        }
        end1 = FFMIN(band_end, 22);
        for (band = begin; band < end1; band++) {
            if (!(is_lfe && band == 6))
                lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);
            fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
            slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
            excite[band] = FFMAX(fastleak - lowcomp, slowleak);
        }
        begin = 22;
    } else {
        
        begin = band_start;
        fastleak = (s->cpl_fast_leak << 8) + 768;
        slowleak = (s->cpl_slow_leak << 8) + 768;
    }
    for (band = begin; band < band_end; band++) {
        fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
        slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
        excite[band] = FFMAX(fastleak, slowleak);
    }
    
    for (band = band_start; band < band_end; band++) {
        int tmp = s->db_per_bit - band_psd[band];
        if (tmp > 0) {
            excite[band] += tmp >> 2;
        }
        mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]);
    }
    
    if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
        int i, seg, delta;
        if (dba_nsegs > 8)
            return -1;
        band = band_start;
        for (seg = 0; seg < dba_nsegs; seg++) {
            band += dba_offsets[seg];
            if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band)
                return -1;
            if (dba_values[seg] >= 4) {
                delta = (dba_values[seg] - 3) * 128;
            } else {
                delta = (dba_values[seg] - 4) * 128;
            }
            for (i = 0; i < dba_lengths[seg]; i++) {
                mask[band++] += delta;
            }
        }
    }
    return 0;
}
int 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[AC3_CRITICAL_BANDS]; 
    int VAR_12;
    int VAR_13, VAR_14, VAR_15, VAR_16;
    int VAR_17, VAR_18, VAR_19;
    
    VAR_13 = ff_ac3_bin_to_band_tab[VAR_2];
    VAR_14   = ff_ac3_bin_to_band_tab[VAR_3-1] + 1;
    if (VAR_13 == 0) {
        VAR_17 = 0;
        VAR_17 = calc_lowcomp1(VAR_17, VAR_1[0], VAR_1[1], 384);
        excite[0] = VAR_1[0] - VAR_4 - VAR_17;
        VAR_17 = calc_lowcomp1(VAR_17, VAR_1[1], VAR_1[2], 384);
        excite[1] = VAR_1[1] - VAR_4 - VAR_17;
        VAR_15 = 7;
        for (VAR_12 = 2; VAR_12 < 7; VAR_12++) {
            if (!(VAR_5 && VAR_12 == 6))
                VAR_17 = calc_lowcomp1(VAR_17, VAR_1[VAR_12], VAR_1[VAR_12+1], 384);
            VAR_18 = VAR_1[VAR_12] - VAR_4;
            VAR_19 = VAR_1[VAR_12] - VAR_0->slow_gain;
            excite[VAR_12] = VAR_18 - VAR_17;
            if (!(VAR_5 && VAR_12 == 6)) {
                if (VAR_1[VAR_12] <= VAR_1[VAR_12+1]) {
                    VAR_15 = VAR_12 + 1;
                    break;
                }
            }
        }
        VAR_16 = FFMIN(VAR_14, 22);
        for (VAR_12 = VAR_15; VAR_12 < VAR_16; VAR_12++) {
            if (!(VAR_5 && VAR_12 == 6))
                VAR_17 = calc_lowcomp(VAR_17, VAR_1[VAR_12], VAR_1[VAR_12+1], VAR_12);
            VAR_18 = FFMAX(VAR_18 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4);
            VAR_19 = FFMAX(VAR_19 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain);
            excite[VAR_12] = FFMAX(VAR_18 - VAR_17, VAR_19);
        }
        VAR_15 = 22;
    } else {
        
        VAR_15 = VAR_13;
        VAR_18 = (VAR_0->cpl_fast_leak << 8) + 768;
        VAR_19 = (VAR_0->cpl_slow_leak << 8) + 768;
    }
    for (VAR_12 = VAR_15; VAR_12 < VAR_14; VAR_12++) {
        VAR_18 = FFMAX(VAR_18 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4);
        VAR_19 = FFMAX(VAR_19 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain);
        excite[VAR_12] = FFMAX(VAR_18, VAR_19);
    }
    
    for (VAR_12 = VAR_13; VAR_12 < VAR_14; VAR_12++) {
        int VAR_20 = VAR_0->db_per_bit - VAR_1[VAR_12];
        if (VAR_20 > 0) {
            excite[VAR_12] += VAR_20 >> 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_21, VAR_22, VAR_23;
        if (VAR_7 > 8)
            return -1;
        VAR_12 = VAR_13;
        for (VAR_22 = 0; VAR_22 < VAR_7; VAR_22++) {
            VAR_12 += VAR_8[VAR_22];
            if (VAR_12 >= AC3_CRITICAL_BANDS || VAR_9[VAR_22] > AC3_CRITICAL_BANDS-VAR_12)
                return -1;
            if (VAR_10[VAR_22] >= 4) {
                VAR_23 = (VAR_10[VAR_22] - 3) * 128;
            } else {
                VAR_23 = (VAR_10[VAR_22] - 4) * 128;
            }
            for (VAR_21 = 0; VAR_21 < VAR_9[VAR_22]; VAR_21++) {
                VAR_11[VAR_12++] += VAR_23;
            }
        }
    }
    return 0;
}
int 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[AC3_CRITICAL_BANDS]; int VAR_12; int VAR_13, VAR_14, VAR_15, VAR_16; int VAR_17, VAR_18, VAR_19; VAR_13 = ff_ac3_bin_to_band_tab[VAR_2]; VAR_14   = ff_ac3_bin_to_band_tab[VAR_3-1] + 1; if (VAR_13 == 0) { VAR_17 = 0; VAR_17 = calc_lowcomp1(VAR_17, VAR_1[0], VAR_1[1], 384); excite[0] = VAR_1[0] - VAR_4 - VAR_17; VAR_17 = calc_lowcomp1(VAR_17, VAR_1[1], VAR_1[2], 384); excite[1] = VAR_1[1] - VAR_4 - VAR_17; VAR_15 = 7; for (VAR_12 = 2; VAR_12 < 7; VAR_12++) { if (!(VAR_5 && VAR_12 == 6))
VAR_17 = calc_lowcomp1(VAR_17, VAR_1[VAR_12], VAR_1[VAR_12+1], 384); VAR_18 = VAR_1[VAR_12] - VAR_4; VAR_19 = VAR_1[VAR_12] - VAR_0->slow_gain; excite[VAR_12] = VAR_18 - VAR_17; if (!(VAR_5 && VAR_12 == 6)) { if (VAR_1[VAR_12] <= VAR_1[VAR_12+1]) { VAR_15 = VAR_12 + 1; break; } } } VAR_16 = FFMIN(VAR_14, 22); for (VAR_12 = VAR_15; VAR_12 < VAR_16; VAR_12++) { if (!(VAR_5 && VAR_12 == 6))
VAR_17 = calc_lowcomp(VAR_17, VAR_1[VAR_12], VAR_1[VAR_12+1], VAR_12); VAR_18 = FFMAX(VAR_18 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4); VAR_19 = FFMAX(VAR_19 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain); excite[VAR_12] = FFMAX(VAR_18 - VAR_17, VAR_19); } VAR_15 = 22; } else { VAR_15 = VAR_13; VAR_18 = (VAR_0->cpl_fast_leak << 8) + 768; VAR_19 = (VAR_0->cpl_slow_leak << 8) + 768; } for (VAR_12 = VAR_15; VAR_12 < VAR_14; VAR_12++) { VAR_18 = FFMAX(VAR_18 - VAR_0->fast_decay, VAR_1[VAR_12] - VAR_4); VAR_19 = FFMAX(VAR_19 - VAR_0->slow_decay, VAR_1[VAR_12] - VAR_0->slow_gain); excite[VAR_12] = FFMAX(VAR_18, VAR_19); } for (VAR_12 = VAR_13; VAR_12 < VAR_14; VAR_12++) { int VAR_20 = VAR_0->db_per_bit - VAR_1[VAR_12]; if (VAR_20 > 0) { excite[VAR_12] += VAR_20 >> 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_21, VAR_22, VAR_23; if (VAR_7 > 8)
return -1; VAR_12 = VAR_13; for (VAR_22 = 0; VAR_22 < VAR_7; VAR_22++) { VAR_12 += VAR_8[VAR_22]; if (VAR_12 >= AC3_CRITICAL_BANDS || VAR_9[VAR_22] > AC3_CRITICAL_BANDS-VAR_12)
return -1; if (VAR_10[VAR_22] >= 4) { VAR_23 = (VAR_10[VAR_22] - 3) * 128; } else { VAR_23 = (VAR_10[VAR_22] - 4) * 128; } for (VAR_21 = 0; VAR_21 < VAR_9[VAR_22]; VAR_21++) { VAR_11[VAR_12++] += VAR_23; } } } return 0; }