static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,

                                 const uint8_t *buf, int buf_size)

{

    TwinVQFrameData     *bits = &tctx->bits;

    const TwinVQModeTab *mtab = tctx->mtab;

    int channels              = tctx->avctx->channels;

    int sub;

    GetBitContext gb;

    int i, j, k;



    if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate + 8) {

        av_log(avctx, AV_LOG_ERROR,

               "Frame too small (%d bytes). Truncated file?\n", buf_size);

        return AVERROR(EINVAL);

    }



    init_get_bits(&gb, buf, buf_size * 8);

    skip_bits(&gb, get_bits(&gb, 8));



    bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS);



    if (bits->window_type > 8) {

        av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n");

        return AVERROR_INVALIDDATA;

    }



    bits->ftype = ff_twinvq_wtype_to_ftype_table[tctx->bits.window_type];



    sub = mtab->fmode[bits->ftype].sub;



    read_cb_data(tctx, &gb, bits->main_coeffs, bits->ftype);



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

        for (j = 0; j < sub; j++)

            for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++)

                bits->bark1[i][j][k] =

                    get_bits(&gb, mtab->fmode[bits->ftype].bark_n_bit);



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

        for (j = 0; j < sub; j++)

            bits->bark_use_hist[i][j] = get_bits1(&gb);



    if (bits->ftype == TWINVQ_FT_LONG) {

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

            bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);

    } else {

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

            bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);

            for (j = 0; j < sub; j++)

                bits->sub_gain_bits[i * sub + j] = get_bits(&gb,

                                                       TWINVQ_SUB_GAIN_BITS);

        }

    }



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

        bits->lpc_hist_idx[i] = get_bits(&gb, mtab->lsp_bit0);

        bits->lpc_idx1[i]     = get_bits(&gb, mtab->lsp_bit1);



        for (j = 0; j < mtab->lsp_split; j++)

            bits->lpc_idx2[i][j] = get_bits(&gb, mtab->lsp_bit2);

    }



    if (bits->ftype == TWINVQ_FT_LONG) {

        read_cb_data(tctx, &gb, bits->ppc_coeffs, 3);

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

            bits->p_coef[i] = get_bits(&gb, mtab->ppc_period_bit);

            bits->g_coef[i] = get_bits(&gb, mtab->pgain_bit);

        }

    }



    return 0;

}

static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,

                                 const uint8_t *buf, int buf_size)

{

    TwinVQFrameData     *bits = &tctx->bits;

    const TwinVQModeTab *mtab = tctx->mtab;

    int channels              = tctx->avctx->channels;

    int sub;

    GetBitContext gb;

    int i, j, k;



    if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate + 8) {

        av_log(avctx, AV_LOG_ERROR,

               "Frame too small (%d bytes). Truncated file?\n", buf_size);

        return AVERROR(EINVAL);

    }



    init_get_bits(&gb, buf, buf_size * 8);

    skip_bits(&gb, get_bits(&gb, 8));



    bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS);



    if (bits->window_type > 8) {

        av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n");

        return AVERROR_INVALIDDATA;

    }



    bits->ftype = ff_twinvq_wtype_to_ftype_table[tctx->bits.window_type];



    sub = mtab->fmode[bits->ftype].sub;



    read_cb_data(tctx, &gb, bits->main_coeffs, bits->ftype);



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

        for (j = 0; j < sub; j++)

            for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++)

                bits->bark1[i][j][k] =

                    get_bits(&gb, mtab->fmode[bits->ftype].bark_n_bit);



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

        for (j = 0; j < sub; j++)

            bits->bark_use_hist[i][j] = get_bits1(&gb);



    if (bits->ftype == TWINVQ_FT_LONG) {

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

            bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);

    } else {

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

            bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);

            for (j = 0; j < sub; j++)

                bits->sub_gain_bits[i * sub + j] = get_bits(&gb,

                                                       TWINVQ_SUB_GAIN_BITS);

        }

    }



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

        bits->lpc_hist_idx[i] = get_bits(&gb, mtab->lsp_bit0);

        bits->lpc_idx1[i]     = get_bits(&gb, mtab->lsp_bit1);



        for (j = 0; j < mtab->lsp_split; j++)

            bits->lpc_idx2[i][j] = get_bits(&gb, mtab->lsp_bit2);

    }



    if (bits->ftype == TWINVQ_FT_LONG) {

        read_cb_data(tctx, &gb, bits->ppc_coeffs, 3);

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

            bits->p_coef[i] = get_bits(&gb, mtab->ppc_period_bit);

            bits->g_coef[i] = get_bits(&gb, mtab->pgain_bit);

        }

    }



    return 0;

}

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

                                 const uint8_t *VAR_2, int VAR_3)

{

    TwinVQFrameData     *bits = &VAR_1->bits;

    const TwinVQModeTab *VAR_4 = VAR_1->VAR_4;

    int VAR_5              = VAR_1->VAR_0->VAR_5;

    int VAR_6;

    GetBitContext gb;

    int VAR_7, VAR_8, VAR_9;



    if (VAR_3 * 8 < VAR_0->bit_rate * VAR_4->size / VAR_0->sample_rate + 8) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Frame too small (%d bytes). Truncated file?\n", VAR_3);

        return AVERROR(EINVAL);

    }



    init_get_bits(&gb, VAR_2, VAR_3 * 8);

    skip_bits(&gb, get_bits(&gb, 8));



    bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS);



    if (bits->window_type > 8) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid window type, broken sample?\n");

        return AVERROR_INVALIDDATA;

    }



    bits->ftype = ff_twinvq_wtype_to_ftype_table[VAR_1->bits.window_type];



    VAR_6 = VAR_4->fmode[bits->ftype].VAR_6;



    read_cb_data(VAR_1, &gb, bits->main_coeffs, bits->ftype);



    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++)

        for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++)

            for (VAR_9 = 0; VAR_9 < VAR_4->fmode[bits->ftype].bark_n_coef; VAR_9++)

                bits->bark1[VAR_7][VAR_8][VAR_9] =

                    get_bits(&gb, VAR_4->fmode[bits->ftype].bark_n_bit);



    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++)

        for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++)

            bits->bark_use_hist[VAR_7][VAR_8] = get_bits1(&gb);



    if (bits->ftype == TWINVQ_FT_LONG) {

        for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++)

            bits->gain_bits[VAR_7] = get_bits(&gb, TWINVQ_GAIN_BITS);

    } else {

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

            bits->gain_bits[VAR_7] = get_bits(&gb, TWINVQ_GAIN_BITS);

            for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++)

                bits->sub_gain_bits[VAR_7 * VAR_6 + VAR_8] = get_bits(&gb,

                                                       TWINVQ_SUB_GAIN_BITS);

        }

    }



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

        bits->lpc_hist_idx[VAR_7] = get_bits(&gb, VAR_4->lsp_bit0);

        bits->lpc_idx1[VAR_7]     = get_bits(&gb, VAR_4->lsp_bit1);



        for (VAR_8 = 0; VAR_8 < VAR_4->lsp_split; VAR_8++)

            bits->lpc_idx2[VAR_7][VAR_8] = get_bits(&gb, VAR_4->lsp_bit2);

    }



    if (bits->ftype == TWINVQ_FT_LONG) {

        read_cb_data(VAR_1, &gb, bits->ppc_coeffs, 3);

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

            bits->p_coef[VAR_7] = get_bits(&gb, VAR_4->ppc_period_bit);

            bits->g_coef[VAR_7] = get_bits(&gb, VAR_4->pgain_bit);

        }

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, TwinVQContext *VAR_1,
const uint8_t *VAR_2, int VAR_3)
{ TwinVQFrameData     *bits = &VAR_1->bits; const TwinVQModeTab *VAR_4 = VAR_1->VAR_4; int VAR_5              = VAR_1->VAR_0->VAR_5; int VAR_6; GetBitContext gb; int VAR_7, VAR_8, VAR_9; if (VAR_3 * 8 < VAR_0->bit_rate * VAR_4->size / VAR_0->sample_rate + 8) { av_log(VAR_0, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", VAR_3); return AVERROR(EINVAL); } init_get_bits(&gb, VAR_2, VAR_3 * 8); skip_bits(&gb, get_bits(&gb, 8)); bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS); if (bits->window_type > 8) { av_log(VAR_0, AV_LOG_ERROR, "Invalid window type, broken sample?\n"); return AVERROR_INVALIDDATA; } bits->ftype = ff_twinvq_wtype_to_ftype_table[VAR_1->bits.window_type]; VAR_6 = VAR_4->fmode[bits->ftype].VAR_6; read_cb_data(VAR_1, &gb, bits->main_coeffs, bits->ftype); for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++) for (VAR_9 = 0; VAR_9 < VAR_4->fmode[bits->ftype].bark_n_coef; VAR_9++) bits->bark1[VAR_7][VAR_8][VAR_9] =
get_bits(&gb, VAR_4->fmode[bits->ftype].bark_n_bit); for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++) bits->bark_use_hist[VAR_7][VAR_8] = get_bits1(&gb); if (bits->ftype == TWINVQ_FT_LONG) { for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) bits->gain_bits[VAR_7] = get_bits(&gb, TWINVQ_GAIN_BITS); } else { for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { bits->gain_bits[VAR_7] = get_bits(&gb, TWINVQ_GAIN_BITS); for (VAR_8 = 0; VAR_8 < VAR_6; VAR_8++) bits->sub_gain_bits[VAR_7 * VAR_6 + VAR_8] = get_bits(&gb,
TWINVQ_SUB_GAIN_BITS); } } for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { bits->lpc_hist_idx[VAR_7] = get_bits(&gb, VAR_4->lsp_bit0); bits->lpc_idx1[VAR_7]     = get_bits(&gb, VAR_4->lsp_bit1); for (VAR_8 = 0; VAR_8 < VAR_4->lsp_split; VAR_8++) bits->lpc_idx2[VAR_7][VAR_8] = get_bits(&gb, VAR_4->lsp_bit2); } if (bits->ftype == TWINVQ_FT_LONG) { read_cb_data(VAR_1, &gb, bits->ppc_coeffs, 3); for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { bits->p_coef[VAR_7] = get_bits(&gb, VAR_4->ppc_period_bit); bits->g_coef[VAR_7] = get_bits(&gb, VAR_4->pgain_bit); } } return 0; }