void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,

                  float* L, float* R)

{

    int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate;

    int ch;

    int nch = (id_aac == TYPE_CPE) ? 2 : 1;



    if (sbr->start) {

        sbr_dequant(sbr, id_aac);

    }

    for (ch = 0; ch < nch; ch++) {

        /* decode channel */

        sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,

                         (float*)sbr->qmf_filter_scratch,

                         sbr->data[ch].W);

        sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W);

        if (sbr->start) {

            sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]);

            sbr_chirp(sbr, &sbr->data[ch]);

            sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1,

                       sbr->data[ch].bw_array, sbr->data[ch].t_env,

                       sbr->data[ch].bs_num_env);



            // hf_adj

            sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);

            sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]);

            sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);

            sbr_hf_assemble(sbr->data[ch].Y, sbr->X_high, sbr, &sbr->data[ch],

                            sbr->data[ch].e_a);

        }



        /* synthesis */

        sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, ch);

    }



    if (ac->m4ac.ps == 1) {

        if (sbr->ps.start) {

            ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);

        } else {

            memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));

        }

        nch = 2;

    }



    sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch,

                      sbr->data[0].synthesis_filterbank_samples,

                      &sbr->data[0].synthesis_filterbank_samples_offset,

                      downsampled);

    if (nch == 2)

        sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch,

                          sbr->data[1].synthesis_filterbank_samples,

                          &sbr->data[1].synthesis_filterbank_samples_offset,

                          downsampled);

}

void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,

                  float* L, float* R)

{

    int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate;

    int ch;

    int nch = (id_aac == TYPE_CPE) ? 2 : 1;



    if (sbr->start) {

        sbr_dequant(sbr, id_aac);

    }

    for (ch = 0; ch < nch; ch++) {

        

        sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,

                         (float*)sbr->qmf_filter_scratch,

                         sbr->data[ch].W);

        sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W);

        if (sbr->start) {

            sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]);

            sbr_chirp(sbr, &sbr->data[ch]);

            sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1,

                       sbr->data[ch].bw_array, sbr->data[ch].t_env,

                       sbr->data[ch].bs_num_env);



            

            sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);

            sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]);

            sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);

            sbr_hf_assemble(sbr->data[ch].Y, sbr->X_high, sbr, &sbr->data[ch],

                            sbr->data[ch].e_a);

        }



        

        sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, ch);

    }



    if (ac->m4ac.ps == 1) {

        if (sbr->ps.start) {

            ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);

        } else {

            memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));

        }

        nch = 2;

    }



    sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch,

                      sbr->data[0].synthesis_filterbank_samples,

                      &sbr->data[0].synthesis_filterbank_samples_offset,

                      downsampled);

    if (nch == 2)

        sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch,

                          sbr->data[1].synthesis_filterbank_samples,

                          &sbr->data[1].synthesis_filterbank_samples_offset,

                          downsampled);

}

void FUNC_0(AACContext *VAR_0, SpectralBandReplication *VAR_1, int VAR_2,

                  float* VAR_3, float* VAR_4)

{

    int VAR_5 = VAR_0->m4ac.ext_sample_rate < VAR_1->sample_rate;

    int VAR_6;

    int VAR_7 = (VAR_2 == TYPE_CPE) ? 2 : 1;



    if (VAR_1->start) {

        sbr_dequant(VAR_1, VAR_2);

    }

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

        

        sbr_qmf_analysis(&VAR_0->dsp, &VAR_1->mdct_ana, VAR_6 ? VAR_4 : VAR_3, VAR_1->data[VAR_6].analysis_filterbank_samples,

                         (float*)VAR_1->qmf_filter_scratch,

                         VAR_1->data[VAR_6].W);

        sbr_lf_gen(VAR_0, VAR_1, VAR_1->X_low, VAR_1->data[VAR_6].W);

        if (VAR_1->start) {

            sbr_hf_inverse_filter(VAR_1->alpha0, VAR_1->alpha1, VAR_1->X_low, VAR_1->k[0]);

            sbr_chirp(VAR_1, &VAR_1->data[VAR_6]);

            sbr_hf_gen(VAR_0, VAR_1, VAR_1->X_high, VAR_1->X_low, VAR_1->alpha0, VAR_1->alpha1,

                       VAR_1->data[VAR_6].bw_array, VAR_1->data[VAR_6].t_env,

                       VAR_1->data[VAR_6].bs_num_env);



            

            sbr_mapping(VAR_0, VAR_1, &VAR_1->data[VAR_6], VAR_1->data[VAR_6].e_a);

            sbr_env_estimate(VAR_1->e_curr, VAR_1->X_high, VAR_1, &VAR_1->data[VAR_6]);

            sbr_gain_calc(VAR_0, VAR_1, &VAR_1->data[VAR_6], VAR_1->data[VAR_6].e_a);

            sbr_hf_assemble(VAR_1->data[VAR_6].Y, VAR_1->X_high, VAR_1, &VAR_1->data[VAR_6],

                            VAR_1->data[VAR_6].e_a);

        }



        

        sbr_x_gen(VAR_1, VAR_1->X[VAR_6], VAR_1->X_low, VAR_1->data[VAR_6].Y, VAR_6);

    }



    if (VAR_0->m4ac.ps == 1) {

        if (VAR_1->ps.start) {

            ff_ps_apply(VAR_0->avctx, &VAR_1->ps, VAR_1->X[0], VAR_1->X[1], VAR_1->kx[1] + VAR_1->m[1]);

        } else {

            memcpy(VAR_1->X[1], VAR_1->X[0], sizeof(VAR_1->X[0]));

        }

        VAR_7 = 2;

    }



    sbr_qmf_synthesis(&VAR_0->dsp, &VAR_1->mdct, VAR_3, VAR_1->X[0], VAR_1->qmf_filter_scratch,

                      VAR_1->data[0].synthesis_filterbank_samples,

                      &VAR_1->data[0].synthesis_filterbank_samples_offset,

                      VAR_5);

    if (VAR_7 == 2)

        sbr_qmf_synthesis(&VAR_0->dsp, &VAR_1->mdct, VAR_4, VAR_1->X[1], VAR_1->qmf_filter_scratch,

                          VAR_1->data[1].synthesis_filterbank_samples,

                          &VAR_1->data[1].synthesis_filterbank_samples_offset,

                          VAR_5);

}

void FUNC_0(AACContext *VAR_0, SpectralBandReplication *VAR_1, int VAR_2,
float* VAR_3, float* VAR_4)
{ int VAR_5 = VAR_0->m4ac.ext_sample_rate < VAR_1->sample_rate; int VAR_6; int VAR_7 = (VAR_2 == TYPE_CPE) ? 2 : 1; if (VAR_1->start) { sbr_dequant(VAR_1, VAR_2); } for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) { sbr_qmf_analysis(&VAR_0->dsp, &VAR_1->mdct_ana, VAR_6 ? VAR_4 : VAR_3, VAR_1->data[VAR_6].analysis_filterbank_samples,
(float*)VAR_1->qmf_filter_scratch,
VAR_1->data[VAR_6].W); sbr_lf_gen(VAR_0, VAR_1, VAR_1->X_low, VAR_1->data[VAR_6].W); if (VAR_1->start) { sbr_hf_inverse_filter(VAR_1->alpha0, VAR_1->alpha1, VAR_1->X_low, VAR_1->k[0]); sbr_chirp(VAR_1, &VAR_1->data[VAR_6]); sbr_hf_gen(VAR_0, VAR_1, VAR_1->X_high, VAR_1->X_low, VAR_1->alpha0, VAR_1->alpha1,
VAR_1->data[VAR_6].bw_array, VAR_1->data[VAR_6].t_env,
VAR_1->data[VAR_6].bs_num_env); sbr_mapping(VAR_0, VAR_1, &VAR_1->data[VAR_6], VAR_1->data[VAR_6].e_a); sbr_env_estimate(VAR_1->e_curr, VAR_1->X_high, VAR_1, &VAR_1->data[VAR_6]); sbr_gain_calc(VAR_0, VAR_1, &VAR_1->data[VAR_6], VAR_1->data[VAR_6].e_a); sbr_hf_assemble(VAR_1->data[VAR_6].Y, VAR_1->X_high, VAR_1, &VAR_1->data[VAR_6],
VAR_1->data[VAR_6].e_a); } sbr_x_gen(VAR_1, VAR_1->X[VAR_6], VAR_1->X_low, VAR_1->data[VAR_6].Y, VAR_6); } if (VAR_0->m4ac.ps == 1) { if (VAR_1->ps.start) { ff_ps_apply(VAR_0->avctx, &VAR_1->ps, VAR_1->X[0], VAR_1->X[1], VAR_1->kx[1] + VAR_1->m[1]); } else { memcpy(VAR_1->X[1], VAR_1->X[0], sizeof(VAR_1->X[0])); } VAR_7 = 2; } sbr_qmf_synthesis(&VAR_0->dsp, &VAR_1->mdct, VAR_3, VAR_1->X[0], VAR_1->qmf_filter_scratch,
VAR_1->data[0].synthesis_filterbank_samples,
&VAR_1->data[0].synthesis_filterbank_samples_offset,
VAR_5); if (VAR_7 == 2)
sbr_qmf_synthesis(&VAR_0->dsp, &VAR_1->mdct, VAR_4, VAR_1->X[1], VAR_1->qmf_filter_scratch,
VAR_1->data[1].synthesis_filterbank_samples,
&VAR_1->data[1].synthesis_filterbank_samples_offset,
VAR_5); }