static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,

                            int *got_frame_ptr)

{

    WMAVoiceContext *s = ctx->priv_data;

    GetBitContext *gb = &s->gb, s_gb;

    int n, res, n_samples = 480;

    double lsps[MAX_FRAMES][MAX_LSPS];

    const double *mean_lsf = s->lsps == 16 ?

        wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];

    float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];

    float synth[MAX_LSPS + MAX_SFRAMESIZE];

    float *samples;



    memcpy(synth,      s->synth_history,

           s->lsps             * sizeof(*synth));

    memcpy(excitation, s->excitation_history,

           s->history_nsamples * sizeof(*excitation));



    if (s->sframe_cache_size > 0) {

        gb = &s_gb;

        init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);

        s->sframe_cache_size = 0;

    }



    if ((res = check_bits_for_superframe(gb, s)) == 1) {

        *got_frame_ptr = 0;

        return 1;

    } else if (res < 0)

        return res;



    /* First bit is speech/music bit, it differentiates between WMAVoice

     * speech samples (the actual codec) and WMAVoice music samples, which

     * are really WMAPro-in-WMAVoice-superframes. I've never seen those in

     * the wild yet. */

    if (!get_bits1(gb)) {

        avpriv_request_sample(ctx, "WMAPro-in-WMAVoice");

        return AVERROR_PATCHWELCOME;

    }



    /* (optional) nr. of samples in superframe; always <= 480 and >= 0 */

    if (get_bits1(gb)) {

        if ((n_samples = get_bits(gb, 12)) > 480) {

            av_log(ctx, AV_LOG_ERROR,

                   "Superframe encodes >480 samples (%d), not allowed\n",

                   n_samples);

            return AVERROR_INVALIDDATA;

        }

    }

    /* Parse LSPs, if global for the superframe (can also be per-frame). */

    if (s->has_residual_lsps) {

        double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];



        for (n = 0; n < s->lsps; n++)

            prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];



        if (s->lsps == 10) {

            dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);

        } else /* s->lsps == 16 */

            dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);



        for (n = 0; n < s->lsps; n++) {

            lsps[0][n]  = mean_lsf[n] + (a1[n]           - a2[n * 2]);

            lsps[1][n]  = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);

            lsps[2][n] += mean_lsf[n];

        }

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

            stabilize_lsps(lsps[n], s->lsps);

    }



    /* get output buffer */

    frame->nb_samples = 480;

    if ((res = ff_get_buffer(ctx, frame, 0)) < 0)

        return res;

    frame->nb_samples = n_samples;

    samples = (float *)frame->data[0];



    /* Parse frames, optionally preceded by per-frame (independent) LSPs. */

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

        if (!s->has_residual_lsps) {

            int m;



            if (s->lsps == 10) {

                dequant_lsp10i(gb, lsps[n]);

            } else /* s->lsps == 16 */

                dequant_lsp16i(gb, lsps[n]);



            for (m = 0; m < s->lsps; m++)

                lsps[n][m] += mean_lsf[m];

            stabilize_lsps(lsps[n], s->lsps);

        }



        if ((res = synth_frame(ctx, gb, n,

                               &samples[n * MAX_FRAMESIZE],

                               lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],

                               &excitation[s->history_nsamples + n * MAX_FRAMESIZE],

                               &synth[s->lsps + n * MAX_FRAMESIZE]))) {

            *got_frame_ptr = 0;

            return res;

        }

    }



    /* Statistics? FIXME - we don't check for length, a slight overrun

     * will be caught by internal buffer padding, and anything else

     * will be skipped, not read. */

    if (get_bits1(gb)) {

        res = get_bits(gb, 4);

        skip_bits(gb, 10 * (res + 1));

    }



    *got_frame_ptr = 1;



    /* Update history */

    memcpy(s->prev_lsps,           lsps[2],

           s->lsps             * sizeof(*s->prev_lsps));

    memcpy(s->synth_history,      &synth[MAX_SFRAMESIZE],

           s->lsps             * sizeof(*synth));

    memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],

           s->history_nsamples * sizeof(*excitation));

    if (s->do_apf)

        memmove(s->zero_exc_pf,       &s->zero_exc_pf[MAX_SFRAMESIZE],

                s->history_nsamples * sizeof(*s->zero_exc_pf));



    return 0;

}

static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,

                            int *got_frame_ptr)

{

    WMAVoiceContext *s = ctx->priv_data;

    GetBitContext *gb = &s->gb, s_gb;

    int n, res, n_samples = 480;

    double lsps[MAX_FRAMES][MAX_LSPS];

    const double *mean_lsf = s->lsps == 16 ?

        wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];

    float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];

    float synth[MAX_LSPS + MAX_SFRAMESIZE];

    float *samples;



    memcpy(synth,      s->synth_history,

           s->lsps             * sizeof(*synth));

    memcpy(excitation, s->excitation_history,

           s->history_nsamples * sizeof(*excitation));



    if (s->sframe_cache_size > 0) {

        gb = &s_gb;

        init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);

        s->sframe_cache_size = 0;

    }



    if ((res = check_bits_for_superframe(gb, s)) == 1) {

        *got_frame_ptr = 0;

        return 1;

    } else if (res < 0)

        return res;



    







    if (!get_bits1(gb)) {

        avpriv_request_sample(ctx, "WMAPro-in-WMAVoice");

        return AVERROR_PATCHWELCOME;

    }



    

    if (get_bits1(gb)) {

        if ((n_samples = get_bits(gb, 12)) > 480) {

            av_log(ctx, AV_LOG_ERROR,

                   "Superframe encodes >480 samples (%d), not allowed\n",

                   n_samples);

            return AVERROR_INVALIDDATA;

        }

    }

    

    if (s->has_residual_lsps) {

        double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];



        for (n = 0; n < s->lsps; n++)

            prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];



        if (s->lsps == 10) {

            dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);

        } else 

            dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);



        for (n = 0; n < s->lsps; n++) {

            lsps[0][n]  = mean_lsf[n] + (a1[n]           - a2[n * 2]);

            lsps[1][n]  = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);

            lsps[2][n] += mean_lsf[n];

        }

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

            stabilize_lsps(lsps[n], s->lsps);

    }



    

    frame->nb_samples = 480;

    if ((res = ff_get_buffer(ctx, frame, 0)) < 0)

        return res;

    frame->nb_samples = n_samples;

    samples = (float *)frame->data[0];



    

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

        if (!s->has_residual_lsps) {

            int m;



            if (s->lsps == 10) {

                dequant_lsp10i(gb, lsps[n]);

            } else 

                dequant_lsp16i(gb, lsps[n]);



            for (m = 0; m < s->lsps; m++)

                lsps[n][m] += mean_lsf[m];

            stabilize_lsps(lsps[n], s->lsps);

        }



        if ((res = synth_frame(ctx, gb, n,

                               &samples[n * MAX_FRAMESIZE],

                               lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],

                               &excitation[s->history_nsamples + n * MAX_FRAMESIZE],

                               &synth[s->lsps + n * MAX_FRAMESIZE]))) {

            *got_frame_ptr = 0;

            return res;

        }

    }



    





    if (get_bits1(gb)) {

        res = get_bits(gb, 4);

        skip_bits(gb, 10 * (res + 1));

    }



    *got_frame_ptr = 1;



    

    memcpy(s->prev_lsps,           lsps[2],

           s->lsps             * sizeof(*s->prev_lsps));

    memcpy(s->synth_history,      &synth[MAX_SFRAMESIZE],

           s->lsps             * sizeof(*synth));

    memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],

           s->history_nsamples * sizeof(*excitation));

    if (s->do_apf)

        memmove(s->zero_exc_pf,       &s->zero_exc_pf[MAX_SFRAMESIZE],

                s->history_nsamples * sizeof(*s->zero_exc_pf));



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,

                            int *VAR_2)

{

    WMAVoiceContext *s = VAR_0->priv_data;

    GetBitContext *gb = &s->gb, s_gb;

    int VAR_3, VAR_4, VAR_5 = 480;

    double VAR_6[MAX_FRAMES][MAX_LSPS];

    const double *VAR_7 = s->VAR_6 == 16 ?

        wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];

    float VAR_8[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];

    float VAR_9[MAX_LSPS + MAX_SFRAMESIZE];

    float *VAR_10;



    memcpy(VAR_9,      s->synth_history,

           s->VAR_6             * sizeof(*VAR_9));

    memcpy(VAR_8, s->excitation_history,

           s->history_nsamples * sizeof(*VAR_8));



    if (s->sframe_cache_size > 0) {

        gb = &s_gb;

        init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);

        s->sframe_cache_size = 0;

    }



    if ((VAR_4 = check_bits_for_superframe(gb, s)) == 1) {

        *VAR_2 = 0;

        return 1;

    } else if (VAR_4 < 0)

        return VAR_4;



    







    if (!get_bits1(gb)) {

        avpriv_request_sample(VAR_0, "WMAPro-in-WMAVoice");

        return AVERROR_PATCHWELCOME;

    }



    

    if (get_bits1(gb)) {

        if ((VAR_5 = get_bits(gb, 12)) > 480) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "Superframe encodes >480 VAR_10 (%d), not allowed\VAR_3",

                   VAR_5);

            return AVERROR_INVALIDDATA;

        }

    }

    

    if (s->has_residual_lsps) {

        double VAR_11[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];



        for (VAR_3 = 0; VAR_3 < s->VAR_6; VAR_3++)

            VAR_11[VAR_3] = s->VAR_11[VAR_3] - VAR_7[VAR_3];



        if (s->VAR_6 == 10) {

            dequant_lsp10r(gb, VAR_6[2], VAR_11, a1, a2, s->lsp_q_mode);

        } else 

            dequant_lsp16r(gb, VAR_6[2], VAR_11, a1, a2, s->lsp_q_mode);



        for (VAR_3 = 0; VAR_3 < s->VAR_6; VAR_3++) {

            VAR_6[0][VAR_3]  = VAR_7[VAR_3] + (a1[VAR_3]           - a2[VAR_3 * 2]);

            VAR_6[1][VAR_3]  = VAR_7[VAR_3] + (a1[s->VAR_6 + VAR_3] - a2[VAR_3 * 2 + 1]);

            VAR_6[2][VAR_3] += VAR_7[VAR_3];

        }

        for (VAR_3 = 0; VAR_3 < 3; VAR_3++)

            stabilize_lsps(VAR_6[VAR_3], s->VAR_6);

    }



    

    VAR_1->nb_samples = 480;

    if ((VAR_4 = ff_get_buffer(VAR_0, VAR_1, 0)) < 0)

        return VAR_4;

    VAR_1->nb_samples = VAR_5;

    VAR_10 = (float *)VAR_1->data[0];



    

    for (VAR_3 = 0; VAR_3 < 3; VAR_3++) {

        if (!s->has_residual_lsps) {

            int VAR_12;



            if (s->VAR_6 == 10) {

                dequant_lsp10i(gb, VAR_6[VAR_3]);

            } else 

                dequant_lsp16i(gb, VAR_6[VAR_3]);



            for (VAR_12 = 0; VAR_12 < s->VAR_6; VAR_12++)

                VAR_6[VAR_3][VAR_12] += VAR_7[VAR_12];

            stabilize_lsps(VAR_6[VAR_3], s->VAR_6);

        }



        if ((VAR_4 = synth_frame(VAR_0, gb, VAR_3,

                               &VAR_10[VAR_3 * MAX_FRAMESIZE],

                               VAR_6[VAR_3], VAR_3 == 0 ? s->VAR_11 : VAR_6[VAR_3 - 1],

                               &VAR_8[s->history_nsamples + VAR_3 * MAX_FRAMESIZE],

                               &VAR_9[s->VAR_6 + VAR_3 * MAX_FRAMESIZE]))) {

            *VAR_2 = 0;

            return VAR_4;

        }

    }



    





    if (get_bits1(gb)) {

        VAR_4 = get_bits(gb, 4);

        skip_bits(gb, 10 * (VAR_4 + 1));

    }



    *VAR_2 = 1;



    

    memcpy(s->VAR_11,           VAR_6[2],

           s->VAR_6             * sizeof(*s->VAR_11));

    memcpy(s->synth_history,      &VAR_9[MAX_SFRAMESIZE],

           s->VAR_6             * sizeof(*VAR_9));

    memcpy(s->excitation_history, &VAR_8[MAX_SFRAMESIZE],

           s->history_nsamples * sizeof(*VAR_8));

    if (s->do_apf)

        memmove(s->zero_exc_pf,       &s->zero_exc_pf[MAX_SFRAMESIZE],

                s->history_nsamples * sizeof(*s->zero_exc_pf));



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1,
int *VAR_2)
{ WMAVoiceContext *s = VAR_0->priv_data; GetBitContext *gb = &s->gb, s_gb; int VAR_3, VAR_4, VAR_5 = 480; double VAR_6[MAX_FRAMES][MAX_LSPS]; const double *VAR_7 = s->VAR_6 == 16 ?
wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode]; float VAR_8[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12]; float VAR_9[MAX_LSPS + MAX_SFRAMESIZE]; float *VAR_10; memcpy(VAR_9,      s->synth_history,
s->VAR_6             * sizeof(*VAR_9)); memcpy(VAR_8, s->excitation_history,
s->history_nsamples * sizeof(*VAR_8)); if (s->sframe_cache_size > 0) { gb = &s_gb; init_get_bits(gb, s->sframe_cache, s->sframe_cache_size); s->sframe_cache_size = 0; } if ((VAR_4 = check_bits_for_superframe(gb, s)) == 1) { *VAR_2 = 0; return 1; } else if (VAR_4 < 0) return VAR_4; if (!get_bits1(gb)) { avpriv_request_sample(VAR_0, "WMAPro-in-WMAVoice"); return AVERROR_PATCHWELCOME; } if (get_bits1(gb)) { if ((VAR_5 = get_bits(gb, 12)) > 480) { av_log(VAR_0, AV_LOG_ERROR,
"Superframe encodes >480 VAR_10 (%d), not allowed\VAR_3",
VAR_5); return AVERROR_INVALIDDATA; } } if (s->has_residual_lsps) { double VAR_11[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2]; for (VAR_3 = 0; VAR_3 < s->VAR_6; VAR_3++) VAR_11[VAR_3] = s->VAR_11[VAR_3] - VAR_7[VAR_3]; if (s->VAR_6 == 10) { dequant_lsp10r(gb, VAR_6[2], VAR_11, a1, a2, s->lsp_q_mode); } else dequant_lsp16r(gb, VAR_6[2], VAR_11, a1, a2, s->lsp_q_mode); for (VAR_3 = 0; VAR_3 < s->VAR_6; VAR_3++) { VAR_6[0][VAR_3]  = VAR_7[VAR_3] + (a1[VAR_3]           - a2[VAR_3 * 2]); VAR_6[1][VAR_3]  = VAR_7[VAR_3] + (a1[s->VAR_6 + VAR_3] - a2[VAR_3 * 2 + 1]); VAR_6[2][VAR_3] += VAR_7[VAR_3]; } for (VAR_3 = 0; VAR_3 < 3; VAR_3++) stabilize_lsps(VAR_6[VAR_3], s->VAR_6); } VAR_1->nb_samples = 480; if ((VAR_4 = ff_get_buffer(VAR_0, VAR_1, 0)) < 0)
return VAR_4; VAR_1->nb_samples = VAR_5; VAR_10 = (float *)VAR_1->data[0]; for (VAR_3 = 0; VAR_3 < 3; VAR_3++) { if (!s->has_residual_lsps) { int VAR_12; if (s->VAR_6 == 10) { dequant_lsp10i(gb, VAR_6[VAR_3]); } else dequant_lsp16i(gb, VAR_6[VAR_3]); for (VAR_12 = 0; VAR_12 < s->VAR_6; VAR_12++) VAR_6[VAR_3][VAR_12] += VAR_7[VAR_12]; stabilize_lsps(VAR_6[VAR_3], s->VAR_6); } if ((VAR_4 = synth_frame(VAR_0, gb, VAR_3,
&VAR_10[VAR_3 * MAX_FRAMESIZE],
VAR_6[VAR_3], VAR_3 == 0 ? s->VAR_11 : VAR_6[VAR_3 - 1],
&VAR_8[s->history_nsamples + VAR_3 * MAX_FRAMESIZE],
&VAR_9[s->VAR_6 + VAR_3 * MAX_FRAMESIZE]))) { *VAR_2 = 0; return VAR_4; } } if (get_bits1(gb)) { VAR_4 = get_bits(gb, 4); skip_bits(gb, 10 * (VAR_4 + 1)); } *VAR_2 = 1; memcpy(s->VAR_11,           VAR_6[2],
s->VAR_6             * sizeof(*s->VAR_11)); memcpy(s->synth_history,      &VAR_9[MAX_SFRAMESIZE],
s->VAR_6             * sizeof(*VAR_9)); memcpy(s->excitation_history, &VAR_8[MAX_SFRAMESIZE],
s->history_nsamples * sizeof(*VAR_8)); if (s->do_apf)
memmove(s->zero_exc_pf,       &s->zero_exc_pf[MAX_SFRAMESIZE],
s->history_nsamples * sizeof(*s->zero_exc_pf)); return 0; }