static void quantize_lpc_coefs(double *lpc_in, int order, int precision,
                               int32_t *lpc_out, int *shift, int max_shift, int zero_shift)
{
    int i;
    double cmax, error;
    int32_t qmax;
    int sh;
    qmax = (1 << (precision - 1)) - 1;
    cmax = 0.0;
    for(i=0; i<order; i++) {
        cmax= FFMAX(cmax, fabs(lpc_in[i]));
    }
    if(cmax * (1 << max_shift) < 1.0) {
        *shift = zero_shift;
        memset(lpc_out, 0, sizeof(int32_t) * order);
        return;
    }
    sh = max_shift;
    while((cmax * (1 << sh) > qmax) && (sh > 0)) {
        sh--;
    }
    if(sh == 0 && cmax > qmax) {
        double scale = ((double)qmax) / cmax;
        for(i=0; i<order; i++) {
            lpc_in[i] *= scale;
        }
    }
    error=0;
    for(i=0; i<order; i++) {
        error -= lpc_in[i] * (1 << sh);
        lpc_out[i] = av_clip(lrintf(error), -qmax, qmax);
        error -= lpc_out[i];
    }
    *shift = sh;
}
['static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame,\n                              int buf_size, void *data)\n{\n    static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4};\n    static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};\n    RA144Context *ractx;\n    PutBitContext pb;\n    int32_t lpc_data[NBLOCKS * BLOCKSIZE];\n    int32_t lpc_coefs[LPC_ORDER][MAX_LPC_ORDER];\n    int shift[LPC_ORDER];\n    int16_t block_coefs[NBLOCKS][LPC_ORDER];\n    int lpc_refl[LPC_ORDER];\n    unsigned int refl_rms[NBLOCKS];\n    int energy = 0;\n    int i, idx;\n    if (buf_size < FRAMESIZE) {\n        av_log(avctx, AV_LOG_ERROR, "output buffer too small\\n");\n        return 0;\n    }\n    ractx = avctx->priv_data;\n    for (i = 0; i < (2 * BLOCKSIZE + BLOCKSIZE / 2); i++) {\n        lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i];\n        energy += (lpc_data[i] * lpc_data[i]) >> 4;\n    }\n    for (i = 2 * BLOCKSIZE + BLOCKSIZE / 2; i < NBLOCKS * BLOCKSIZE; i++) {\n        lpc_data[i] = *((int16_t *)data + i - 2 * BLOCKSIZE - BLOCKSIZE / 2) >>\n                      2;\n        energy += (lpc_data[i] * lpc_data[i]) >> 4;\n    }\n    energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab,\n                                    32)];\n    ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER,\n                      LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON,\n                      0, ORDER_METHOD_EST, 12, 0);\n    for (i = 0; i < LPC_ORDER; i++)\n        block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] <<\n                                        (12 - shift[LPC_ORDER - 1]));\n    if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) {\n        ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]);\n        ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx);\n    }\n    init_put_bits(&pb, frame, buf_size);\n    for (i = 0; i < LPC_ORDER; i++) {\n        idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]);\n        put_bits(&pb, bit_sizes[i], idx);\n        lpc_refl[i] = ff_lpc_refl_cb[i][idx];\n    }\n    ractx->lpc_refl_rms[0] = ff_rms(lpc_refl);\n    ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);\n    refl_rms[0] = ff_interp(ractx, block_coefs[0], 1, 1, ractx->old_energy);\n    refl_rms[1] = ff_interp(ractx, block_coefs[1], 2,\n                            energy <= ractx->old_energy,\n                            ff_t_sqrt(energy * ractx->old_energy) >> 12);\n    refl_rms[2] = ff_interp(ractx, block_coefs[2], 3, 0, energy);\n    refl_rms[3] = ff_rescale_rms(ractx->lpc_refl_rms[0], energy);\n    ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[0]);\n    put_bits(&pb, 5, quantize(energy, ff_energy_tab, 32));\n    for (i = 0; i < NBLOCKS; i++)\n        ra144_encode_subblock(ractx, ractx->curr_block + i * BLOCKSIZE,\n                              block_coefs[i], refl_rms[i], &pb);\n    flush_put_bits(&pb);\n    ractx->old_energy = energy;\n    ractx->lpc_refl_rms[1] = ractx->lpc_refl_rms[0];\n    FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);\n    for (i = 0; i < NBLOCKS * BLOCKSIZE; i++)\n        ractx->curr_block[i] = *((int16_t *)data + i) >> 2;\n    return FRAMESIZE;\n}', 'int ff_lpc_calc_coefs(LPCContext *s,\n                      const int32_t *samples, int blocksize, int min_order,\n                      int max_order, int precision,\n                      int32_t coefs[][MAX_LPC_ORDER], int *shift,\n                      enum FFLPCType lpc_type, int lpc_passes,\n                      int omethod, int max_shift, int zero_shift)\n{\n    double autoc[MAX_LPC_ORDER+1];\n    double ref[MAX_LPC_ORDER];\n    double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER];\n    int i, j, pass;\n    int opt_order;\n    assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&\n           lpc_type > FF_LPC_TYPE_FIXED);\n    if (blocksize != s->blocksize || max_order != s->max_order ||\n        lpc_type  != s->lpc_type) {\n        ff_lpc_end(s);\n        ff_lpc_init(s, blocksize, max_order, lpc_type);\n    }\n    if (lpc_type == FF_LPC_TYPE_LEVINSON) {\n        double *windowed_samples = s->windowed_samples + max_order;\n        s->lpc_apply_welch_window(samples, blocksize, windowed_samples);\n        s->lpc_compute_autocorr(windowed_samples, blocksize, max_order, autoc);\n        compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1);\n        for(i=0; i<max_order; i++)\n            ref[i] = fabs(lpc[i][i]);\n    } else if (lpc_type == FF_LPC_TYPE_CHOLESKY) {\n        LLSModel m[2];\n        double var[MAX_LPC_ORDER+1], av_uninit(weight);\n        for(pass=0; pass<lpc_passes; pass++){\n            av_init_lls(&m[pass&1], max_order);\n            weight=0;\n            for(i=max_order; i<blocksize; i++){\n                for(j=0; j<=max_order; j++)\n                    var[j]= samples[i-j];\n                if(pass){\n                    double eval, inv, rinv;\n                    eval= av_evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);\n                    eval= (512>>pass) + fabs(eval - var[0]);\n                    inv = 1/eval;\n                    rinv = sqrt(inv);\n                    for(j=0; j<=max_order; j++)\n                        var[j] *= rinv;\n                    weight += inv;\n                }else\n                    weight++;\n                av_update_lls(&m[pass&1], var, 1.0);\n            }\n            av_solve_lls(&m[pass&1], 0.001, 0);\n        }\n        for(i=0; i<max_order; i++){\n            for(j=0; j<max_order; j++)\n                lpc[i][j]=-m[(pass-1)&1].coeff[i][j];\n            ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000;\n        }\n        for(i=max_order-1; i>0; i--)\n            ref[i] = ref[i-1] - ref[i];\n    }\n    opt_order = max_order;\n    if(omethod == ORDER_METHOD_EST) {\n        opt_order = estimate_best_order(ref, min_order, max_order);\n        i = opt_order-1;\n        quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);\n    } else {\n        for(i=min_order-1; i<max_order; i++) {\n            quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);\n        }\n    }\n    return opt_order;\n}', 'static void quantize_lpc_coefs(double *lpc_in, int order, int precision,\n                               int32_t *lpc_out, int *shift, int max_shift, int zero_shift)\n{\n    int i;\n    double cmax, error;\n    int32_t qmax;\n    int sh;\n    qmax = (1 << (precision - 1)) - 1;\n    cmax = 0.0;\n    for(i=0; i<order; i++) {\n        cmax= FFMAX(cmax, fabs(lpc_in[i]));\n    }\n    if(cmax * (1 << max_shift) < 1.0) {\n        *shift = zero_shift;\n        memset(lpc_out, 0, sizeof(int32_t) * order);\n        return;\n    }\n    sh = max_shift;\n    while((cmax * (1 << sh) > qmax) && (sh > 0)) {\n        sh--;\n    }\n    if(sh == 0 && cmax > qmax) {\n        double scale = ((double)qmax) / cmax;\n        for(i=0; i<order; i++) {\n            lpc_in[i] *= scale;\n        }\n    }\n    error=0;\n    for(i=0; i<order; i++) {\n        error -= lpc_in[i] * (1 << sh);\n        lpc_out[i] = av_clip(lrintf(error), -qmax, qmax);\n        error -= lpc_out[i];\n    }\n    *shift = sh;\n}']