+ channels = element == TYPE_CPE ? 2 : 1;
+
+ if (s->verbatim) {
+ write_element_header(s, element, instance);
+ /* samples are channel-interleaved in verbatim mode */
+ if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {
+ int shift = 32 - s->avctx->bits_per_raw_sample;
+ int32_t const *samples_s32[2] = { (const int32_t *)samples0,
+ (const int32_t *)samples1 };
+ for (i = 0; i < s->frame_size; i++)
+ for (j = 0; j < channels; j++)
+ put_sbits(pb, s->avctx->bits_per_raw_sample,
+ samples_s32[j][i] >> shift);
+ } else {
+ int16_t const *samples_s16[2] = { (const int16_t *)samples0,
+ (const int16_t *)samples1 };
+ for (i = 0; i < s->frame_size; i++)
+ for (j = 0; j < channels; j++)
+ put_sbits(pb, s->avctx->bits_per_raw_sample,
+ samples_s16[j][i]);
+ }
+ } else {
+ s->write_sample_size = s->avctx->bits_per_raw_sample - s->extra_bits +
+ channels - 1;
+
+ init_sample_buffers(s, channels, samples);
+ write_element_header(s, element, instance);
+
+ if (channels == 2)
+ alac_stereo_decorrelation(s);
+ else
+ s->interlacing_shift = s->interlacing_leftweight = 0;
+ put_bits(pb, 8, s->interlacing_shift);
+ put_bits(pb, 8, s->interlacing_leftweight);
+
+ for (i = 0; i < channels; i++) {
+ calc_predictor_params(s, i);
+
+ put_bits(pb, 4, prediction_type);
+ put_bits(pb, 4, s->lpc[i].lpc_quant);
+
+ put_bits(pb, 3, s->rc.rice_modifier);
+ put_bits(pb, 5, s->lpc[i].lpc_order);
+ // predictor coeff. table
+ for (j = 0; j < s->lpc[i].lpc_order; j++)
+ put_sbits(pb, 16, s->lpc[i].lpc_coeff[j]);
+ }