static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,

                        SBRData *ch_data, int e_a[2])

{

    int e, i, m;



    memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1]));

    for (e = 0; e < ch_data->bs_num_env; e++) {

        const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]];

        uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;

        int k;



        for (i = 0; i < ilim; i++)

            for (m = table[i]; m < table[i + 1]; m++)

                sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];



        // ch_data->bs_num_noise > 1 => 2 noise floors

        k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]);

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

            for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++)

                sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i];



        for (i = 0; i < sbr->n[1]; i++) {

            if (ch_data->bs_add_harmonic_flag) {

                const unsigned int m_midpoint =

                    (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1;



                ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] *

                    (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1));

            }

        }



        for (i = 0; i < ilim; i++) {

            int additional_sinusoid_present = 0;

            for (m = table[i]; m < table[i + 1]; m++) {

                if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) {

                    additional_sinusoid_present = 1;

                    break;

                }

            }

            memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present,

                   (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0]));

        }

    }



    memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0]));

}

static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,

                        SBRData *ch_data, int e_a[2])

{

    int e, i, m;



    memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1]));

    for (e = 0; e < ch_data->bs_num_env; e++) {

        const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]];

        uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;

        int k;



        for (i = 0; i < ilim; i++)

            for (m = table[i]; m < table[i + 1]; m++)

                sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];



        

        k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]);

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

            for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++)

                sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i];



        for (i = 0; i < sbr->n[1]; i++) {

            if (ch_data->bs_add_harmonic_flag) {

                const unsigned int m_midpoint =

                    (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1;



                ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] *

                    (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1));

            }

        }



        for (i = 0; i < ilim; i++) {

            int additional_sinusoid_present = 0;

            for (m = table[i]; m < table[i + 1]; m++) {

                if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) {

                    additional_sinusoid_present = 1;

                    break;

                }

            }

            memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present,

                   (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0]));

        }

    }



    memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0]));

}

static void FUNC_0(AACContext *VAR_0, SpectralBandReplication *VAR_1,

                        SBRData *VAR_2, int VAR_3[2])

{

    int VAR_4, VAR_5, VAR_6;



    memset(VAR_2->s_indexmapped[1], 0, 7*sizeof(VAR_2->s_indexmapped[1]));

    for (VAR_4 = 0; VAR_4 < VAR_2->bs_num_env; VAR_4++) {

        const unsigned int ilim = VAR_1->n[VAR_2->bs_freq_res[VAR_4 + 1]];

        uint16_t *table = VAR_2->bs_freq_res[VAR_4 + 1] ? VAR_1->f_tablehigh : VAR_1->f_tablelow;

        int k;



        for (VAR_5 = 0; VAR_5 < ilim; VAR_5++)

            for (VAR_6 = table[VAR_5]; VAR_6 < table[VAR_5 + 1]; VAR_6++)

                VAR_1->e_origmapped[VAR_4][VAR_6 - VAR_1->kx[1]] = VAR_2->env_facs[VAR_4+1][VAR_5];



        

        k = (VAR_2->bs_num_noise > 1) && (VAR_2->t_env[VAR_4] >= VAR_2->t_q[1]);

        for (VAR_5 = 0; VAR_5 < VAR_1->n_q; VAR_5++)

            for (VAR_6 = VAR_1->f_tablenoise[VAR_5]; VAR_6 < VAR_1->f_tablenoise[VAR_5 + 1]; VAR_6++)

                VAR_1->q_mapped[VAR_4][VAR_6 - VAR_1->kx[1]] = VAR_2->noise_facs[k+1][VAR_5];



        for (VAR_5 = 0; VAR_5 < VAR_1->n[1]; VAR_5++) {

            if (VAR_2->bs_add_harmonic_flag) {

                const unsigned int m_midpoint =

                    (VAR_1->f_tablehigh[VAR_5] + VAR_1->f_tablehigh[VAR_5 + 1]) >> 1;



                VAR_2->s_indexmapped[VAR_4 + 1][m_midpoint - VAR_1->kx[1]] = VAR_2->bs_add_harmonic[VAR_5] *

                    (VAR_4 >= VAR_3[1] || (VAR_2->s_indexmapped[0][m_midpoint - VAR_1->kx[1]] == 1));

            }

        }



        for (VAR_5 = 0; VAR_5 < ilim; VAR_5++) {

            int additional_sinusoid_present = 0;

            for (VAR_6 = table[VAR_5]; VAR_6 < table[VAR_5 + 1]; VAR_6++) {

                if (VAR_2->s_indexmapped[VAR_4 + 1][VAR_6 - VAR_1->kx[1]]) {

                    additional_sinusoid_present = 1;

                    break;

                }

            }

            memset(&VAR_1->s_mapped[VAR_4][table[VAR_5] - VAR_1->kx[1]], additional_sinusoid_present,

                   (table[VAR_5 + 1] - table[VAR_5]) * sizeof(VAR_1->s_mapped[VAR_4][0]));

        }

    }



    memcpy(VAR_2->s_indexmapped[0], VAR_2->s_indexmapped[VAR_2->bs_num_env], sizeof(VAR_2->s_indexmapped[0]));

}

static void FUNC_0(AACContext *VAR_0, SpectralBandReplication *VAR_1,
SBRData *VAR_2, int VAR_3[2])
{ int VAR_4, VAR_5, VAR_6; memset(VAR_2->s_indexmapped[1], 0, 7*sizeof(VAR_2->s_indexmapped[1])); for (VAR_4 = 0; VAR_4 < VAR_2->bs_num_env; VAR_4++) { const unsigned int ilim = VAR_1->n[VAR_2->bs_freq_res[VAR_4 + 1]]; uint16_t *table = VAR_2->bs_freq_res[VAR_4 + 1] ? VAR_1->f_tablehigh : VAR_1->f_tablelow; int k; for (VAR_5 = 0; VAR_5 < ilim; VAR_5++) for (VAR_6 = table[VAR_5]; VAR_6 < table[VAR_5 + 1]; VAR_6++) VAR_1->e_origmapped[VAR_4][VAR_6 - VAR_1->kx[1]] = VAR_2->env_facs[VAR_4+1][VAR_5]; k = (VAR_2->bs_num_noise > 1) && (VAR_2->t_env[VAR_4] >= VAR_2->t_q[1]); for (VAR_5 = 0; VAR_5 < VAR_1->n_q; VAR_5++) for (VAR_6 = VAR_1->f_tablenoise[VAR_5]; VAR_6 < VAR_1->f_tablenoise[VAR_5 + 1]; VAR_6++) VAR_1->q_mapped[VAR_4][VAR_6 - VAR_1->kx[1]] = VAR_2->noise_facs[k+1][VAR_5]; for (VAR_5 = 0; VAR_5 < VAR_1->n[1]; VAR_5++) { if (VAR_2->bs_add_harmonic_flag) { const unsigned int m_midpoint =
(VAR_1->f_tablehigh[VAR_5] + VAR_1->f_tablehigh[VAR_5 + 1]) >> 1; VAR_2->s_indexmapped[VAR_4 + 1][m_midpoint - VAR_1->kx[1]] = VAR_2->bs_add_harmonic[VAR_5] *
(VAR_4 >= VAR_3[1] || (VAR_2->s_indexmapped[0][m_midpoint - VAR_1->kx[1]] == 1)); } } for (VAR_5 = 0; VAR_5 < ilim; VAR_5++) { int additional_sinusoid_present = 0; for (VAR_6 = table[VAR_5]; VAR_6 < table[VAR_5 + 1]; VAR_6++) { if (VAR_2->s_indexmapped[VAR_4 + 1][VAR_6 - VAR_1->kx[1]]) { additional_sinusoid_present = 1; break; } } memset(&VAR_1->s_mapped[VAR_4][table[VAR_5] - VAR_1->kx[1]], additional_sinusoid_present,
(table[VAR_5 + 1] - table[VAR_5]) * sizeof(VAR_1->s_mapped[VAR_4][0])); } } memcpy(VAR_2->s_indexmapped[0], VAR_2->s_indexmapped[VAR_2->bs_num_env], sizeof(VAR_2->s_indexmapped[0])); }