static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)

{

    int k, e;

    int ch;



    if (id_aac == TYPE_CPE && sbr->bs_coupling) {

        int alpha      = sbr->data[0].bs_amp_res ?  2 :  1;

        int pan_offset = sbr->data[0].bs_amp_res ? 12 : 24;

        for (e = 1; e <= sbr->data[0].bs_num_env; e++) {

            for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = sbr->data[0].env_facs[e][k].mant * alpha + 14;

                if (temp1.exp & 1)

                  temp1.mant = 759250125;

                else

                  temp1.mant = 0x20000000;

                temp1.exp = (temp1.exp >> 1) + 1;

                if (temp1.exp > 66) { // temp1 > 1E20

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }



                temp2.exp = (pan_offset - sbr->data[1].env_facs[e][k].mant) * alpha;

                if (temp2.exp & 1)

                  temp2.mant = 759250125;

                else

                  temp2.mant = 0x20000000;

                temp2.exp = (temp2.exp >> 1) + 1;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                sbr->data[0].env_facs[e][k] = fac;

                sbr->data[1].env_facs[e][k] = av_mul_sf(fac, temp2);

            }

        }

        for (e = 1; e <= sbr->data[0].bs_num_noise; e++) {

            for (k = 0; k < sbr->n_q; k++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = NOISE_FLOOR_OFFSET - \

                    sbr->data[0].noise_facs[e][k].mant + 2;

                temp1.mant = 0x20000000;

                if (temp1.exp > 66) { // temp1 > 1E20

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }

                temp2.exp = 12 - sbr->data[1].noise_facs[e][k].mant + 1;

                temp2.mant = 0x20000000;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                sbr->data[0].noise_facs[e][k] = fac;

                sbr->data[1].noise_facs[e][k] = av_mul_sf(fac, temp2);

            }

        }

    } else { // SCE or one non-coupled CPE

        for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {

            int alpha = sbr->data[ch].bs_amp_res ? 2 : 1;

            for (e = 1; e <= sbr->data[ch].bs_num_env; e++)

                for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++){

                    SoftFloat temp1;



                    temp1.exp = alpha * sbr->data[ch].env_facs[e][k].mant + 12;

                    if (temp1.exp & 1)

                        temp1.mant = 759250125;

                    else

                        temp1.mant = 0x20000000;

                    temp1.exp = (temp1.exp >> 1) + 1;

                    if (temp1.exp > 66) { // temp1 > 1E20

                        av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                        temp1 = FLOAT_1;

                    }

                    sbr->data[ch].env_facs[e][k] = temp1;

                }

            for (e = 1; e <= sbr->data[ch].bs_num_noise; e++)

                for (k = 0; k < sbr->n_q; k++){

                    sbr->data[ch].noise_facs[e][k].exp = NOISE_FLOOR_OFFSET - \

                        sbr->data[ch].noise_facs[e][k].mant + 1;

                    sbr->data[ch].noise_facs[e][k].mant = 0x20000000;

                }

        }

    }

}

static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)

{

    int k, e;

    int ch;



    if (id_aac == TYPE_CPE && sbr->bs_coupling) {

        int alpha      = sbr->data[0].bs_amp_res ?  2 :  1;

        int pan_offset = sbr->data[0].bs_amp_res ? 12 : 24;

        for (e = 1; e <= sbr->data[0].bs_num_env; e++) {

            for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = sbr->data[0].env_facs[e][k].mant * alpha + 14;

                if (temp1.exp & 1)

                  temp1.mant = 759250125;

                else

                  temp1.mant = 0x20000000;

                temp1.exp = (temp1.exp >> 1) + 1;

                if (temp1.exp > 66) { 

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }



                temp2.exp = (pan_offset - sbr->data[1].env_facs[e][k].mant) * alpha;

                if (temp2.exp & 1)

                  temp2.mant = 759250125;

                else

                  temp2.mant = 0x20000000;

                temp2.exp = (temp2.exp >> 1) + 1;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                sbr->data[0].env_facs[e][k] = fac;

                sbr->data[1].env_facs[e][k] = av_mul_sf(fac, temp2);

            }

        }

        for (e = 1; e <= sbr->data[0].bs_num_noise; e++) {

            for (k = 0; k < sbr->n_q; k++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = NOISE_FLOOR_OFFSET - \

                    sbr->data[0].noise_facs[e][k].mant + 2;

                temp1.mant = 0x20000000;

                if (temp1.exp > 66) { 

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }

                temp2.exp = 12 - sbr->data[1].noise_facs[e][k].mant + 1;

                temp2.mant = 0x20000000;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                sbr->data[0].noise_facs[e][k] = fac;

                sbr->data[1].noise_facs[e][k] = av_mul_sf(fac, temp2);

            }

        }

    } else { 

        for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {

            int alpha = sbr->data[ch].bs_amp_res ? 2 : 1;

            for (e = 1; e <= sbr->data[ch].bs_num_env; e++)

                for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++){

                    SoftFloat temp1;



                    temp1.exp = alpha * sbr->data[ch].env_facs[e][k].mant + 12;

                    if (temp1.exp & 1)

                        temp1.mant = 759250125;

                    else

                        temp1.mant = 0x20000000;

                    temp1.exp = (temp1.exp >> 1) + 1;

                    if (temp1.exp > 66) { 

                        av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                        temp1 = FLOAT_1;

                    }

                    sbr->data[ch].env_facs[e][k] = temp1;

                }

            for (e = 1; e <= sbr->data[ch].bs_num_noise; e++)

                for (k = 0; k < sbr->n_q; k++){

                    sbr->data[ch].noise_facs[e][k].exp = NOISE_FLOOR_OFFSET - \

                        sbr->data[ch].noise_facs[e][k].mant + 1;

                    sbr->data[ch].noise_facs[e][k].mant = 0x20000000;

                }

        }

    }

}

static void FUNC_0(SpectralBandReplication *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3;

    int VAR_4;



    if (VAR_1 == TYPE_CPE && VAR_0->bs_coupling) {

        int VAR_5      = VAR_0->data[0].bs_amp_res ?  2 :  1;

        int VAR_6 = VAR_0->data[0].bs_amp_res ? 12 : 24;

        for (VAR_3 = 1; VAR_3 <= VAR_0->data[0].bs_num_env; VAR_3++) {

            for (VAR_2 = 0; VAR_2 < VAR_0->n[VAR_0->data[0].bs_freq_res[VAR_3]]; VAR_2++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = VAR_0->data[0].env_facs[VAR_3][VAR_2].mant * VAR_5 + 14;

                if (temp1.exp & 1)

                  temp1.mant = 759250125;

                else

                  temp1.mant = 0x20000000;

                temp1.exp = (temp1.exp >> 1) + 1;

                if (temp1.exp > 66) { 

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }



                temp2.exp = (VAR_6 - VAR_0->data[1].env_facs[VAR_3][VAR_2].mant) * VAR_5;

                if (temp2.exp & 1)

                  temp2.mant = 759250125;

                else

                  temp2.mant = 0x20000000;

                temp2.exp = (temp2.exp >> 1) + 1;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                VAR_0->data[0].env_facs[VAR_3][VAR_2] = fac;

                VAR_0->data[1].env_facs[VAR_3][VAR_2] = av_mul_sf(fac, temp2);

            }

        }

        for (VAR_3 = 1; VAR_3 <= VAR_0->data[0].bs_num_noise; VAR_3++) {

            for (VAR_2 = 0; VAR_2 < VAR_0->n_q; VAR_2++) {

                SoftFloat temp1, temp2, fac;



                temp1.exp = NOISE_FLOOR_OFFSET - \

                    VAR_0->data[0].noise_facs[VAR_3][VAR_2].mant + 2;

                temp1.mant = 0x20000000;

                if (temp1.exp > 66) { 

                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                    temp1 = FLOAT_1;

                }

                temp2.exp = 12 - VAR_0->data[1].noise_facs[VAR_3][VAR_2].mant + 1;

                temp2.mant = 0x20000000;

                fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2));

                VAR_0->data[0].noise_facs[VAR_3][VAR_2] = fac;

                VAR_0->data[1].noise_facs[VAR_3][VAR_2] = av_mul_sf(fac, temp2);

            }

        }

    } else { 

        for (VAR_4 = 0; VAR_4 < (VAR_1 == TYPE_CPE) + 1; VAR_4++) {

            int VAR_5 = VAR_0->data[VAR_4].bs_amp_res ? 2 : 1;

            for (VAR_3 = 1; VAR_3 <= VAR_0->data[VAR_4].bs_num_env; VAR_3++)

                for (VAR_2 = 0; VAR_2 < VAR_0->n[VAR_0->data[VAR_4].bs_freq_res[VAR_3]]; VAR_2++){

                    SoftFloat temp1;



                    temp1.exp = VAR_5 * VAR_0->data[VAR_4].env_facs[VAR_3][VAR_2].mant + 12;

                    if (temp1.exp & 1)

                        temp1.mant = 759250125;

                    else

                        temp1.mant = 0x20000000;

                    temp1.exp = (temp1.exp >> 1) + 1;

                    if (temp1.exp > 66) { 

                        av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");

                        temp1 = FLOAT_1;

                    }

                    VAR_0->data[VAR_4].env_facs[VAR_3][VAR_2] = temp1;

                }

            for (VAR_3 = 1; VAR_3 <= VAR_0->data[VAR_4].bs_num_noise; VAR_3++)

                for (VAR_2 = 0; VAR_2 < VAR_0->n_q; VAR_2++){

                    VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].exp = NOISE_FLOOR_OFFSET - \

                        VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].mant + 1;

                    VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].mant = 0x20000000;

                }

        }

    }

}

static void FUNC_0(SpectralBandReplication *VAR_0, int VAR_1)
{ int VAR_2, VAR_3; int VAR_4; if (VAR_1 == TYPE_CPE && VAR_0->bs_coupling) { int VAR_5      = VAR_0->data[0].bs_amp_res ?  2 :  1; int VAR_6 = VAR_0->data[0].bs_amp_res ? 12 : 24; for (VAR_3 = 1; VAR_3 <= VAR_0->data[0].bs_num_env; VAR_3++) { for (VAR_2 = 0; VAR_2 < VAR_0->n[VAR_0->data[0].bs_freq_res[VAR_3]]; VAR_2++) { SoftFloat temp1, temp2, fac; temp1.exp = VAR_0->data[0].env_facs[VAR_3][VAR_2].mant * VAR_5 + 14; if (temp1.exp & 1)
temp1.mant = 759250125; else
temp1.mant = 0x20000000; temp1.exp = (temp1.exp >> 1) + 1; if (temp1.exp > 66) { av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n"); temp1 = FLOAT_1; } temp2.exp = (VAR_6 - VAR_0->data[1].env_facs[VAR_3][VAR_2].mant) * VAR_5; if (temp2.exp & 1)
temp2.mant = 759250125; else
temp2.mant = 0x20000000; temp2.exp = (temp2.exp >> 1) + 1; fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2)); VAR_0->data[0].env_facs[VAR_3][VAR_2] = fac; VAR_0->data[1].env_facs[VAR_3][VAR_2] = av_mul_sf(fac, temp2); } } for (VAR_3 = 1; VAR_3 <= VAR_0->data[0].bs_num_noise; VAR_3++) { for (VAR_2 = 0; VAR_2 < VAR_0->n_q; VAR_2++) { SoftFloat temp1, temp2, fac; temp1.exp = NOISE_FLOOR_OFFSET - \
VAR_0->data[0].noise_facs[VAR_3][VAR_2].mant + 2; temp1.mant = 0x20000000; if (temp1.exp > 66) { av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n"); temp1 = FLOAT_1; } temp2.exp = 12 - VAR_0->data[1].noise_facs[VAR_3][VAR_2].mant + 1; temp2.mant = 0x20000000; fac   = av_div_sf(temp1, av_add_sf(FLOAT_1, temp2)); VAR_0->data[0].noise_facs[VAR_3][VAR_2] = fac; VAR_0->data[1].noise_facs[VAR_3][VAR_2] = av_mul_sf(fac, temp2); } } } else { for (VAR_4 = 0; VAR_4 < (VAR_1 == TYPE_CPE) + 1; VAR_4++) { int VAR_5 = VAR_0->data[VAR_4].bs_amp_res ? 2 : 1; for (VAR_3 = 1; VAR_3 <= VAR_0->data[VAR_4].bs_num_env; VAR_3++) for (VAR_2 = 0; VAR_2 < VAR_0->n[VAR_0->data[VAR_4].bs_freq_res[VAR_3]]; VAR_2++){ SoftFloat temp1; temp1.exp = VAR_5 * VAR_0->data[VAR_4].env_facs[VAR_3][VAR_2].mant + 12; if (temp1.exp & 1)
temp1.mant = 759250125; else
temp1.mant = 0x20000000; temp1.exp = (temp1.exp >> 1) + 1; if (temp1.exp > 66) { av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n"); temp1 = FLOAT_1; } VAR_0->data[VAR_4].env_facs[VAR_3][VAR_2] = temp1; } for (VAR_3 = 1; VAR_3 <= VAR_0->data[VAR_4].bs_num_noise; VAR_3++) for (VAR_2 = 0; VAR_2 < VAR_0->n_q; VAR_2++){ VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].exp = NOISE_FLOOR_OFFSET - \
VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].mant + 1; VAR_0->data[VAR_4].noise_facs[VAR_3][VAR_2].mant = 0x20000000; } } } }