static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                              const AVFrame *frame, int *got_packet_ptr)

{

    static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};

    static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};

    RA144Context *ractx = avctx->priv_data;

    PutBitContext pb;

    int32_t lpc_data[NBLOCKS * BLOCKSIZE];

    int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER];

    int shift[LPC_ORDER];

    int16_t block_coefs[NBLOCKS][LPC_ORDER];

    int lpc_refl[LPC_ORDER];    /**< reflection coefficients of the frame */

    unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */

    const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;

    int energy = 0;

    int i, idx, ret;



    if (ractx->last_frame)

        return 0;



    if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE)))

        return ret;



    /**

     * Since the LPC coefficients are calculated on a frame centered over the

     * fourth subframe, to encode a given frame, data from the next frame is

     * needed. In each call to this function, the previous frame (whose data are

     * saved in the encoder context) is encoded, and data from the current frame

     * are saved in the encoder context to be used in the next function call.

     */

    for (i = 0; i < (2 * BLOCKSIZE + BLOCKSIZE / 2); i++) {

        lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i];

        energy += (lpc_data[i] * lpc_data[i]) >> 4;

    }

    if (frame) {

        int j;

        for (j = 0; j < frame->nb_samples && i < NBLOCKS * BLOCKSIZE; i++, j++) {

            lpc_data[i] = samples[j] >> 2;

            energy += (lpc_data[i] * lpc_data[i]) >> 4;

        }

    }

    if (i < NBLOCKS * BLOCKSIZE)

        memset(&lpc_data[i], 0, (NBLOCKS * BLOCKSIZE - i) * sizeof(*lpc_data));

    energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab,

                                    32)];



    ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,

                      LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON,

                      0, ORDER_METHOD_EST, 12, 0);

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

        block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<

                                        (12 - shift[LPC_ORDER - 1]));



    /**

     * TODO: apply perceptual weighting of the input speech through bandwidth

     * expansion of the LPC filter.

     */



    if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {

        /**

         * The filter is unstable: use the coefficients of the previous frame.

         */

        ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);

        if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {

            /* the filter is still unstable. set reflection coeffs to zero. */

            memset(lpc_refl, 0, sizeof(lpc_refl));

        }

    }

    init_put_bits(&pb, avpkt->data, avpkt->size);

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

        idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]);

        put_bits(&pb, bit_sizes[i], idx);

        lpc_refl[i] = ff_lpc_refl_cb[i][idx];

    }

    ractx->lpc_refl_rms[0] = ff_rms(lpc_refl);

    ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);

    refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy);

    refl_rms[1] = ff_interp(ractx, block_coefs[1], 2,

                            energy <= ractx->old_energy,

                            ff_t_sqrt(energy * ractx->old_energy) >> 12);

    refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy);

    refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy);

    ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]);

    put_bits(&pb, 5, quantize(energy, ff_energy_tab, 32));

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

        ra144_encode_subblock(ractx, ractx->curr_block + i * BLOCKSIZE,

                              block_coefs[i], refl_rms[i], &pb);

    flush_put_bits(&pb);

    ractx->old_energy = energy;

    ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];

    FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);



    /* copy input samples to current block for processing in next call */

    i = 0;

    if (frame) {

        for (; i < frame->nb_samples; i++)

            ractx->curr_block[i] = samples[i] >> 2;



        if ((ret = ff_af_queue_add(&ractx->afq, frame)) < 0)

            return ret;

    } else

        ractx->last_frame = 1;

    memset(&ractx->curr_block[i], 0,

           (NBLOCKS * BLOCKSIZE - i) * sizeof(*ractx->curr_block));



    /* Get the next frame pts/duration */

    ff_af_queue_remove(&ractx->afq, avctx->frame_size, &avpkt->pts,

                       &avpkt->duration);



    avpkt->size = FRAMESIZE;

    *got_packet_ptr = 1;

    return 0;

}

static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                              const AVFrame *frame, int *got_packet_ptr)

{

    static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};

    static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};

    RA144Context *ractx = avctx->priv_data;

    PutBitContext pb;

    int32_t lpc_data[NBLOCKS * BLOCKSIZE];

    int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER];

    int shift[LPC_ORDER];

    int16_t block_coefs[NBLOCKS][LPC_ORDER];

    int lpc_refl[LPC_ORDER];    

    unsigned int refl_rms[NBLOCKS]; 

    const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;

    int energy = 0;

    int i, idx, ret;



    if (ractx->last_frame)

        return 0;



    if ((ret = ff_alloc_packet2(avctx, avpkt, FRAMESIZE)))

        return ret;



    













    for (i = 0; i < (2 * BLOCKSIZE + BLOCKSIZE / 2); i++) {

        lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i];

        energy += (lpc_data[i] * lpc_data[i]) >> 4;

    }

    if (frame) {

        int j;

        for (j = 0; j < frame->nb_samples && i < NBLOCKS * BLOCKSIZE; i++, j++) {

            lpc_data[i] = samples[j] >> 2;

            energy += (lpc_data[i] * lpc_data[i]) >> 4;

        }

    }

    if (i < NBLOCKS * BLOCKSIZE)

        memset(&lpc_data[i], 0, (NBLOCKS * BLOCKSIZE - i) * sizeof(*lpc_data));

    energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab,

                                    32)];



    ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,

                      LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON,

                      0, ORDER_METHOD_EST, 12, 0);

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

        block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<

                                        (12 - shift[LPC_ORDER - 1]));



    









    if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {

        





        ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);

        if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {

            

            memset(lpc_refl, 0, sizeof(lpc_refl));

        }

    }

    init_put_bits(&pb, avpkt->data, avpkt->size);

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

        idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]);

        put_bits(&pb, bit_sizes[i], idx);

        lpc_refl[i] = ff_lpc_refl_cb[i][idx];

    }

    ractx->lpc_refl_rms[0] = ff_rms(lpc_refl);

    ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);

    refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy);

    refl_rms[1] = ff_interp(ractx, block_coefs[1], 2,

                            energy <= ractx->old_energy,

                            ff_t_sqrt(energy * ractx->old_energy) >> 12);

    refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy);

    refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy);

    ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]);

    put_bits(&pb, 5, quantize(energy, ff_energy_tab, 32));

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

        ra144_encode_subblock(ractx, ractx->curr_block + i * BLOCKSIZE,

                              block_coefs[i], refl_rms[i], &pb);

    flush_put_bits(&pb);

    ractx->old_energy = energy;

    ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];

    FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);



    

    i = 0;

    if (frame) {

        for (; i < frame->nb_samples; i++)

            ractx->curr_block[i] = samples[i] >> 2;



        if ((ret = ff_af_queue_add(&ractx->afq, frame)) < 0)

            return ret;

    } else

        ractx->last_frame = 1;

    memset(&ractx->curr_block[i], 0,

           (NBLOCKS * BLOCKSIZE - i) * sizeof(*ractx->curr_block));



    

    ff_af_queue_remove(&ractx->afq, avctx->frame_size, &avpkt->pts,

                       &avpkt->duration);



    avpkt->size = FRAMESIZE;

    *got_packet_ptr = 1;

    return 0;

}

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

                              const AVFrame *VAR_2, int *VAR_3)

{

    static const uint8_t VAR_4[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};

    static const uint8_t VAR_5[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};

    RA144Context *ractx = VAR_0->priv_data;

    PutBitContext pb;

    int32_t lpc_data[NBLOCKS * BLOCKSIZE];

    int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER];

    int VAR_6[LPC_ORDER];

    int16_t block_coefs[NBLOCKS][LPC_ORDER];

    int VAR_7[LPC_ORDER];    

    unsigned int VAR_8[NBLOCKS]; 

    const int16_t *VAR_9 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL;

    int VAR_10 = 0;

    int VAR_11, VAR_12, VAR_13;



    if (ractx->last_frame)

        return 0;



    if ((VAR_13 = ff_alloc_packet2(VAR_0, VAR_1, FRAMESIZE)))

        return VAR_13;



    













    for (VAR_11 = 0; VAR_11 < (2 * BLOCKSIZE + BLOCKSIZE / 2); VAR_11++) {

        lpc_data[VAR_11] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + VAR_11];

        VAR_10 += (lpc_data[VAR_11] * lpc_data[VAR_11]) >> 4;

    }

    if (VAR_2) {

        int VAR_14;

        for (VAR_14 = 0; VAR_14 < VAR_2->nb_samples && VAR_11 < NBLOCKS * BLOCKSIZE; VAR_11++, VAR_14++) {

            lpc_data[VAR_11] = VAR_9[VAR_14] >> 2;

            VAR_10 += (lpc_data[VAR_11] * lpc_data[VAR_11]) >> 4;

        }

    }

    if (VAR_11 < NBLOCKS * BLOCKSIZE)

        memset(&lpc_data[VAR_11], 0, (NBLOCKS * BLOCKSIZE - VAR_11) * sizeof(*lpc_data));

    VAR_10 = ff_energy_tab[quantize(ff_t_sqrt(VAR_10 >> 5) >> 10, ff_energy_tab,

                                    32)];



    ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,

                      LPC_ORDER, 16, lpc_coefs, VAR_6, FF_LPC_TYPE_LEVINSON,

                      0, ORDER_METHOD_EST, 12, 0);

    for (VAR_11 = 0; VAR_11 < LPC_ORDER; VAR_11++)

        block_coefs[NBLOCKS - 1][VAR_11] = -(lpc_coefs[LPC_ORDER - 1][VAR_11] <<

                                        (12 - VAR_6[LPC_ORDER - 1]));



    









    if (ff_eval_refl(VAR_7, block_coefs[NBLOCKS - 1], VAR_0)) {

        





        ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);

        if (ff_eval_refl(VAR_7, block_coefs[NBLOCKS - 1], VAR_0)) {

            

            memset(VAR_7, 0, sizeof(VAR_7));

        }

    }

    init_put_bits(&pb, VAR_1->data, VAR_1->size);

    for (VAR_11 = 0; VAR_11 < LPC_ORDER; VAR_11++) {

        VAR_12 = quantize(VAR_7[VAR_11], ff_lpc_refl_cb[VAR_11], VAR_4[VAR_11]);

        put_bits(&pb, VAR_5[VAR_11], VAR_12);

        VAR_7[VAR_11] = ff_lpc_refl_cb[VAR_11][VAR_12];

    }

    ractx->lpc_refl_rms[0] = ff_rms(VAR_7);

    ff_eval_coefs(ractx->lpc_coef[0], VAR_7);

    VAR_8[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy);

    VAR_8[1] = ff_interp(ractx, block_coefs[1], 2,

                            VAR_10 <= ractx->old_energy,

                            ff_t_sqrt(VAR_10 * ractx->old_energy) >> 12);

    VAR_8[2] = ff_interp(ractx, block_coefs[2], 3, 0, VAR_10);

    VAR_8[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], VAR_10);

    ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]);

    put_bits(&pb, 5, quantize(VAR_10, ff_energy_tab, 32));

    for (VAR_11 = 0; VAR_11 < NBLOCKS; VAR_11++)

        ra144_encode_subblock(ractx, ractx->curr_block + VAR_11 * BLOCKSIZE,

                              block_coefs[VAR_11], VAR_8[VAR_11], &pb);

    flush_put_bits(&pb);

    ractx->old_energy = VAR_10;

    ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];

    FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);



    

    VAR_11 = 0;

    if (VAR_2) {

        for (; VAR_11 < VAR_2->nb_samples; VAR_11++)

            ractx->curr_block[VAR_11] = VAR_9[VAR_11] >> 2;



        if ((VAR_13 = ff_af_queue_add(&ractx->afq, VAR_2)) < 0)

            return VAR_13;

    } else

        ractx->last_frame = 1;

    memset(&ractx->curr_block[VAR_11], 0,

           (NBLOCKS * BLOCKSIZE - VAR_11) * sizeof(*ractx->curr_block));



    

    ff_af_queue_remove(&ractx->afq, VAR_0->frame_size, &VAR_1->pts,

                       &VAR_1->duration);



    VAR_1->size = FRAMESIZE;

    *VAR_3 = 1;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ static const uint8_t VAR_4[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4}; static const uint8_t VAR_5[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; RA144Context *ractx = VAR_0->priv_data; PutBitContext pb; int32_t lpc_data[NBLOCKS * BLOCKSIZE]; int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER]; int VAR_6[LPC_ORDER]; int16_t block_coefs[NBLOCKS][LPC_ORDER]; int VAR_7[LPC_ORDER]; unsigned int VAR_8[NBLOCKS]; const int16_t *VAR_9 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL; int VAR_10 = 0; int VAR_11, VAR_12, VAR_13; if (ractx->last_frame)
return 0; if ((VAR_13 = ff_alloc_packet2(VAR_0, VAR_1, FRAMESIZE)))
return VAR_13; for (VAR_11 = 0; VAR_11 < (2 * BLOCKSIZE + BLOCKSIZE / 2); VAR_11++) { lpc_data[VAR_11] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + VAR_11]; VAR_10 += (lpc_data[VAR_11] * lpc_data[VAR_11]) >> 4; } if (VAR_2) { int VAR_14; for (VAR_14 = 0; VAR_14 < VAR_2->nb_samples && VAR_11 < NBLOCKS * BLOCKSIZE; VAR_11++, VAR_14++) { lpc_data[VAR_11] = VAR_9[VAR_14] >> 2; VAR_10 += (lpc_data[VAR_11] * lpc_data[VAR_11]) >> 4; } } if (VAR_11 < NBLOCKS * BLOCKSIZE)
memset(&lpc_data[VAR_11], 0, (NBLOCKS * BLOCKSIZE - VAR_11) * sizeof(*lpc_data)); VAR_10 = ff_energy_tab[quantize(ff_t_sqrt(VAR_10 >> 5) >> 10, ff_energy_tab,
32)]; ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,
LPC_ORDER, 16, lpc_coefs, VAR_6, FF_LPC_TYPE_LEVINSON,
0, ORDER_METHOD_EST, 12, 0); for (VAR_11 = 0; VAR_11 < LPC_ORDER; VAR_11++) block_coefs[NBLOCKS - 1][VAR_11] = -(lpc_coefs[LPC_ORDER - 1][VAR_11] <<
(12 - VAR_6[LPC_ORDER - 1])); if (ff_eval_refl(VAR_7, block_coefs[NBLOCKS - 1], VAR_0)) { ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]); if (ff_eval_refl(VAR_7, block_coefs[NBLOCKS - 1], VAR_0)) { memset(VAR_7, 0, sizeof(VAR_7)); } } init_put_bits(&pb, VAR_1->data, VAR_1->size); for (VAR_11 = 0; VAR_11 < LPC_ORDER; VAR_11++) { VAR_12 = quantize(VAR_7[VAR_11], ff_lpc_refl_cb[VAR_11], VAR_4[VAR_11]); put_bits(&pb, VAR_5[VAR_11], VAR_12); VAR_7[VAR_11] = ff_lpc_refl_cb[VAR_11][VAR_12]; } ractx->lpc_refl_rms[0] = ff_rms(VAR_7); ff_eval_coefs(ractx->lpc_coef[0], VAR_7); VAR_8[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy); VAR_8[1] = ff_interp(ractx, block_coefs[1], 2,
VAR_10 <= ractx->old_energy,
ff_t_sqrt(VAR_10 * ractx->old_energy) >> 12); VAR_8[2] = ff_interp(ractx, block_coefs[2], 3, 0, VAR_10); VAR_8[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], VAR_10); ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]); put_bits(&pb, 5, quantize(VAR_10, ff_energy_tab, 32)); for (VAR_11 = 0; VAR_11 < NBLOCKS; VAR_11++) ra144_encode_subblock(ractx, ractx->curr_block + VAR_11 * BLOCKSIZE,
block_coefs[VAR_11], VAR_8[VAR_11], &pb); flush_put_bits(&pb); ractx->old_energy = VAR_10; ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0]; FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); VAR_11 = 0; if (VAR_2) { for (; VAR_11 < VAR_2->nb_samples; VAR_11++) ractx->curr_block[VAR_11] = VAR_9[VAR_11] >> 2; if ((VAR_13 = ff_af_queue_add(&ractx->afq, VAR_2)) < 0)
return VAR_13; } else ractx->last_frame = 1; memset(&ractx->curr_block[VAR_11], 0,
(NBLOCKS * BLOCKSIZE - VAR_11) * sizeof(*ractx->curr_block)); ff_af_queue_remove(&ractx->afq, VAR_0->frame_size, &VAR_1->pts,
&VAR_1->duration); VAR_1->size = FRAMESIZE; *VAR_3 = 1; return 0; }