[FFmpeg-cvslog] avcodec/adpcmenc: Adds encoder for Westwood ADPCM.
Aidan Richmond
git at videolan.org
Mon Apr 26 13:03:11 EEST 2021
ffmpeg | branch: master | Aidan Richmond <aidan.is at hotmail.co.uk> | Sun Apr 25 21:00:00 2021 +0100| [a0fd55c206cea0af3a688c62ca7bf9001d1b8b4b] | committer: Zane van Iperen
avcodec/adpcmenc: Adds encoder for Westwood ADPCM.
Signed-off-by: Aidan Richmond <aidan.is at hotmail.co.uk>
Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a0fd55c206cea0af3a688c62ca7bf9001d1b8b4b
---
Changelog | 1 +
libavcodec/Makefile | 1 +
libavcodec/adpcmenc.c | 32 ++++++++++++++++++++++++++++++--
libavcodec/allcodecs.c | 1 +
libavcodec/version.h | 4 ++--
5 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/Changelog b/Changelog
index 3ee4712490..320a18bcd6 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest.
version <next>:
+- ADPCM IMA Westwood encoder
version 4.4:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4a597f727a..fcddde459d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -898,6 +898,7 @@ OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_WS_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 9dc77d519a..752cae5cf4 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -94,7 +94,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_SSI ||
avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_APM ||
- avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO) {
+ avctx->codec->id == AV_CODEC_ID_ADPCM_ARGO ||
+ avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_WS) {
/*
* The current trellis implementation doesn't work for extended
* runs of samples without periodic resets. Disallow it.
@@ -192,6 +193,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
avctx->frame_size = 32;
avctx->block_align = 17 * avctx->channels;
break;
+ case AV_CODEC_ID_ADPCM_IMA_WS:
+ /* each 16 bits sample gives one nibble */
+ avctx->frame_size = s->block_size * 2 / avctx->channels;
+ avctx->block_align = s->block_size;
+ break;
default:
return AVERROR(EINVAL);
}
@@ -594,7 +600,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI ||
avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP ||
- avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM)
+ avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM ||
+ avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS)
pkt_size = (frame->nb_samples * avctx->channels) / 2;
else
pkt_size = avctx->block_align;
@@ -929,6 +936,26 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
flush_put_bits(&pb);
break;
}
+ case AV_CODEC_ID_ADPCM_IMA_WS:
+ {
+ PutBitContext pb;
+ init_put_bits(&pb, dst, pkt_size);
+
+ av_assert0(avctx->trellis == 0);
+ for (n = frame->nb_samples / 2; n > 0; n--) {
+ /* stereo: 1 byte (2 samples) for left, 1 byte for right */
+ for (ch = 0; ch < avctx->channels; ch++) {
+ int t1, t2;
+ t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++);
+ t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]);
+ put_bits(&pb, 4, t2);
+ put_bits(&pb, 4, t1);
+ }
+ samples += avctx->channels;
+ }
+ flush_put_bits(&pb);
+ break;
+ }
default:
return AVERROR(EINVAL);
}
@@ -990,6 +1017,7 @@ ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_ALP, adpcm_ima_alp, sample_fmts, AV_CODEC_
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV");
+ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Westwood");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_MS, adpcm_ms, sample_fmts, 0, "ADPCM Microsoft");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_SWF, adpcm_swf, sample_fmts, 0, "ADPCM Shockwave Flash");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, sample_fmts, 0, "ADPCM Yamaha");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2e9a3581de..b748c9718e 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -645,6 +645,7 @@ extern AVCodec ff_adpcm_ima_ssi_encoder;
extern AVCodec ff_adpcm_ima_smjpeg_decoder;
extern AVCodec ff_adpcm_ima_wav_encoder;
extern AVCodec ff_adpcm_ima_wav_decoder;
+extern AVCodec ff_adpcm_ima_ws_encoder;
extern AVCodec ff_adpcm_ima_ws_decoder;
extern AVCodec ff_adpcm_ms_encoder;
extern AVCodec ff_adpcm_ms_decoder;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 349b4b1269..78c14f1c0d 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,8 +28,8 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 58
-#define LIBAVCODEC_VERSION_MINOR 136
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR 137
+#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list