static int wma_decode_block(WMACodecContext *s)

{

    int n, v, a, ch, bsize;

    int coef_nb_bits, total_gain;

    int nb_coefs[MAX_CHANNELS];

    float mdct_norm;

    FFTContext *mdct;



#ifdef TRACE

    tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);

#endif



    /* compute current block length */

    if (s->use_variable_block_len) {

        n = av_log2(s->nb_block_sizes - 1) + 1;



        if (s->reset_block_lengths) {

            s->reset_block_lengths = 0;

            v = get_bits(&s->gb, n);

            if (v >= s->nb_block_sizes){

                av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);

                return -1;


            s->prev_block_len_bits = s->frame_len_bits - v;

            v = get_bits(&s->gb, n);

            if (v >= s->nb_block_sizes){

                av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);

                return -1;


            s->block_len_bits = s->frame_len_bits - v;

        } else {

            /* update block lengths */

            s->prev_block_len_bits = s->block_len_bits;

            s->block_len_bits = s->next_block_len_bits;


        v = get_bits(&s->gb, n);

        if (v >= s->nb_block_sizes){

            av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);

            return -1;


        s->next_block_len_bits = s->frame_len_bits - v;

    } else {

        /* fixed block len */

        s->next_block_len_bits = s->frame_len_bits;

        s->prev_block_len_bits = s->frame_len_bits;

        s->block_len_bits = s->frame_len_bits;




    if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){

        av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");

        return -1;




    /* now check if the block length is coherent with the frame length */

    s->block_len = 1 << s->block_len_bits;

    if ((s->block_pos + s->block_len) > s->frame_len){

        av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");

        return -1;




    if (s->avctx->channels == 2) {

        s->ms_stereo = get_bits1(&s->gb);


    v = 0;

    for(ch = 0; ch < s->avctx->channels; ch++) {

        a = get_bits1(&s->gb);

        s->channel_coded[ch] = a;

        v |= a;




    bsize = s->frame_len_bits - s->block_len_bits;



    /* if no channel coded, no need to go further */

    /* XXX: fix potential framing problems */

    if (!v)

        goto next;



    /* read total gain and extract corresponding number of bits for

       coef escape coding */

    total_gain = 1;

    for(;;) {





        a = get_bits(&s->gb, 7);

        total_gain += a;

        if (a != 127)

            break;




    coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);



    /* compute number of coefficients */

    n = s->coefs_end[bsize] - s->coefs_start;

    for(ch = 0; ch < s->avctx->channels; ch++)

        nb_coefs[ch] = n;



    /* complex coding */

    if (s->use_noise_coding) {



        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                int i, n, a;

                n = s->exponent_high_sizes[bsize];

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

                    a = get_bits1(&s->gb);

                    s->high_band_coded[ch][i] = a;

                    /* if noise coding, the coefficients are not transmitted */

                    if (a)

                        nb_coefs[ch] -= s->exponent_high_bands[bsize][i];




        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                int i, n, val, code;



                n = s->exponent_high_sizes[bsize];

                val = (int)0x80000000;

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

                    if (s->high_band_coded[ch][i]) {

                        if (val == (int)0x80000000) {

                            val = get_bits(&s->gb, 7) - 19;

                        } else {

                            code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);

                            if (code < 0){

                                av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");

                                return -1;


                            val += code - 18;


                        s->high_band_values[ch][i] = val;








    /* exponents can be reused in short blocks. */

    if ((s->block_len_bits == s->frame_len_bits) ||

        get_bits1(&s->gb)) {

        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                if (s->use_exp_vlc) {

                    if (decode_exp_vlc(s, ch) < 0)

                        return -1;

                } else {

                    decode_exp_lsp(s, ch);


                s->exponents_bsize[ch] = bsize;






    /* parse spectral coefficients : just RLE encoding */

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            int tindex;

            WMACoef* ptr = &s->coefs1[ch][0];



            /* special VLC tables are used for ms stereo because

               there is potentially less energy there */

            tindex = (ch == 1 && s->ms_stereo);

            memset(ptr, 0, s->block_len * sizeof(WMACoef));

            ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],

                  s->level_table[tindex], s->run_table[tindex],

                  0, ptr, 0, nb_coefs[ch],

                  s->block_len, s->frame_len_bits, coef_nb_bits);


        if (s->version == 1 && s->avctx->channels >= 2) {

            align_get_bits(&s->gb);





    /* normalize */

    {

        int n4 = s->block_len / 2;

        mdct_norm = 1.0 / (float)n4;

        if (s->version == 1) {

            mdct_norm *= sqrt(n4);





    /* finally compute the MDCT coefficients */

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            WMACoef *coefs1;

            float *coefs, *exponents, mult, mult1, noise;

            int i, j, n, n1, last_high_band, esize;

            float exp_power[HIGH_BAND_MAX_SIZE];



            coefs1 = s->coefs1[ch];

            exponents = s->exponents[ch];

            esize = s->exponents_bsize[ch];

            mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];

            mult *= mdct_norm;

            coefs = s->coefs[ch];

            if (s->use_noise_coding) {

                mult1 = mult;

                /* very low freqs : noise */

                for(i = 0;i < s->coefs_start; i++) {

                    *coefs++ = s->noise_table[s->noise_index] *

                      exponents[i<<bsize>>esize] * mult1;

                    s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);




                n1 = s->exponent_high_sizes[bsize];



                /* compute power of high bands */

                exponents = s->exponents[ch] +

                    (s->high_band_start[bsize]<<bsize>>esize);

                last_high_band = 0; /* avoid warning */

                for(j=0;j<n1;j++) {

                    n = s->exponent_high_bands[s->frame_len_bits -

                                              s->block_len_bits][j];

                    if (s->high_band_coded[ch][j]) {

                        float e2, v;

                        e2 = 0;

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

                            v = exponents[i<<bsize>>esize];

                            e2 += v * v;


                        exp_power[j] = e2 / n;

                        last_high_band = j;

                        tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);


                    exponents += n<<bsize>>esize;




                /* main freqs and high freqs */

                exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);

                for(j=-1;j<n1;j++) {

                    if (j < 0) {

                        n = s->high_band_start[bsize] -

                            s->coefs_start;

                    } else {

                        n = s->exponent_high_bands[s->frame_len_bits -

                                                  s->block_len_bits][j];


                    if (j >= 0 && s->high_band_coded[ch][j]) {

                        /* use noise with specified power */

                        mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);

                        /* XXX: use a table */

                        mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);

                        mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);

                        mult1 *= mdct_norm;

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

                            noise = s->noise_table[s->noise_index];

                            s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ =  noise *

                                exponents[i<<bsize>>esize] * mult1;


                        exponents += n<<bsize>>esize;

                    } else {

                        /* coded values + small noise */

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

                            noise = s->noise_table[s->noise_index];

                            s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ = ((*coefs1++) + noise) *

                                exponents[i<<bsize>>esize] * mult;


                        exponents += n<<bsize>>esize;





                /* very high freqs : noise */

                n = s->block_len - s->coefs_end[bsize];

                mult1 = mult * exponents[((-1<<bsize))>>esize];

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

                    *coefs++ = s->noise_table[s->noise_index] * mult1;

                    s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);


            } else {

                /* XXX: optimize more */

                for(i = 0;i < s->coefs_start; i++)

                    *coefs++ = 0.0;

                n = nb_coefs[ch];

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

                    *coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult;


                n = s->block_len - s->coefs_end[bsize];

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

                    *coefs++ = 0.0;






#ifdef TRACE

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);

            dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);



#endif



    if (s->ms_stereo && s->channel_coded[1]) {

        /* nominal case for ms stereo: we do it before mdct */

        /* no need to optimize this case because it should almost

           never happen */

        if (!s->channel_coded[0]) {

            tprintf(s->avctx, "rare ms-stereo case happened\n");

            memset(s->coefs[0], 0, sizeof(float) * s->block_len);

            s->channel_coded[0] = 1;




        s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);




next:

    mdct = &s->mdct_ctx[bsize];



    for (ch = 0; ch < s->avctx->channels; ch++) {

        int n4, index;



        n4 = s->block_len / 2;

        if(s->channel_coded[ch]){

            mdct->imdct_calc(mdct, s->output, s->coefs[ch]);

        }else if(!(s->ms_stereo && ch==1))

            memset(s->output, 0, sizeof(s->output));



        /* multiply by the window and add in the frame */

        index = (s->frame_len / 2) + s->block_pos - n4;

        wma_window(s, &s->frame_out[ch][index]);




    /* update block number */

    s->block_num++;

    s->block_pos += s->block_len;

    if (s->block_pos >= s->frame_len)

        return 1;

    else

        return 0;

static int wma_decode_block(WMACodecContext *s)

{

    int n, v, a, ch, bsize;

    int coef_nb_bits, total_gain;

    int nb_coefs[MAX_CHANNELS];

    float mdct_norm;

    FFTContext *mdct;



#ifdef TRACE

    tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);

#endif



    

    if (s->use_variable_block_len) {

        n = av_log2(s->nb_block_sizes - 1) + 1;



        if (s->reset_block_lengths) {

            s->reset_block_lengths = 0;

            v = get_bits(&s->gb, n);

            if (v >= s->nb_block_sizes){

                av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);

                return -1;


            s->prev_block_len_bits = s->frame_len_bits - v;

            v = get_bits(&s->gb, n);

            if (v >= s->nb_block_sizes){

                av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);

                return -1;


            s->block_len_bits = s->frame_len_bits - v;

        } else {

            

            s->prev_block_len_bits = s->block_len_bits;

            s->block_len_bits = s->next_block_len_bits;


        v = get_bits(&s->gb, n);

        if (v >= s->nb_block_sizes){

            av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);

            return -1;


        s->next_block_len_bits = s->frame_len_bits - v;

    } else {

        

        s->next_block_len_bits = s->frame_len_bits;

        s->prev_block_len_bits = s->frame_len_bits;

        s->block_len_bits = s->frame_len_bits;




    if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){

        av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");

        return -1;




    

    s->block_len = 1 << s->block_len_bits;

    if ((s->block_pos + s->block_len) > s->frame_len){

        av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");

        return -1;




    if (s->avctx->channels == 2) {

        s->ms_stereo = get_bits1(&s->gb);


    v = 0;

    for(ch = 0; ch < s->avctx->channels; ch++) {

        a = get_bits1(&s->gb);

        s->channel_coded[ch] = a;

        v |= a;




    bsize = s->frame_len_bits - s->block_len_bits;



    

    

    if (!v)

        goto next;



    



    total_gain = 1;

    for(;;) {





        a = get_bits(&s->gb, 7);

        total_gain += a;

        if (a != 127)

            break;




    coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);



    

    n = s->coefs_end[bsize] - s->coefs_start;

    for(ch = 0; ch < s->avctx->channels; ch++)

        nb_coefs[ch] = n;



    

    if (s->use_noise_coding) {



        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                int i, n, a;

                n = s->exponent_high_sizes[bsize];

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

                    a = get_bits1(&s->gb);

                    s->high_band_coded[ch][i] = a;

                    

                    if (a)

                        nb_coefs[ch] -= s->exponent_high_bands[bsize][i];




        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                int i, n, val, code;



                n = s->exponent_high_sizes[bsize];

                val = (int)0x80000000;

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

                    if (s->high_band_coded[ch][i]) {

                        if (val == (int)0x80000000) {

                            val = get_bits(&s->gb, 7) - 19;

                        } else {

                            code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);

                            if (code < 0){

                                av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");

                                return -1;


                            val += code - 18;


                        s->high_band_values[ch][i] = val;








    

    if ((s->block_len_bits == s->frame_len_bits) ||

        get_bits1(&s->gb)) {

        for(ch = 0; ch < s->avctx->channels; ch++) {

            if (s->channel_coded[ch]) {

                if (s->use_exp_vlc) {

                    if (decode_exp_vlc(s, ch) < 0)

                        return -1;

                } else {

                    decode_exp_lsp(s, ch);


                s->exponents_bsize[ch] = bsize;






    

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            int tindex;

            WMACoef* ptr = &s->coefs1[ch][0];



            



            tindex = (ch == 1 && s->ms_stereo);

            memset(ptr, 0, s->block_len * sizeof(WMACoef));

            ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],

                  s->level_table[tindex], s->run_table[tindex],

                  0, ptr, 0, nb_coefs[ch],

                  s->block_len, s->frame_len_bits, coef_nb_bits);


        if (s->version == 1 && s->avctx->channels >= 2) {

            align_get_bits(&s->gb);





    

    {

        int n4 = s->block_len / 2;

        mdct_norm = 1.0 / (float)n4;

        if (s->version == 1) {

            mdct_norm *= sqrt(n4);





    

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            WMACoef *coefs1;

            float *coefs, *exponents, mult, mult1, noise;

            int i, j, n, n1, last_high_band, esize;

            float exp_power[HIGH_BAND_MAX_SIZE];



            coefs1 = s->coefs1[ch];

            exponents = s->exponents[ch];

            esize = s->exponents_bsize[ch];

            mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];

            mult *= mdct_norm;

            coefs = s->coefs[ch];

            if (s->use_noise_coding) {

                mult1 = mult;

                

                for(i = 0;i < s->coefs_start; i++) {

                    *coefs++ = s->noise_table[s->noise_index] *

                      exponents[i<<bsize>>esize] * mult1;

                    s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);




                n1 = s->exponent_high_sizes[bsize];



                

                exponents = s->exponents[ch] +

                    (s->high_band_start[bsize]<<bsize>>esize);

                last_high_band = 0; 

                for(j=0;j<n1;j++) {

                    n = s->exponent_high_bands[s->frame_len_bits -

                                              s->block_len_bits][j];

                    if (s->high_band_coded[ch][j]) {

                        float e2, v;

                        e2 = 0;

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

                            v = exponents[i<<bsize>>esize];

                            e2 += v * v;


                        exp_power[j] = e2 / n;

                        last_high_band = j;

                        tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);


                    exponents += n<<bsize>>esize;




                

                exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);

                for(j=-1;j<n1;j++) {

                    if (j < 0) {

                        n = s->high_band_start[bsize] -

                            s->coefs_start;

                    } else {

                        n = s->exponent_high_bands[s->frame_len_bits -

                                                  s->block_len_bits][j];


                    if (j >= 0 && s->high_band_coded[ch][j]) {

                        

                        mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);

                        

                        mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);

                        mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);

                        mult1 *= mdct_norm;

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

                            noise = s->noise_table[s->noise_index];

                            s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ =  noise *

                                exponents[i<<bsize>>esize] * mult1;


                        exponents += n<<bsize>>esize;

                    } else {

                        

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

                            noise = s->noise_table[s->noise_index];

                            s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ = ((*coefs1++) + noise) *

                                exponents[i<<bsize>>esize] * mult;


                        exponents += n<<bsize>>esize;





                

                n = s->block_len - s->coefs_end[bsize];

                mult1 = mult * exponents[((-1<<bsize))>>esize];

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

                    *coefs++ = s->noise_table[s->noise_index] * mult1;

                    s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);


            } else {

                

                for(i = 0;i < s->coefs_start; i++)

                    *coefs++ = 0.0;

                n = nb_coefs[ch];

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

                    *coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult;


                n = s->block_len - s->coefs_end[bsize];

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

                    *coefs++ = 0.0;






#ifdef TRACE

    for (ch = 0; ch < s->avctx->channels; ch++) {

        if (s->channel_coded[ch]) {

            dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);

            dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);



#endif



    if (s->ms_stereo && s->channel_coded[1]) {

        

        



        if (!s->channel_coded[0]) {

            tprintf(s->avctx, "rare ms-stereo case happened\n");

            memset(s->coefs[0], 0, sizeof(float) * s->block_len);

            s->channel_coded[0] = 1;




        s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);




next:

    mdct = &s->mdct_ctx[bsize];



    for (ch = 0; ch < s->avctx->channels; ch++) {

        int n4, index;



        n4 = s->block_len / 2;

        if(s->channel_coded[ch]){

            mdct->imdct_calc(mdct, s->output, s->coefs[ch]);

        }else if(!(s->ms_stereo && ch==1))

            memset(s->output, 0, sizeof(s->output));



        

        index = (s->frame_len / 2) + s->block_pos - n4;

        wma_window(s, &s->frame_out[ch][index]);




    

    s->block_num++;

    s->block_pos += s->block_len;

    if (s->block_pos >= s->frame_len)

        return 1;

    else

        return 0;

static int FUNC_0(WMACodecContext *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6, VAR_7;

    int VAR_8[MAX_CHANNELS];

    float VAR_9;

    FFTContext *mdct;



#ifdef TRACE

    tprintf(VAR_0->avctx, "***decode_block: %d:%d\VAR_1", VAR_0->frame_count - 1, VAR_0->block_num);

#endif



    

    if (VAR_0->use_variable_block_len) {

        VAR_1 = av_log2(VAR_0->nb_block_sizes - 1) + 1;



        if (VAR_0->reset_block_lengths) {

            VAR_0->reset_block_lengths = 0;

            VAR_2 = get_bits(&VAR_0->gb, VAR_1);

            if (VAR_2 >= VAR_0->nb_block_sizes){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2);

                return -1;


            VAR_0->prev_block_len_bits = VAR_0->frame_len_bits - VAR_2;

            VAR_2 = get_bits(&VAR_0->gb, VAR_1);

            if (VAR_2 >= VAR_0->nb_block_sizes){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2);

                return -1;


            VAR_0->block_len_bits = VAR_0->frame_len_bits - VAR_2;

        } else {

            

            VAR_0->prev_block_len_bits = VAR_0->block_len_bits;

            VAR_0->block_len_bits = VAR_0->next_block_len_bits;


        VAR_2 = get_bits(&VAR_0->gb, VAR_1);

        if (VAR_2 >= VAR_0->nb_block_sizes){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2);

            return -1;


        VAR_0->next_block_len_bits = VAR_0->frame_len_bits - VAR_2;

    } else {

        

        VAR_0->next_block_len_bits = VAR_0->frame_len_bits;

        VAR_0->prev_block_len_bits = VAR_0->frame_len_bits;

        VAR_0->block_len_bits = VAR_0->frame_len_bits;




    if (VAR_0->frame_len_bits - VAR_0->block_len_bits >= VAR_0->nb_block_sizes){

        av_log(VAR_0->avctx, AV_LOG_ERROR, "block_len_bits not initialized to VAR_3 valid value\VAR_1");

        return -1;




    

    VAR_0->block_len = 1 << VAR_0->block_len_bits;

    if ((VAR_0->block_pos + VAR_0->block_len) > VAR_0->frame_len){

        av_log(VAR_0->avctx, AV_LOG_ERROR, "frame_len overflow\VAR_1");

        return -1;




    if (VAR_0->avctx->channels == 2) {

        VAR_0->ms_stereo = get_bits1(&VAR_0->gb);


    VAR_2 = 0;

    for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

        VAR_3 = get_bits1(&VAR_0->gb);

        VAR_0->channel_coded[VAR_4] = VAR_3;

        VAR_2 |= VAR_3;




    VAR_5 = VAR_0->frame_len_bits - VAR_0->block_len_bits;



    

    

    if (!VAR_2)

        goto next;



    



    VAR_7 = 1;

    for(;;) {





        VAR_3 = get_bits(&VAR_0->gb, 7);

        VAR_7 += VAR_3;

        if (VAR_3 != 127)

            break;




    VAR_6= ff_wma_total_gain_to_bits(VAR_7);



    

    VAR_1 = VAR_0->coefs_end[VAR_5] - VAR_0->coefs_start;

    for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++)

        VAR_8[VAR_4] = VAR_1;



    

    if (VAR_0->use_noise_coding) {



        for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

            if (VAR_0->channel_coded[VAR_4]) {

                int i, VAR_1, VAR_3;

                VAR_1 = VAR_0->exponent_high_sizes[VAR_5];

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

                    VAR_3 = get_bits1(&VAR_0->gb);

                    VAR_0->high_band_coded[VAR_4][i] = VAR_3;

                    

                    if (VAR_3)

                        VAR_8[VAR_4] -= VAR_0->exponent_high_bands[VAR_5][i];




        for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

            if (VAR_0->channel_coded[VAR_4]) {

                int i, VAR_1, val, code;



                VAR_1 = VAR_0->exponent_high_sizes[VAR_5];

                val = (int)0x80000000;

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

                    if (VAR_0->high_band_coded[VAR_4][i]) {

                        if (val == (int)0x80000000) {

                            val = get_bits(&VAR_0->gb, 7) - 19;

                        } else {

                            code = get_vlc2(&VAR_0->gb, VAR_0->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);

                            if (code < 0){

                                av_log(VAR_0->avctx, AV_LOG_ERROR, "hgain vlc invalid\VAR_1");

                                return -1;


                            val += code - 18;


                        VAR_0->high_band_values[VAR_4][i] = val;








    

    if ((VAR_0->block_len_bits == VAR_0->frame_len_bits) ||

        get_bits1(&VAR_0->gb)) {

        for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

            if (VAR_0->channel_coded[VAR_4]) {

                if (VAR_0->use_exp_vlc) {

                    if (decode_exp_vlc(VAR_0, VAR_4) < 0)

                        return -1;

                } else {

                    decode_exp_lsp(VAR_0, VAR_4);


                VAR_0->exponents_bsize[VAR_4] = VAR_5;






    

    for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

        if (VAR_0->channel_coded[VAR_4]) {

            int tindex;

            WMACoef* ptr = &VAR_0->coefs1[VAR_4][0];



            



            tindex = (VAR_4 == 1 && VAR_0->ms_stereo);

            memset(ptr, 0, VAR_0->block_len * sizeof(WMACoef));

            ff_wma_run_level_decode(VAR_0->avctx, &VAR_0->gb, &VAR_0->coef_vlc[tindex],

                  VAR_0->level_table[tindex], VAR_0->run_table[tindex],

                  0, ptr, 0, VAR_8[VAR_4],

                  VAR_0->block_len, VAR_0->frame_len_bits, VAR_6);


        if (VAR_0->version == 1 && VAR_0->avctx->channels >= 2) {

            align_get_bits(&VAR_0->gb);





    

    {

        int n4 = VAR_0->block_len / 2;

        VAR_9 = 1.0 / (float)n4;

        if (VAR_0->version == 1) {

            VAR_9 *= sqrt(n4);





    

    for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

        if (VAR_0->channel_coded[VAR_4]) {

            WMACoef *coefs1;

            float *coefs, *exponents, mult, mult1, noise;

            int i, j, VAR_1, n1, last_high_band, esize;

            float exp_power[HIGH_BAND_MAX_SIZE];



            coefs1 = VAR_0->coefs1[VAR_4];

            exponents = VAR_0->exponents[VAR_4];

            esize = VAR_0->exponents_bsize[VAR_4];

            mult = pow(10, VAR_7 * 0.05) / VAR_0->max_exponent[VAR_4];

            mult *= VAR_9;

            coefs = VAR_0->coefs[VAR_4];

            if (VAR_0->use_noise_coding) {

                mult1 = mult;

                

                for(i = 0;i < VAR_0->coefs_start; i++) {

                    *coefs++ = VAR_0->noise_table[VAR_0->noise_index] *

                      exponents[i<<VAR_5>>esize] * mult1;

                    VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1);




                n1 = VAR_0->exponent_high_sizes[VAR_5];



                

                exponents = VAR_0->exponents[VAR_4] +

                    (VAR_0->high_band_start[VAR_5]<<VAR_5>>esize);

                last_high_band = 0; 

                for(j=0;j<n1;j++) {

                    VAR_1 = VAR_0->exponent_high_bands[VAR_0->frame_len_bits -

                                              VAR_0->block_len_bits][j];

                    if (VAR_0->high_band_coded[VAR_4][j]) {

                        float e2, VAR_2;

                        e2 = 0;

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

                            VAR_2 = exponents[i<<VAR_5>>esize];

                            e2 += VAR_2 * VAR_2;


                        exp_power[j] = e2 / VAR_1;

                        last_high_band = j;

                        tprintf(VAR_0->avctx, "%d: power=%f (%d)\VAR_1", j, exp_power[j], VAR_1);


                    exponents += VAR_1<<VAR_5>>esize;




                

                exponents = VAR_0->exponents[VAR_4] + (VAR_0->coefs_start<<VAR_5>>esize);

                for(j=-1;j<n1;j++) {

                    if (j < 0) {

                        VAR_1 = VAR_0->high_band_start[VAR_5] -

                            VAR_0->coefs_start;

                    } else {

                        VAR_1 = VAR_0->exponent_high_bands[VAR_0->frame_len_bits -

                                                  VAR_0->block_len_bits][j];


                    if (j >= 0 && VAR_0->high_band_coded[VAR_4][j]) {

                        

                        mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);

                        

                        mult1 = mult1 * pow(10, VAR_0->high_band_values[VAR_4][j] * 0.05);

                        mult1 = mult1 / (VAR_0->max_exponent[VAR_4] * VAR_0->noise_mult);

                        mult1 *= VAR_9;

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

                            noise = VAR_0->noise_table[VAR_0->noise_index];

                            VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ =  noise *

                                exponents[i<<VAR_5>>esize] * mult1;


                        exponents += VAR_1<<VAR_5>>esize;

                    } else {

                        

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

                            noise = VAR_0->noise_table[VAR_0->noise_index];

                            VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1);

                            *coefs++ = ((*coefs1++) + noise) *

                                exponents[i<<VAR_5>>esize] * mult;


                        exponents += VAR_1<<VAR_5>>esize;





                

                VAR_1 = VAR_0->block_len - VAR_0->coefs_end[VAR_5];

                mult1 = mult * exponents[((-1<<VAR_5))>>esize];

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

                    *coefs++ = VAR_0->noise_table[VAR_0->noise_index] * mult1;

                    VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1);


            } else {

                

                for(i = 0;i < VAR_0->coefs_start; i++)

                    *coefs++ = 0.0;

                VAR_1 = VAR_8[VAR_4];

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

                    *coefs++ = coefs1[i] * exponents[i<<VAR_5>>esize] * mult;


                VAR_1 = VAR_0->block_len - VAR_0->coefs_end[VAR_5];

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

                    *coefs++ = 0.0;






#ifdef TRACE

    for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

        if (VAR_0->channel_coded[VAR_4]) {

            dump_floats(VAR_0, "exponents", 3, VAR_0->exponents[VAR_4], VAR_0->block_len);

            dump_floats(VAR_0, "coefs", 1, VAR_0->coefs[VAR_4], VAR_0->block_len);



#endif



    if (VAR_0->ms_stereo && VAR_0->channel_coded[1]) {

        

        



        if (!VAR_0->channel_coded[0]) {

            tprintf(VAR_0->avctx, "rare ms-stereo case happened\VAR_1");

            memset(VAR_0->coefs[0], 0, sizeof(float) * VAR_0->block_len);

            VAR_0->channel_coded[0] = 1;




        VAR_0->fdsp.butterflies_float(VAR_0->coefs[0], VAR_0->coefs[1], VAR_0->block_len);




next:

    mdct = &VAR_0->mdct_ctx[VAR_5];



    for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) {

        int n4, index;



        n4 = VAR_0->block_len / 2;

        if(VAR_0->channel_coded[VAR_4]){

            mdct->imdct_calc(mdct, VAR_0->output, VAR_0->coefs[VAR_4]);

        }else if(!(VAR_0->ms_stereo && VAR_4==1))

            memset(VAR_0->output, 0, sizeof(VAR_0->output));



        

        index = (VAR_0->frame_len / 2) + VAR_0->block_pos - n4;

        wma_window(VAR_0, &VAR_0->frame_out[VAR_4][index]);




    

    VAR_0->block_num++;

    VAR_0->block_pos += VAR_0->block_len;

    if (VAR_0->block_pos >= VAR_0->frame_len)

        return 1;

    else

        return 0;

static int FUNC_0(WMACodecContext *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6, VAR_7; int VAR_8[MAX_CHANNELS]; float VAR_9; FFTContext *mdct; #ifdef TRACE
tprintf(VAR_0->avctx, "***decode_block: %d:%d\VAR_1", VAR_0->frame_count - 1, VAR_0->block_num); #endif
if (VAR_0->use_variable_block_len) { VAR_1 = av_log2(VAR_0->nb_block_sizes - 1) + 1; if (VAR_0->reset_block_lengths) { VAR_0->reset_block_lengths = 0; VAR_2 = get_bits(&VAR_0->gb, VAR_1); if (VAR_2 >= VAR_0->nb_block_sizes){ av_log(VAR_0->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2); return -1; VAR_0->prev_block_len_bits = VAR_0->frame_len_bits - VAR_2; VAR_2 = get_bits(&VAR_0->gb, VAR_1); if (VAR_2 >= VAR_0->nb_block_sizes){ av_log(VAR_0->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2); return -1; VAR_0->block_len_bits = VAR_0->frame_len_bits - VAR_2; } else { VAR_0->prev_block_len_bits = VAR_0->block_len_bits; VAR_0->block_len_bits = VAR_0->next_block_len_bits; VAR_2 = get_bits(&VAR_0->gb, VAR_1); if (VAR_2 >= VAR_0->nb_block_sizes){ av_log(VAR_0->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\VAR_1", VAR_0->frame_len_bits - VAR_2); return -1; VAR_0->next_block_len_bits = VAR_0->frame_len_bits - VAR_2; } else { VAR_0->next_block_len_bits = VAR_0->frame_len_bits; VAR_0->prev_block_len_bits = VAR_0->frame_len_bits; VAR_0->block_len_bits = VAR_0->frame_len_bits; if (VAR_0->frame_len_bits - VAR_0->block_len_bits >= VAR_0->nb_block_sizes){ av_log(VAR_0->avctx, AV_LOG_ERROR, "block_len_bits not initialized to VAR_3 valid value\VAR_1"); return -1; VAR_0->block_len = 1 << VAR_0->block_len_bits; if ((VAR_0->block_pos + VAR_0->block_len) > VAR_0->frame_len){ av_log(VAR_0->avctx, AV_LOG_ERROR, "frame_len overflow\VAR_1"); return -1; if (VAR_0->avctx->channels == 2) { VAR_0->ms_stereo = get_bits1(&VAR_0->gb); VAR_2 = 0; for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { VAR_3 = get_bits1(&VAR_0->gb); VAR_0->channel_coded[VAR_4] = VAR_3; VAR_2 |= VAR_3; VAR_5 = VAR_0->frame_len_bits - VAR_0->block_len_bits; if (!VAR_2)
goto next; VAR_7 = 1; for(;;) { VAR_3 = get_bits(&VAR_0->gb, 7); VAR_7 += VAR_3; if (VAR_3 != 127)
break; VAR_6= ff_wma_total_gain_to_bits(VAR_7); VAR_1 = VAR_0->coefs_end[VAR_5] - VAR_0->coefs_start; for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) VAR_8[VAR_4] = VAR_1; if (VAR_0->use_noise_coding) { for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { int i, VAR_1, VAR_3; VAR_1 = VAR_0->exponent_high_sizes[VAR_5]; for(i=0;i<VAR_1;i++) { VAR_3 = get_bits1(&VAR_0->gb); VAR_0->high_band_coded[VAR_4][i] = VAR_3; if (VAR_3)
VAR_8[VAR_4] -= VAR_0->exponent_high_bands[VAR_5][i]; for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { int i, VAR_1, val, code; VAR_1 = VAR_0->exponent_high_sizes[VAR_5]; val = (int)0x80000000; for(i=0;i<VAR_1;i++) { if (VAR_0->high_band_coded[VAR_4][i]) { if (val == (int)0x80000000) { val = get_bits(&VAR_0->gb, 7) - 19; } else { code = get_vlc2(&VAR_0->gb, VAR_0->hgain_vlc.table, HGAINVLCBITS, HGAINMAX); if (code < 0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "hgain vlc invalid\VAR_1"); return -1; val += code - 18; VAR_0->high_band_values[VAR_4][i] = val; if ((VAR_0->block_len_bits == VAR_0->frame_len_bits) ||
get_bits1(&VAR_0->gb)) { for(VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { if (VAR_0->use_exp_vlc) { if (decode_exp_vlc(VAR_0, VAR_4) < 0)
return -1; } else { decode_exp_lsp(VAR_0, VAR_4); VAR_0->exponents_bsize[VAR_4] = VAR_5; for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { int tindex; WMACoef* ptr = &VAR_0->coefs1[VAR_4][0]; tindex = (VAR_4 == 1 && VAR_0->ms_stereo); memset(ptr, 0, VAR_0->block_len * sizeof(WMACoef)); ff_wma_run_level_decode(VAR_0->avctx, &VAR_0->gb, &VAR_0->coef_vlc[tindex],
VAR_0->level_table[tindex], VAR_0->run_table[tindex],
0, ptr, 0, VAR_8[VAR_4],
VAR_0->block_len, VAR_0->frame_len_bits, VAR_6); if (VAR_0->version == 1 && VAR_0->avctx->channels >= 2) { align_get_bits(&VAR_0->gb); { int n4 = VAR_0->block_len / 2; VAR_9 = 1.0 / (float)n4; if (VAR_0->version == 1) { VAR_9 *= sqrt(n4); for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { WMACoef *coefs1; float *coefs, *exponents, mult, mult1, noise; int i, j, VAR_1, n1, last_high_band, esize; float exp_power[HIGH_BAND_MAX_SIZE]; coefs1 = VAR_0->coefs1[VAR_4]; exponents = VAR_0->exponents[VAR_4]; esize = VAR_0->exponents_bsize[VAR_4]; mult = pow(10, VAR_7 * 0.05) / VAR_0->max_exponent[VAR_4]; mult *= VAR_9; coefs = VAR_0->coefs[VAR_4]; if (VAR_0->use_noise_coding) { mult1 = mult; for(i = 0;i < VAR_0->coefs_start; i++) { *coefs++ = VAR_0->noise_table[VAR_0->noise_index] *
exponents[i<<VAR_5>>esize] * mult1; VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1); n1 = VAR_0->exponent_high_sizes[VAR_5]; exponents = VAR_0->exponents[VAR_4] +
(VAR_0->high_band_start[VAR_5]<<VAR_5>>esize); last_high_band = 0; for(j=0;j<n1;j++) { VAR_1 = VAR_0->exponent_high_bands[VAR_0->frame_len_bits -
VAR_0->block_len_bits][j]; if (VAR_0->high_band_coded[VAR_4][j]) { float e2, VAR_2; e2 = 0; for(i = 0;i < VAR_1; i++) { VAR_2 = exponents[i<<VAR_5>>esize]; e2 += VAR_2 * VAR_2; exp_power[j] = e2 / VAR_1; last_high_band = j; tprintf(VAR_0->avctx, "%d: power=%f (%d)\VAR_1", j, exp_power[j], VAR_1); exponents += VAR_1<<VAR_5>>esize; exponents = VAR_0->exponents[VAR_4] + (VAR_0->coefs_start<<VAR_5>>esize); for(j=-1;j<n1;j++) { if (j < 0) { VAR_1 = VAR_0->high_band_start[VAR_5] -
VAR_0->coefs_start; } else { VAR_1 = VAR_0->exponent_high_bands[VAR_0->frame_len_bits -
VAR_0->block_len_bits][j]; if (j >= 0 && VAR_0->high_band_coded[VAR_4][j]) { mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); mult1 = mult1 * pow(10, VAR_0->high_band_values[VAR_4][j] * 0.05); mult1 = mult1 / (VAR_0->max_exponent[VAR_4] * VAR_0->noise_mult); mult1 *= VAR_9; for(i = 0;i < VAR_1; i++) { noise = VAR_0->noise_table[VAR_0->noise_index]; VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ =  noise *
exponents[i<<VAR_5>>esize] * mult1; exponents += VAR_1<<VAR_5>>esize; } else { for(i = 0;i < VAR_1; i++) { noise = VAR_0->noise_table[VAR_0->noise_index]; VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1); *coefs++ = ((*coefs1++) + noise) *
exponents[i<<VAR_5>>esize] * mult; exponents += VAR_1<<VAR_5>>esize; VAR_1 = VAR_0->block_len - VAR_0->coefs_end[VAR_5]; mult1 = mult * exponents[((-1<<VAR_5))>>esize]; for(i = 0; i < VAR_1; i++) { *coefs++ = VAR_0->noise_table[VAR_0->noise_index] * mult1; VAR_0->noise_index = (VAR_0->noise_index + 1) & (NOISE_TAB_SIZE - 1); } else { for(i = 0;i < VAR_0->coefs_start; i++) *coefs++ = 0.0; VAR_1 = VAR_8[VAR_4]; for(i = 0;i < VAR_1; i++) { *coefs++ = coefs1[i] * exponents[i<<VAR_5>>esize] * mult; VAR_1 = VAR_0->block_len - VAR_0->coefs_end[VAR_5]; for(i = 0;i < VAR_1; i++) *coefs++ = 0.0; #ifdef TRACE
for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { if (VAR_0->channel_coded[VAR_4]) { dump_floats(VAR_0, "exponents", 3, VAR_0->exponents[VAR_4], VAR_0->block_len); dump_floats(VAR_0, "coefs", 1, VAR_0->coefs[VAR_4], VAR_0->block_len); #endif
if (VAR_0->ms_stereo && VAR_0->channel_coded[1]) { if (!VAR_0->channel_coded[0]) { tprintf(VAR_0->avctx, "rare ms-stereo case happened\VAR_1"); memset(VAR_0->coefs[0], 0, sizeof(float) * VAR_0->block_len); VAR_0->channel_coded[0] = 1; VAR_0->fdsp.butterflies_float(VAR_0->coefs[0], VAR_0->coefs[1], VAR_0->block_len); next:
mdct = &VAR_0->mdct_ctx[VAR_5]; for (VAR_4 = 0; VAR_4 < VAR_0->avctx->channels; VAR_4++) { int n4, index; n4 = VAR_0->block_len / 2; if(VAR_0->channel_coded[VAR_4]){ mdct->imdct_calc(mdct, VAR_0->output, VAR_0->coefs[VAR_4]); }else if(!(VAR_0->ms_stereo && VAR_4==1)) memset(VAR_0->output, 0, sizeof(VAR_0->output)); index = (VAR_0->frame_len / 2) + VAR_0->block_pos - n4; wma_window(VAR_0, &VAR_0->frame_out[VAR_4][index]); VAR_0->block_num++; VAR_0->block_pos += VAR_0->block_len; if (VAR_0->block_pos >= VAR_0->frame_len)
return 1; else
return 0;