static void alac_linear_predictor(AlacEncodeContext *s, int ch)
{
    int i;
    AlacLPCContext lpc = s->lpc[ch];
    if (lpc.lpc_order == 31) {
        s->predictor_buf[0] = s->sample_buf[ch][0];
        for (i = 1; i < s->frame_size; i++) {
            s->predictor_buf[i] = s->sample_buf[ch][i    ] -
                                  s->sample_buf[ch][i - 1];
        }
        return;
    }
    if (lpc.lpc_order > 0) {
        int32_t *samples  = s->sample_buf[ch];
        int32_t *residual = s->predictor_buf;
        residual[0] = samples[0];
        for (i = 1; i <= lpc.lpc_order; i++)
            residual[i] = samples[i] - samples[i-1];
        for (i = lpc.lpc_order + 1; i < s->frame_size; i++) {
            int sum = 1 << (lpc.lpc_quant - 1), res_val, j;
            for (j = 0; j < lpc.lpc_order; j++) {
                sum += (samples[lpc.lpc_order-j] - samples[0]) *
                       lpc.lpc_coeff[j];
            }
            sum >>= lpc.lpc_quant;
            sum += samples[0];
            residual[i] = sign_extend(samples[lpc.lpc_order+1] - sum,
                                      s->write_sample_size);
            res_val = residual[i];
            if (res_val) {
                int index = lpc.lpc_order - 1;
                int neg = (res_val < 0);
                while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
                    int val  = samples[0] - samples[lpc.lpc_order - index];
                    int sign = (val ? FFSIGN(val) : 0);
                    if (neg)
                        sign *= -1;
                    lpc.lpc_coeff[index] -= sign;
                    val *= sign;
                    res_val -= (val >> lpc.lpc_quant) * (lpc.lpc_order - index);
                    index--;
                }
            }
            samples++;
        }
    }
}
['static void write_element(AlacEncodeContext *s,\n                          enum AlacRawDataBlockType element, int instance,\n                          const uint8_t *samples0, const uint8_t *samples1)\n{\n    uint8_t const *samples[2] = { samples0, samples1 };\n    int i, j, channels;\n    int prediction_type = 0;\n    PutBitContext *pb = &s->pbctx;\n    channels = element == TYPE_CPE ? 2 : 1;\n    if (s->verbatim) {\n        write_element_header(s, element, instance);\n        if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {\n            int shift = 32 - s->avctx->bits_per_raw_sample;\n            int32_t const *samples_s32[2] = { (const int32_t *)samples0,\n                                              (const int32_t *)samples1 };\n            for (i = 0; i < s->frame_size; i++)\n                for (j = 0; j < channels; j++)\n                    put_sbits(pb, s->avctx->bits_per_raw_sample,\n                              samples_s32[j][i] >> shift);\n        } else {\n            int16_t const *samples_s16[2] = { (const int16_t *)samples0,\n                                              (const int16_t *)samples1 };\n            for (i = 0; i < s->frame_size; i++)\n                for (j = 0; j < channels; j++)\n                    put_sbits(pb, s->avctx->bits_per_raw_sample,\n                              samples_s16[j][i]);\n        }\n    } else {\n        s->write_sample_size = s->avctx->bits_per_raw_sample - s->extra_bits +\n                               channels - 1;\n        init_sample_buffers(s, channels, samples);\n        write_element_header(s, element, instance);\n        if (channels == 2)\n            alac_stereo_decorrelation(s);\n        else\n            s->interlacing_shift = s->interlacing_leftweight = 0;\n        put_bits(pb, 8, s->interlacing_shift);\n        put_bits(pb, 8, s->interlacing_leftweight);\n        for (i = 0; i < channels; i++) {\n            calc_predictor_params(s, i);\n            put_bits(pb, 4, prediction_type);\n            put_bits(pb, 4, s->lpc[i].lpc_quant);\n            put_bits(pb, 3, s->rc.rice_modifier);\n            put_bits(pb, 5, s->lpc[i].lpc_order);\n            for (j = 0; j < s->lpc[i].lpc_order; j++)\n                put_sbits(pb, 16, s->lpc[i].lpc_coeff[j]);\n        }\n        if (s->extra_bits) {\n            uint32_t mask = (1 << s->extra_bits) - 1;\n            for (i = 0; i < s->frame_size; i++) {\n                for (j = 0; j < channels; j++) {\n                    put_bits(pb, s->extra_bits, s->sample_buf[j][i] & mask);\n                    s->sample_buf[j][i] >>= s->extra_bits;\n                }\n            }\n        }\n        for (i = 0; i < channels; i++) {\n            alac_linear_predictor(s, i);\n            if (prediction_type == 15) {\n                for (j = s->frame_size - 1; j > 0; j--)\n                    s->predictor_buf[j] -= s->predictor_buf[j - 1];\n            }\n            alac_entropy_coder(s);\n        }\n    }\n}', 'static void alac_linear_predictor(AlacEncodeContext *s, int ch)\n{\n    int i;\n    AlacLPCContext lpc = s->lpc[ch];\n    if (lpc.lpc_order == 31) {\n        s->predictor_buf[0] = s->sample_buf[ch][0];\n        for (i = 1; i < s->frame_size; i++) {\n            s->predictor_buf[i] = s->sample_buf[ch][i    ] -\n                                  s->sample_buf[ch][i - 1];\n        }\n        return;\n    }\n    if (lpc.lpc_order > 0) {\n        int32_t *samples  = s->sample_buf[ch];\n        int32_t *residual = s->predictor_buf;\n        residual[0] = samples[0];\n        for (i = 1; i <= lpc.lpc_order; i++)\n            residual[i] = samples[i] - samples[i-1];\n        for (i = lpc.lpc_order + 1; i < s->frame_size; i++) {\n            int sum = 1 << (lpc.lpc_quant - 1), res_val, j;\n            for (j = 0; j < lpc.lpc_order; j++) {\n                sum += (samples[lpc.lpc_order-j] - samples[0]) *\n                       lpc.lpc_coeff[j];\n            }\n            sum >>= lpc.lpc_quant;\n            sum += samples[0];\n            residual[i] = sign_extend(samples[lpc.lpc_order+1] - sum,\n                                      s->write_sample_size);\n            res_val = residual[i];\n            if (res_val) {\n                int index = lpc.lpc_order - 1;\n                int neg = (res_val < 0);\n                while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {\n                    int val  = samples[0] - samples[lpc.lpc_order - index];\n                    int sign = (val ? FFSIGN(val) : 0);\n                    if (neg)\n                        sign *= -1;\n                    lpc.lpc_coeff[index] -= sign;\n                    val *= sign;\n                    res_val -= (val >> lpc.lpc_quant) * (lpc.lpc_order - index);\n                    index--;\n                }\n            }\n            samples++;\n        }\n    }\n}']