void ff_celp_circ_addf(float *out, const float *in,
                       const float *lagged, int lag, float fac, int n)
{
    int k;
    for (k = 0; k < lag; k++)
        out[k] = in[k] + fac * lagged[n + k - lag];
    for (; k < n; k++)
        out[k] = in[k] + fac * lagged[    k - lag];
}
['static int amrnb_decode_frame(AVCodecContext *avctx, void *data,\n                              int *got_frame_ptr, AVPacket *avpkt)\n{\n    AMRContext *p = avctx->priv_data;\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    float *buf_out;\n    int i, subframe, ret;\n    float fixed_gain_factor;\n    AMRFixed fixed_sparse = {0};\n    float spare_vector[AMR_SUBFRAME_SIZE];\n    float synth_fixed_gain;\n    const float *synth_fixed_vector;\n    p->avframe.nb_samples = AMR_BLOCK_SIZE;\n    if ((ret = avctx->get_buffer(avctx, &p->avframe)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    buf_out = (float *)p->avframe.data[0];\n    p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);\n    if (p->cur_frame_mode == MODE_DTX) {\n        av_log_missing_feature(avctx, "dtx mode", 1);\n        return -1;\n    }\n    if (p->cur_frame_mode == MODE_12k2) {\n        lsf2lsp_5(p);\n    } else\n        lsf2lsp_3(p);\n    for (i = 0; i < 4; i++)\n        ff_acelp_lspd2lpc(p->lsp[i], p->lpc[i], 5);\n    for (subframe = 0; subframe < 4; subframe++) {\n        const AMRNBSubframe *amr_subframe = &p->frame.subframe[subframe];\n        decode_pitch_vector(p, amr_subframe, subframe);\n        decode_fixed_sparse(&fixed_sparse, amr_subframe->pulses,\n                            p->cur_frame_mode, subframe);\n        decode_gains(p, amr_subframe, p->cur_frame_mode, subframe,\n                     &fixed_gain_factor);\n        pitch_sharpening(p, subframe, p->cur_frame_mode, &fixed_sparse);\n        if (fixed_sparse.pitch_lag == 0) {\n            av_log(avctx, AV_LOG_ERROR, "The file is corrupted, pitch_lag = 0 is not allowed\\n");\n            return AVERROR_INVALIDDATA;\n        }\n        ff_set_fixed_vector(p->fixed_vector, &fixed_sparse, 1.0,\n                            AMR_SUBFRAME_SIZE);\n        p->fixed_gain[4] =\n            ff_amr_set_fixed_gain(fixed_gain_factor,\n                       ff_dot_productf(p->fixed_vector, p->fixed_vector,\n                                       AMR_SUBFRAME_SIZE)/AMR_SUBFRAME_SIZE,\n                       p->prediction_error,\n                       energy_mean[p->cur_frame_mode], energy_pred_fac);\n        for (i = 0; i < AMR_SUBFRAME_SIZE; i++)\n            p->excitation[i] *= p->pitch_gain[4];\n        ff_set_fixed_vector(p->excitation, &fixed_sparse, p->fixed_gain[4],\n                            AMR_SUBFRAME_SIZE);\n        for (i = 0; i < AMR_SUBFRAME_SIZE; i++)\n            p->excitation[i] = truncf(p->excitation[i]);\n        synth_fixed_gain = fixed_gain_smooth(p, p->lsf_q[subframe],\n                                             p->lsf_avg, p->cur_frame_mode);\n        synth_fixed_vector = anti_sparseness(p, &fixed_sparse, p->fixed_vector,\n                                             synth_fixed_gain, spare_vector);\n        if (synthesis(p, p->lpc[subframe], synth_fixed_gain,\n                      synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 0))\n            synthesis(p, p->lpc[subframe], synth_fixed_gain,\n                      synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 1);\n        postfilter(p, p->lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);\n        ff_clear_fixed_vector(p->fixed_vector, &fixed_sparse, AMR_SUBFRAME_SIZE);\n        update_state(p);\n    }\n    ff_acelp_apply_order_2_transfer_function(buf_out, buf_out, highpass_zeros,\n                                             highpass_poles,\n                                             highpass_gain * AMR_SAMPLE_SCALE,\n                                             p->high_pass_mem, AMR_BLOCK_SIZE);\n    ff_weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3],\n                            0.84, 0.16, LP_FILTER_ORDER);\n    *got_frame_ptr   = 1;\n    *(AVFrame *)data = p->avframe;\n    return frame_sizes_nb[p->cur_frame_mode] + 1;\n}', 'static void decode_pitch_vector(AMRContext *p,\n                                const AMRNBSubframe *amr_subframe,\n                                const int subframe)\n{\n    int pitch_lag_int, pitch_lag_frac;\n    enum Mode mode = p->cur_frame_mode;\n    if (p->cur_frame_mode == MODE_12k2) {\n        decode_pitch_lag_1_6(&pitch_lag_int, &pitch_lag_frac,\n                             amr_subframe->p_lag, p->pitch_lag_int,\n                             subframe);\n    } else\n        ff_decode_pitch_lag(&pitch_lag_int, &pitch_lag_frac,\n                            amr_subframe->p_lag,\n                            p->pitch_lag_int, subframe,\n                            mode != MODE_4k75 && mode != MODE_5k15,\n                            mode <= MODE_6k7 ? 4 : (mode == MODE_7k95 ? 5 : 6));\n    p->pitch_lag_int = pitch_lag_int;\n    pitch_lag_frac <<= (p->cur_frame_mode != MODE_12k2);\n    pitch_lag_int += pitch_lag_frac > 0;\n    ff_acelp_interpolatef(p->excitation, p->excitation + 1 - pitch_lag_int,\n                          ff_b60_sinc, 6,\n                          pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),\n                          10, AMR_SUBFRAME_SIZE);\n    memcpy(p->pitch_vector, p->excitation, AMR_SUBFRAME_SIZE * sizeof(float));\n}', 'static void decode_pitch_lag_1_6(int *lag_int, int *lag_frac, int pitch_index,\n                                 const int prev_lag_int, const int subframe)\n{\n    if (subframe == 0 || subframe == 2) {\n        if (pitch_index < 463) {\n            *lag_int  = (pitch_index + 107) * 10923 >> 16;\n            *lag_frac = pitch_index - *lag_int * 6 + 105;\n        } else {\n            *lag_int  = pitch_index - 368;\n            *lag_frac = 0;\n        }\n    } else {\n        *lag_int  = ((pitch_index + 5) * 10923 >> 16) - 1;\n        *lag_frac = pitch_index - *lag_int * 6 - 3;\n        *lag_int += av_clip(prev_lag_int - 5, PITCH_LAG_MIN_MODE_12k2,\n                            PITCH_DELAY_MAX - 9);\n    }\n}', 'static void pitch_sharpening(AMRContext *p, int subframe, enum Mode mode,\n                             AMRFixed *fixed_sparse)\n{\n    if (mode == MODE_12k2)\n        p->beta = FFMIN(p->pitch_gain[4], 1.0);\n    fixed_sparse->pitch_lag  = p->pitch_lag_int;\n    fixed_sparse->pitch_fac  = p->beta;\n    if (mode != MODE_4k75 || subframe & 1)\n        p->beta = av_clipf(p->pitch_gain[4], 0.0, SHARP_MAX);\n}', 'static const float *anti_sparseness(AMRContext *p, AMRFixed *fixed_sparse,\n                                    const float *fixed_vector,\n                                    float fixed_gain, float *out)\n{\n    int ir_filter_nr;\n    if (p->pitch_gain[4] < 0.6) {\n        ir_filter_nr = 0;\n    } else if (p->pitch_gain[4] < 0.9) {\n        ir_filter_nr = 1;\n    } else\n        ir_filter_nr = 2;\n    if (fixed_gain > 2.0 * p->prev_sparse_fixed_gain) {\n        p->ir_filter_onset = 2;\n    } else if (p->ir_filter_onset)\n        p->ir_filter_onset--;\n    if (!p->ir_filter_onset) {\n        int i, count = 0;\n        for (i = 0; i < 5; i++)\n            if (p->pitch_gain[i] < 0.6)\n                count++;\n        if (count > 2)\n            ir_filter_nr = 0;\n        if (ir_filter_nr > p->prev_ir_filter_nr + 1)\n            ir_filter_nr--;\n    } else if (ir_filter_nr < 2)\n        ir_filter_nr++;\n    if (fixed_gain < 5.0)\n        ir_filter_nr = 2;\n    if (p->cur_frame_mode != MODE_7k4 && p->cur_frame_mode < MODE_10k2\n         && ir_filter_nr < 2) {\n        apply_ir_filter(out, fixed_sparse,\n                        (p->cur_frame_mode == MODE_7k95 ?\n                             ir_filters_lookup_MODE_7k95 :\n                             ir_filters_lookup)[ir_filter_nr]);\n        fixed_vector = out;\n    }\n    p->prev_ir_filter_nr       = ir_filter_nr;\n    p->prev_sparse_fixed_gain  = fixed_gain;\n    return fixed_vector;\n}', 'static void apply_ir_filter(float *out, const AMRFixed *in,\n                            const float *filter)\n{\n    float filter1[AMR_SUBFRAME_SIZE],\n          filter2[AMR_SUBFRAME_SIZE];\n    int   lag = in->pitch_lag;\n    float fac = in->pitch_fac;\n    int i;\n    if (lag < AMR_SUBFRAME_SIZE) {\n        ff_celp_circ_addf(filter1, filter, filter, lag, fac,\n                          AMR_SUBFRAME_SIZE);\n        if (lag < AMR_SUBFRAME_SIZE >> 1)\n            ff_celp_circ_addf(filter2, filter, filter1, lag, fac,\n                              AMR_SUBFRAME_SIZE);\n    }\n    memset(out, 0, sizeof(float) * AMR_SUBFRAME_SIZE);\n    for (i = 0; i < in->n; i++) {\n        int   x = in->x[i];\n        float y = in->y[i];\n        const float *filterp;\n        if (x >= AMR_SUBFRAME_SIZE - lag) {\n            filterp = filter;\n        } else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {\n            filterp = filter1;\n        } else\n            filterp = filter2;\n        ff_celp_circ_addf(out, out, filterp, x, y, AMR_SUBFRAME_SIZE);\n    }\n}', 'void ff_celp_circ_addf(float *out, const float *in,\n                       const float *lagged, int lag, float fac, int n)\n{\n    int k;\n    for (k = 0; k < lag; k++)\n        out[k] = in[k] + fac * lagged[n + k - lag];\n    for (; k < n; k++)\n        out[k] = in[k] + fac * lagged[    k - lag];\n}']