static int encode_superframe(AVCodecContext *avctx,

                            unsigned char *buf, int buf_size, void *data){

    WMACodecContext *s = avctx->priv_data;

    const short *samples = data;

    int i, total_gain;



    s->block_len_bits= s->frame_len_bits; //required by non variable block len

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



    apply_window_and_mdct(avctx, samples, avctx->frame_size);



    if (s->ms_stereo) {

        float a, b;

        int i;



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

            a = s->coefs[0][i]*0.5;

            b = s->coefs[1][i]*0.5;

            s->coefs[0][i] = a + b;

            s->coefs[1][i] = a - b;

        }

    }



    if (buf_size < 2 * MAX_CODED_SUPERFRAME_SIZE) {

        av_log(avctx, AV_LOG_ERROR, "output buffer size is too small\n");

        return AVERROR(EINVAL);

    }



#if 1

    total_gain= 128;

    for(i=64; i; i>>=1){

        int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);

        if(error<0)

            total_gain-= i;

    }

#else

    total_gain= 90;

    best= encode_frame(s, s->coefs, buf, buf_size, total_gain);

    for(i=32; i; i>>=1){

        int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);

        int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i);

        av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain);

        if(scoreL < FFMIN(best, scoreR)){

            best = scoreL;

            total_gain -= i;

        }else if(scoreR < best){

            best = scoreR;

            total_gain += i;

        }

    }

#endif



    if ((i = encode_frame(s, s->coefs, buf, buf_size, total_gain)) >= 0) {

        av_log(avctx, AV_LOG_ERROR, "required frame size too large. please "

               "use a higher bit rate.\n");

        return AVERROR(EINVAL);

    }

    assert((put_bits_count(&s->pb) & 7) == 0);

    while (i++)

        put_bits(&s->pb, 8, 'N');



    flush_put_bits(&s->pb);

    return s->block_align;

}

static int encode_superframe(AVCodecContext *avctx,

                            unsigned char *buf, int buf_size, void *data){

    WMACodecContext *s = avctx->priv_data;

    const short *samples = data;

    int i, total_gain;



    s->block_len_bits= s->frame_len_bits; 

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



    apply_window_and_mdct(avctx, samples, avctx->frame_size);



    if (s->ms_stereo) {

        float a, b;

        int i;



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

            a = s->coefs[0][i]*0.5;

            b = s->coefs[1][i]*0.5;

            s->coefs[0][i] = a + b;

            s->coefs[1][i] = a - b;

        }

    }



    if (buf_size < 2 * MAX_CODED_SUPERFRAME_SIZE) {

        av_log(avctx, AV_LOG_ERROR, "output buffer size is too small\n");

        return AVERROR(EINVAL);

    }



#if 1

    total_gain= 128;

    for(i=64; i; i>>=1){

        int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);

        if(error<0)

            total_gain-= i;

    }

#else

    total_gain= 90;

    best= encode_frame(s, s->coefs, buf, buf_size, total_gain);

    for(i=32; i; i>>=1){

        int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);

        int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i);

        av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain);

        if(scoreL < FFMIN(best, scoreR)){

            best = scoreL;

            total_gain -= i;

        }else if(scoreR < best){

            best = scoreR;

            total_gain += i;

        }

    }

#endif



    if ((i = encode_frame(s, s->coefs, buf, buf_size, total_gain)) >= 0) {

        av_log(avctx, AV_LOG_ERROR, "required frame size too large. please "

               "use a higher bit rate.\n");

        return AVERROR(EINVAL);

    }

    assert((put_bits_count(&s->pb) & 7) == 0);

    while (i++)

        put_bits(&s->pb, 8, 'N');



    flush_put_bits(&s->pb);

    return s->block_align;

}

    if ((i = encode_frame(s, s->coefs, buf, buf_size, total_gain)) >= 0) {         av_log(avctx, AV_LOG_ERROR, "required frame size too large. please "                "use a higher bit rate.\n");         return AVERROR(EINVAL);     while (i++)
static int FUNC_0(AVCodecContext *VAR_0,

                            unsigned char *VAR_1, int VAR_2, void *VAR_3){

    WMACodecContext *s = VAR_0->priv_data;

    const short *VAR_4 = VAR_3;

    int VAR_9, VAR_6;



    s->block_len_bits= s->frame_len_bits; 

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



    apply_window_and_mdct(VAR_0, VAR_4, VAR_0->frame_size);



    if (s->ms_stereo) {

        float VAR_7, VAR_8;

        int VAR_9;



        for(VAR_9 = 0; VAR_9 < s->block_len; VAR_9++) {

            VAR_7 = s->coefs[0][VAR_9]*0.5;

            VAR_8 = s->coefs[1][VAR_9]*0.5;

            s->coefs[0][VAR_9] = VAR_7 + VAR_8;

            s->coefs[1][VAR_9] = VAR_7 - VAR_8;

        }

    }



    if (VAR_2 < 2 * MAX_CODED_SUPERFRAME_SIZE) {

        av_log(VAR_0, AV_LOG_ERROR, "output buffer size is too small\n");

        return AVERROR(EINVAL);

    }



#if 1

    VAR_6= 128;

    for(VAR_9=64; VAR_9; VAR_9>>=1){

        int VAR_9= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6-VAR_9);

        if(VAR_9<0)

            VAR_6-= VAR_9;

    }

#else

    VAR_6= 90;

    best= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6);

    for(VAR_9=32; VAR_9; VAR_9>>=1){

        int scoreL= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6-VAR_9);

        int scoreR= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6+VAR_9);

        av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, VAR_6);

        if(scoreL < FFMIN(best, scoreR)){

            best = scoreL;

            VAR_6 -= VAR_9;

        }else if(scoreR < best){

            best = scoreR;

            VAR_6 += VAR_9;

        }

    }

#endif



    if ((VAR_9 = encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6)) >= 0) {

        av_log(VAR_0, AV_LOG_ERROR, "required frame size too large. please "

               "use VAR_7 higher bit rate.\n");

        return AVERROR(EINVAL);

    }

    assert((put_bits_count(&s->pb) & 7) == 0);

    while (VAR_9++)

        put_bits(&s->pb, 8, 'N');



    flush_put_bits(&s->pb);

    return s->block_align;

}

static int FUNC_0(AVCodecContext *VAR_0,
unsigned char *VAR_1, int VAR_2, void *VAR_3){ WMACodecContext *s = VAR_0->priv_data; const short *VAR_4 = VAR_3; int VAR_9, VAR_6; s->block_len_bits= s->frame_len_bits; s->block_len = 1 << s->block_len_bits; apply_window_and_mdct(VAR_0, VAR_4, VAR_0->frame_size); if (s->ms_stereo) { float VAR_7, VAR_8; int VAR_9; for(VAR_9 = 0; VAR_9 < s->block_len; VAR_9++) { VAR_7 = s->coefs[0][VAR_9]*0.5; VAR_8 = s->coefs[1][VAR_9]*0.5; s->coefs[0][VAR_9] = VAR_7 + VAR_8; s->coefs[1][VAR_9] = VAR_7 - VAR_8; } } if (VAR_2 < 2 * MAX_CODED_SUPERFRAME_SIZE) { av_log(VAR_0, AV_LOG_ERROR, "output buffer size is too small\n"); return AVERROR(EINVAL); } #if 1
VAR_6= 128; for(VAR_9=64; VAR_9; VAR_9>>=1){ int VAR_9= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6-VAR_9); if(VAR_9<0)
VAR_6-= VAR_9; } #else
VAR_6= 90; best= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6); for(VAR_9=32; VAR_9; VAR_9>>=1){ int scoreL= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6-VAR_9); int scoreR= encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6+VAR_9); av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, VAR_6); if(scoreL < FFMIN(best, scoreR)){ best = scoreL; VAR_6 -= VAR_9; }else if(scoreR < best){ best = scoreR; VAR_6 += VAR_9; } } #endif
if ((VAR_9 = encode_frame(s, s->coefs, VAR_1, VAR_2, VAR_6)) >= 0) { av_log(VAR_0, AV_LOG_ERROR, "required frame size too large. please "
"use VAR_7 higher bit rate.\n"); return AVERROR(EINVAL); } assert((put_bits_count(&s->pb) & 7) == 0); while (VAR_9++)
put_bits(&s->pb, 8, 'N'); flush_put_bits(&s->pb); return s->block_align; }