static void search_for_ms(AACEncContext *s, ChannelElement *cpe)

{

    int start = 0, i, w, w2, g, sid_sf_boost;

    float M[128], S[128];

    float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;

    const float lambda = s->lambda;

    const float mslambda = FFMIN(1.0f, lambda / 120.f);

    SingleChannelElement *sce0 = &cpe->ch[0];

    SingleChannelElement *sce1 = &cpe->ch[1];

    if (!cpe->common_window)

        return;

    for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {

        int min_sf_idx_mid = SCALE_MAX_POS;

        int min_sf_idx_side = SCALE_MAX_POS;

        for (g = 0; g < sce0->ics.num_swb; g++) {

            if (!sce0->zeroes[w*16+g] && sce0->band_type[w*16+g] < RESERVED_BT)

                min_sf_idx_mid = FFMIN(min_sf_idx_mid, sce0->sf_idx[w*16+g]);

            if (!sce1->zeroes[w*16+g] && sce1->band_type[w*16+g] < RESERVED_BT)

                min_sf_idx_side = FFMIN(min_sf_idx_side, sce1->sf_idx[w*16+g]);

        }



        start = 0;

        for (g = 0;  g < sce0->ics.num_swb; g++) {

            float bmax = bval2bmax(g * 17.0f / sce0->ics.num_swb) / 0.0045f;

            cpe->ms_mask[w*16+g] = 0;

            if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {

                float Mmax = 0.0f, Smax = 0.0f;



                /* Must compute mid/side SF and book for the whole window group */

                for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {

                    for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {

                        M[i] = (sce0->coeffs[start+(w+w2)*128+i]

                              + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;

                        S[i] =  M[i]

                              - sce1->coeffs[start+(w+w2)*128+i];

                    }

                    abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);

                    abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);

                    for (i = 0; i < sce0->ics.swb_sizes[g]; i++ ) {

                        Mmax = FFMAX(Mmax, M34[i]);

                        Smax = FFMAX(Smax, S34[i]);

                    }

                }



                for (sid_sf_boost = 0; sid_sf_boost < 4; sid_sf_boost++) {

                    float dist1 = 0.0f, dist2 = 0.0f;

                    int B0 = 0, B1 = 0;

                    int minidx;

                    int mididx, sididx;

                    int midcb, sidcb;



                    minidx = FFMIN(sce0->sf_idx[w*16+g], sce1->sf_idx[w*16+g]);

                    mididx = av_clip(minidx, min_sf_idx_mid, min_sf_idx_mid + SCALE_MAX_DIFF);

                    sididx = av_clip(minidx - sid_sf_boost * 3, min_sf_idx_side, min_sf_idx_side + SCALE_MAX_DIFF);

                    midcb = find_min_book(Mmax, mididx);

                    sidcb = find_min_book(Smax, sididx);



                    if ((mididx > minidx) || (sididx > minidx)) {

                        /* scalefactor range violation, bad stuff, will decrease quality unacceptably */

                        continue;

                    }



                    /* No CB can be zero */

                    midcb = FFMAX(1,midcb);

                    sidcb = FFMAX(1,sidcb);



                    for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {

                        FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];

                        FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];

                        float minthr = FFMIN(band0->threshold, band1->threshold);

                        int b1,b2,b3,b4;

                        for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {

                            M[i] = (sce0->coeffs[start+(w+w2)*128+i]

                                  + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;

                            S[i] =  M[i]

                                  - sce1->coeffs[start+(w+w2)*128+i];

                        }



                        abs_pow34_v(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);

                        abs_pow34_v(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);

                        abs_pow34_v(M34, M,                         sce0->ics.swb_sizes[g]);

                        abs_pow34_v(S34, S,                         sce0->ics.swb_sizes[g]);

                        dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128],

                                                    L34,

                                                    sce0->ics.swb_sizes[g],

                                                    sce0->sf_idx[(w+w2)*16+g],

                                                    sce0->band_type[(w+w2)*16+g],

                                                    lambda / band0->threshold, INFINITY, &b1, NULL, 0);

                        dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128],

                                                    R34,

                                                    sce1->ics.swb_sizes[g],

                                                    sce1->sf_idx[(w+w2)*16+g],

                                                    sce1->band_type[(w+w2)*16+g],

                                                    lambda / band1->threshold, INFINITY, &b2, NULL, 0);

                        dist2 += quantize_band_cost(s, M,

                                                    M34,

                                                    sce0->ics.swb_sizes[g],

                                                    sce0->sf_idx[(w+w2)*16+g],

                                                    sce0->band_type[(w+w2)*16+g],

                                                    lambda / minthr, INFINITY, &b3, NULL, 0);

                        dist2 += quantize_band_cost(s, S,

                                                    S34,

                                                    sce1->ics.swb_sizes[g],

                                                    sce1->sf_idx[(w+w2)*16+g],

                                                    sce1->band_type[(w+w2)*16+g],

                                                    mslambda / (minthr * bmax), INFINITY, &b4, NULL, 0);

                        B0 += b1+b2;

                        B1 += b3+b4;

                        dist1 -= B0;

                        dist2 -= B1;

                    }

                    cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0;

                    if (cpe->ms_mask[w*16+g]) {

                        /* Setting the M/S mask is useful with I/S or PNS, but only the flag */

                        if (!cpe->is_mask[w*16+g] && sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT) {

                            sce0->sf_idx[w*16+g] = mididx;

                            sce1->sf_idx[w*16+g] = sididx;

                            sce0->band_type[w*16+g] = midcb;

                            sce1->band_type[w*16+g] = sidcb;

                        }

                        break;

                    } else if (B1 > B0) {

                        /* More boost won't fix this */

                        break;

                    }

                }

            }

            start += sce0->ics.swb_sizes[g];

        }

    }

}

static void search_for_ms(AACEncContext *s, ChannelElement *cpe)

{

    int start = 0, i, w, w2, g, sid_sf_boost;

    float M[128], S[128];

    float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;

    const float lambda = s->lambda;

    const float mslambda = FFMIN(1.0f, lambda / 120.f);

    SingleChannelElement *sce0 = &cpe->ch[0];

    SingleChannelElement *sce1 = &cpe->ch[1];

    if (!cpe->common_window)

        return;

    for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {

        int min_sf_idx_mid = SCALE_MAX_POS;

        int min_sf_idx_side = SCALE_MAX_POS;

        for (g = 0; g < sce0->ics.num_swb; g++) {

            if (!sce0->zeroes[w*16+g] && sce0->band_type[w*16+g] < RESERVED_BT)

                min_sf_idx_mid = FFMIN(min_sf_idx_mid, sce0->sf_idx[w*16+g]);

            if (!sce1->zeroes[w*16+g] && sce1->band_type[w*16+g] < RESERVED_BT)

                min_sf_idx_side = FFMIN(min_sf_idx_side, sce1->sf_idx[w*16+g]);

        }



        start = 0;

        for (g = 0;  g < sce0->ics.num_swb; g++) {

            float bmax = bval2bmax(g * 17.0f / sce0->ics.num_swb) / 0.0045f;

            cpe->ms_mask[w*16+g] = 0;

            if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {

                float Mmax = 0.0f, Smax = 0.0f;



                

                for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {

                    for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {

                        M[i] = (sce0->coeffs[start+(w+w2)*128+i]

                              + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;

                        S[i] =  M[i]

                              - sce1->coeffs[start+(w+w2)*128+i];

                    }

                    abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);

                    abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);

                    for (i = 0; i < sce0->ics.swb_sizes[g]; i++ ) {

                        Mmax = FFMAX(Mmax, M34[i]);

                        Smax = FFMAX(Smax, S34[i]);

                    }

                }



                for (sid_sf_boost = 0; sid_sf_boost < 4; sid_sf_boost++) {

                    float dist1 = 0.0f, dist2 = 0.0f;

                    int B0 = 0, B1 = 0;

                    int minidx;

                    int mididx, sididx;

                    int midcb, sidcb;



                    minidx = FFMIN(sce0->sf_idx[w*16+g], sce1->sf_idx[w*16+g]);

                    mididx = av_clip(minidx, min_sf_idx_mid, min_sf_idx_mid + SCALE_MAX_DIFF);

                    sididx = av_clip(minidx - sid_sf_boost * 3, min_sf_idx_side, min_sf_idx_side + SCALE_MAX_DIFF);

                    midcb = find_min_book(Mmax, mididx);

                    sidcb = find_min_book(Smax, sididx);



                    if ((mididx > minidx) || (sididx > minidx)) {

                        

                        continue;

                    }



                    

                    midcb = FFMAX(1,midcb);

                    sidcb = FFMAX(1,sidcb);



                    for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {

                        FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];

                        FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];

                        float minthr = FFMIN(band0->threshold, band1->threshold);

                        int b1,b2,b3,b4;

                        for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {

                            M[i] = (sce0->coeffs[start+(w+w2)*128+i]

                                  + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;

                            S[i] =  M[i]

                                  - sce1->coeffs[start+(w+w2)*128+i];

                        }



                        abs_pow34_v(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);

                        abs_pow34_v(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);

                        abs_pow34_v(M34, M,                         sce0->ics.swb_sizes[g]);

                        abs_pow34_v(S34, S,                         sce0->ics.swb_sizes[g]);

                        dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128],

                                                    L34,

                                                    sce0->ics.swb_sizes[g],

                                                    sce0->sf_idx[(w+w2)*16+g],

                                                    sce0->band_type[(w+w2)*16+g],

                                                    lambda / band0->threshold, INFINITY, &b1, NULL, 0);

                        dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128],

                                                    R34,

                                                    sce1->ics.swb_sizes[g],

                                                    sce1->sf_idx[(w+w2)*16+g],

                                                    sce1->band_type[(w+w2)*16+g],

                                                    lambda / band1->threshold, INFINITY, &b2, NULL, 0);

                        dist2 += quantize_band_cost(s, M,

                                                    M34,

                                                    sce0->ics.swb_sizes[g],

                                                    sce0->sf_idx[(w+w2)*16+g],

                                                    sce0->band_type[(w+w2)*16+g],

                                                    lambda / minthr, INFINITY, &b3, NULL, 0);

                        dist2 += quantize_band_cost(s, S,

                                                    S34,

                                                    sce1->ics.swb_sizes[g],

                                                    sce1->sf_idx[(w+w2)*16+g],

                                                    sce1->band_type[(w+w2)*16+g],

                                                    mslambda / (minthr * bmax), INFINITY, &b4, NULL, 0);

                        B0 += b1+b2;

                        B1 += b3+b4;

                        dist1 -= B0;

                        dist2 -= B1;

                    }

                    cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0;

                    if (cpe->ms_mask[w*16+g]) {

                        

                        if (!cpe->is_mask[w*16+g] && sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT) {

                            sce0->sf_idx[w*16+g] = mididx;

                            sce1->sf_idx[w*16+g] = sididx;

                            sce0->band_type[w*16+g] = midcb;

                            sce1->band_type[w*16+g] = sidcb;

                        }

                        break;

                    } else if (B1 > B0) {

                        

                        break;

                    }

                }

            }

            start += sce0->ics.swb_sizes[g];

        }

    }

}

    int start = 0, i, w, w2, g, sid_sf_boost;     for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {         int min_sf_idx_mid = SCALE_MAX_POS;         int min_sf_idx_side = SCALE_MAX_POS;         for (g = 0; g < sce0->ics.num_swb; g++) {             if (!sce0->zeroes[w*16+g] && sce0->band_type[w*16+g] < RESERVED_BT)                 min_sf_idx_mid = FFMIN(min_sf_idx_mid, sce0->sf_idx[w*16+g]);             if (!sce1->zeroes[w*16+g] && sce1->band_type[w*16+g] < RESERVED_BT)                 min_sf_idx_side = FFMIN(min_sf_idx_side, sce1->sf_idx[w*16+g]);             if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {                     mididx = av_clip(minidx, min_sf_idx_mid, min_sf_idx_mid + SCALE_MAX_DIFF);                     sididx = av_clip(minidx - sid_sf_boost * 3, min_sf_idx_side, min_sf_idx_side + SCALE_MAX_DIFF);                     midcb = find_min_book(Mmax, mididx);                     sidcb = find_min_book(Smax, sididx);                     if ((mididx > minidx) || (sididx > minidx)) {             if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
static void FUNC_0(AACEncContext *VAR_0, ChannelElement *VAR_1)

{

    int VAR_2 = 0, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    float VAR_8[128], VAR_9[128];

    float *VAR_10 = VAR_0->scoefs, *VAR_11 = VAR_0->scoefs + 128, *VAR_12 = VAR_0->scoefs + 128*2, *VAR_13 = VAR_0->scoefs + 128*3;

    const float VAR_14 = VAR_0->VAR_14;

    const float VAR_15 = FFMIN(1.0f, VAR_14 / 120.f);

    SingleChannelElement *sce0 = &VAR_1->ch[0];

    SingleChannelElement *sce1 = &VAR_1->ch[1];

    if (!VAR_1->common_window)

        return;

    for (VAR_4 = 0; VAR_4 < sce0->ics.num_windows; VAR_4 += sce0->ics.group_len[VAR_4]) {

        int min_sf_idx_mid = SCALE_MAX_POS;

        int min_sf_idx_side = SCALE_MAX_POS;

        for (VAR_6 = 0; VAR_6 < sce0->ics.num_swb; VAR_6++) {

            if (!sce0->zeroes[VAR_4*16+VAR_6] && sce0->band_type[VAR_4*16+VAR_6] < RESERVED_BT)

                min_sf_idx_mid = FFMIN(min_sf_idx_mid, sce0->sf_idx[VAR_4*16+VAR_6]);

            if (!sce1->zeroes[VAR_4*16+VAR_6] && sce1->band_type[VAR_4*16+VAR_6] < RESERVED_BT)

                min_sf_idx_side = FFMIN(min_sf_idx_side, sce1->sf_idx[VAR_4*16+VAR_6]);

        }



        VAR_2 = 0;

        for (VAR_6 = 0;  VAR_6 < sce0->ics.num_swb; VAR_6++) {

            float bmax = bval2bmax(VAR_6 * 17.0f / sce0->ics.num_swb) / 0.0045f;

            VAR_1->ms_mask[VAR_4*16+VAR_6] = 0;

            if (!VAR_1->ch[0].zeroes[VAR_4*16+VAR_6] && !VAR_1->ch[1].zeroes[VAR_4*16+VAR_6]) {

                float Mmax = 0.0f, Smax = 0.0f;



                

                for (VAR_5 = 0; VAR_5 < sce0->ics.group_len[VAR_4]; VAR_5++) {

                    for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++) {

                        VAR_8[VAR_3] = (sce0->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]

                              + sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]) * 0.5;

                        VAR_9[VAR_3] =  VAR_8[VAR_3]

                              - sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3];

                    }

                    abs_pow34_v(VAR_12, VAR_8, sce0->ics.swb_sizes[VAR_6]);

                    abs_pow34_v(VAR_13, VAR_9, sce0->ics.swb_sizes[VAR_6]);

                    for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++ ) {

                        Mmax = FFMAX(Mmax, VAR_12[VAR_3]);

                        Smax = FFMAX(Smax, VAR_13[VAR_3]);

                    }

                }



                for (VAR_7 = 0; VAR_7 < 4; VAR_7++) {

                    float dist1 = 0.0f, dist2 = 0.0f;

                    int B0 = 0, B1 = 0;

                    int minidx;

                    int mididx, sididx;

                    int midcb, sidcb;



                    minidx = FFMIN(sce0->sf_idx[VAR_4*16+VAR_6], sce1->sf_idx[VAR_4*16+VAR_6]);

                    mididx = av_clip(minidx, min_sf_idx_mid, min_sf_idx_mid + SCALE_MAX_DIFF);

                    sididx = av_clip(minidx - VAR_7 * 3, min_sf_idx_side, min_sf_idx_side + SCALE_MAX_DIFF);

                    midcb = find_min_book(Mmax, mididx);

                    sidcb = find_min_book(Smax, sididx);



                    if ((mididx > minidx) || (sididx > minidx)) {

                        

                        continue;

                    }



                    

                    midcb = FFMAX(1,midcb);

                    sidcb = FFMAX(1,sidcb);



                    for (VAR_5 = 0; VAR_5 < sce0->ics.group_len[VAR_4]; VAR_5++) {

                        FFPsyBand *band0 = &VAR_0->psy.ch[VAR_0->cur_channel+0].psy_bands[(VAR_4+VAR_5)*16+VAR_6];

                        FFPsyBand *band1 = &VAR_0->psy.ch[VAR_0->cur_channel+1].psy_bands[(VAR_4+VAR_5)*16+VAR_6];

                        float minthr = FFMIN(band0->threshold, band1->threshold);

                        int b1,b2,b3,b4;

                        for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++) {

                            VAR_8[VAR_3] = (sce0->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]

                                  + sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]) * 0.5;

                            VAR_9[VAR_3] =  VAR_8[VAR_3]

                                  - sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3];

                        }



                        abs_pow34_v(VAR_10, sce0->coeffs+VAR_2+(VAR_4+VAR_5)*128, sce0->ics.swb_sizes[VAR_6]);

                        abs_pow34_v(VAR_11, sce1->coeffs+VAR_2+(VAR_4+VAR_5)*128, sce0->ics.swb_sizes[VAR_6]);

                        abs_pow34_v(VAR_12, VAR_8,                         sce0->ics.swb_sizes[VAR_6]);

                        abs_pow34_v(VAR_13, VAR_9,                         sce0->ics.swb_sizes[VAR_6]);

                        dist1 += quantize_band_cost(VAR_0, &sce0->coeffs[VAR_2 + (VAR_4+VAR_5)*128],

                                                    VAR_10,

                                                    sce0->ics.swb_sizes[VAR_6],

                                                    sce0->sf_idx[(VAR_4+VAR_5)*16+VAR_6],

                                                    sce0->band_type[(VAR_4+VAR_5)*16+VAR_6],

                                                    VAR_14 / band0->threshold, INFINITY, &b1, NULL, 0);

                        dist1 += quantize_band_cost(VAR_0, &sce1->coeffs[VAR_2 + (VAR_4+VAR_5)*128],

                                                    VAR_11,

                                                    sce1->ics.swb_sizes[VAR_6],

                                                    sce1->sf_idx[(VAR_4+VAR_5)*16+VAR_6],

                                                    sce1->band_type[(VAR_4+VAR_5)*16+VAR_6],

                                                    VAR_14 / band1->threshold, INFINITY, &b2, NULL, 0);

                        dist2 += quantize_band_cost(VAR_0, VAR_8,

                                                    VAR_12,

                                                    sce0->ics.swb_sizes[VAR_6],

                                                    sce0->sf_idx[(VAR_4+VAR_5)*16+VAR_6],

                                                    sce0->band_type[(VAR_4+VAR_5)*16+VAR_6],

                                                    VAR_14 / minthr, INFINITY, &b3, NULL, 0);

                        dist2 += quantize_band_cost(VAR_0, VAR_9,

                                                    VAR_13,

                                                    sce1->ics.swb_sizes[VAR_6],

                                                    sce1->sf_idx[(VAR_4+VAR_5)*16+VAR_6],

                                                    sce1->band_type[(VAR_4+VAR_5)*16+VAR_6],

                                                    VAR_15 / (minthr * bmax), INFINITY, &b4, NULL, 0);

                        B0 += b1+b2;

                        B1 += b3+b4;

                        dist1 -= B0;

                        dist2 -= B1;

                    }

                    VAR_1->ms_mask[VAR_4*16+VAR_6] = dist2 <= dist1 && B1 < B0;

                    if (VAR_1->ms_mask[VAR_4*16+VAR_6]) {

                        

                        if (!VAR_1->is_mask[VAR_4*16+VAR_6] && sce0->band_type[VAR_4*16+VAR_6] != NOISE_BT && sce1->band_type[VAR_4*16+VAR_6] != NOISE_BT) {

                            sce0->sf_idx[VAR_4*16+VAR_6] = mididx;

                            sce1->sf_idx[VAR_4*16+VAR_6] = sididx;

                            sce0->band_type[VAR_4*16+VAR_6] = midcb;

                            sce1->band_type[VAR_4*16+VAR_6] = sidcb;

                        }

                        break;

                    } else if (B1 > B0) {

                        

                        break;

                    }

                }

            }

            VAR_2 += sce0->ics.swb_sizes[VAR_6];

        }

    }

}

static void FUNC_0(AACEncContext *VAR_0, ChannelElement *VAR_1)
{ int VAR_2 = 0, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; float VAR_8[128], VAR_9[128]; float *VAR_10 = VAR_0->scoefs, *VAR_11 = VAR_0->scoefs + 128, *VAR_12 = VAR_0->scoefs + 128*2, *VAR_13 = VAR_0->scoefs + 128*3; const float VAR_14 = VAR_0->VAR_14; const float VAR_15 = FFMIN(1.0f, VAR_14 / 120.f); SingleChannelElement *sce0 = &VAR_1->ch[0]; SingleChannelElement *sce1 = &VAR_1->ch[1]; if (!VAR_1->common_window)
return; for (VAR_4 = 0; VAR_4 < sce0->ics.num_windows; VAR_4 += sce0->ics.group_len[VAR_4]) { int min_sf_idx_mid = SCALE_MAX_POS; int min_sf_idx_side = SCALE_MAX_POS; for (VAR_6 = 0; VAR_6 < sce0->ics.num_swb; VAR_6++) { if (!sce0->zeroes[VAR_4*16+VAR_6] && sce0->band_type[VAR_4*16+VAR_6] < RESERVED_BT)
min_sf_idx_mid = FFMIN(min_sf_idx_mid, sce0->sf_idx[VAR_4*16+VAR_6]); if (!sce1->zeroes[VAR_4*16+VAR_6] && sce1->band_type[VAR_4*16+VAR_6] < RESERVED_BT)
min_sf_idx_side = FFMIN(min_sf_idx_side, sce1->sf_idx[VAR_4*16+VAR_6]); } VAR_2 = 0; for (VAR_6 = 0;  VAR_6 < sce0->ics.num_swb; VAR_6++) { float bmax = bval2bmax(VAR_6 * 17.0f / sce0->ics.num_swb) / 0.0045f; VAR_1->ms_mask[VAR_4*16+VAR_6] = 0; if (!VAR_1->ch[0].zeroes[VAR_4*16+VAR_6] && !VAR_1->ch[1].zeroes[VAR_4*16+VAR_6]) { float Mmax = 0.0f, Smax = 0.0f; for (VAR_5 = 0; VAR_5 < sce0->ics.group_len[VAR_4]; VAR_5++) { for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++) { VAR_8[VAR_3] = (sce0->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]
+ sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]) * 0.5; VAR_9[VAR_3] =  VAR_8[VAR_3]
- sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]; } abs_pow34_v(VAR_12, VAR_8, sce0->ics.swb_sizes[VAR_6]); abs_pow34_v(VAR_13, VAR_9, sce0->ics.swb_sizes[VAR_6]); for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++ ) { Mmax = FFMAX(Mmax, VAR_12[VAR_3]); Smax = FFMAX(Smax, VAR_13[VAR_3]); } } for (VAR_7 = 0; VAR_7 < 4; VAR_7++) { float dist1 = 0.0f, dist2 = 0.0f; int B0 = 0, B1 = 0; int minidx; int mididx, sididx; int midcb, sidcb; minidx = FFMIN(sce0->sf_idx[VAR_4*16+VAR_6], sce1->sf_idx[VAR_4*16+VAR_6]); mididx = av_clip(minidx, min_sf_idx_mid, min_sf_idx_mid + SCALE_MAX_DIFF); sididx = av_clip(minidx - VAR_7 * 3, min_sf_idx_side, min_sf_idx_side + SCALE_MAX_DIFF); midcb = find_min_book(Mmax, mididx); sidcb = find_min_book(Smax, sididx); if ((mididx > minidx) || (sididx > minidx)) { continue; } midcb = FFMAX(1,midcb); sidcb = FFMAX(1,sidcb); for (VAR_5 = 0; VAR_5 < sce0->ics.group_len[VAR_4]; VAR_5++) { FFPsyBand *band0 = &VAR_0->psy.ch[VAR_0->cur_channel+0].psy_bands[(VAR_4+VAR_5)*16+VAR_6]; FFPsyBand *band1 = &VAR_0->psy.ch[VAR_0->cur_channel+1].psy_bands[(VAR_4+VAR_5)*16+VAR_6]; float minthr = FFMIN(band0->threshold, band1->threshold); int b1,b2,b3,b4; for (VAR_3 = 0; VAR_3 < sce0->ics.swb_sizes[VAR_6]; VAR_3++) { VAR_8[VAR_3] = (sce0->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]
+ sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]) * 0.5; VAR_9[VAR_3] =  VAR_8[VAR_3]
- sce1->coeffs[VAR_2+(VAR_4+VAR_5)*128+VAR_3]; } abs_pow34_v(VAR_10, sce0->coeffs+VAR_2+(VAR_4+VAR_5)*128, sce0->ics.swb_sizes[VAR_6]); abs_pow34_v(VAR_11, sce1->coeffs+VAR_2+(VAR_4+VAR_5)*128, sce0->ics.swb_sizes[VAR_6]); abs_pow34_v(VAR_12, VAR_8,                         sce0->ics.swb_sizes[VAR_6]); abs_pow34_v(VAR_13, VAR_9,                         sce0->ics.swb_sizes[VAR_6]); dist1 += quantize_band_cost(VAR_0, &sce0->coeffs[VAR_2 + (VAR_4+VAR_5)*128],
VAR_10,
sce0->ics.swb_sizes[VAR_6],
sce0->sf_idx[(VAR_4+VAR_5)*16+VAR_6],
sce0->band_type[(VAR_4+VAR_5)*16+VAR_6],
VAR_14 / band0->threshold, INFINITY, &b1, NULL, 0); dist1 += quantize_band_cost(VAR_0, &sce1->coeffs[VAR_2 + (VAR_4+VAR_5)*128],
VAR_11,
sce1->ics.swb_sizes[VAR_6],
sce1->sf_idx[(VAR_4+VAR_5)*16+VAR_6],
sce1->band_type[(VAR_4+VAR_5)*16+VAR_6],
VAR_14 / band1->threshold, INFINITY, &b2, NULL, 0); dist2 += quantize_band_cost(VAR_0, VAR_8,
VAR_12,
sce0->ics.swb_sizes[VAR_6],
sce0->sf_idx[(VAR_4+VAR_5)*16+VAR_6],
sce0->band_type[(VAR_4+VAR_5)*16+VAR_6],
VAR_14 / minthr, INFINITY, &b3, NULL, 0); dist2 += quantize_band_cost(VAR_0, VAR_9,
VAR_13,
sce1->ics.swb_sizes[VAR_6],
sce1->sf_idx[(VAR_4+VAR_5)*16+VAR_6],
sce1->band_type[(VAR_4+VAR_5)*16+VAR_6],
VAR_15 / (minthr * bmax), INFINITY, &b4, NULL, 0); B0 += b1+b2; B1 += b3+b4; dist1 -= B0; dist2 -= B1; } VAR_1->ms_mask[VAR_4*16+VAR_6] = dist2 <= dist1 && B1 < B0; if (VAR_1->ms_mask[VAR_4*16+VAR_6]) { if (!VAR_1->is_mask[VAR_4*16+VAR_6] && sce0->band_type[VAR_4*16+VAR_6] != NOISE_BT && sce1->band_type[VAR_4*16+VAR_6] != NOISE_BT) { sce0->sf_idx[VAR_4*16+VAR_6] = mididx; sce1->sf_idx[VAR_4*16+VAR_6] = sididx; sce0->band_type[VAR_4*16+VAR_6] = midcb; sce1->band_type[VAR_4*16+VAR_6] = sidcb; } break; } else if (B1 > B0) { break; } } } VAR_2 += sce0->ics.swb_sizes[VAR_6]; } } }