+ case AV_CODEC_ID_ADPCM_IMA_AMV:
+ {
+ av_assert0(avctx->channels == 1);
+
+ c->status[0].prev_sample = *samples;
+ bytestream_put_le16(&dst, c->status[0].prev_sample);
+ bytestream_put_byte(&dst, c->status[0].step_index);
+ bytestream_put_byte(&dst, 0);
+ bytestream_put_le32(&dst, avctx->frame_size);
+
+ if (avctx->trellis > 0) {
+ n = frame->nb_samples >> 1;
+
+ if (!(buf = av_malloc(2 * n)))
+ return AVERROR(ENOMEM);
+
+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, avctx->channels);
+ for (i = 0; i < n; i++)
+ bytestream_put_byte(&dst, (buf[2 * i] << 4) | buf[2 * i + 1]);
+
+ samples += 2 * n;
+ } else for (n = frame->nb_samples >> 1; n > 0; n--) {
+ int nibble;
+ nibble = adpcm_ima_compress_sample(&c->status[0], *samples++) << 4;
+ nibble |= adpcm_ima_compress_sample(&c->status[0], *samples++) & 0x0F;
+ bytestream_put_byte(&dst, nibble);
+ }
+
+ if (avctx->frame_size & 1) {
+ int nibble = adpcm_ima_compress_sample(&c->status[0], *samples++) << 4;
+ bytestream_put_byte(&dst, nibble);
+ }
+ break;
+ }