[FFmpeg-cvslog] avcodec: add adpcm_ima_alp encoder
Zane van Iperen
git at videolan.org
Sun Oct 25 16:02:38 EET 2020
ffmpeg | branch: master | Zane van Iperen <zane at zanevaniperen.com> | Fri Oct 23 18:14:59 2020 +1000| [40a8d438850dcc31a89762a8f13b5073f4369ceb] | committer: Zane van Iperen
avcodec: add adpcm_ima_alp encoder
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=40a8d438850dcc31a89762a8f13b5073f4369ceb
---
Changelog | 1 +
libavcodec/Makefile | 1 +
libavcodec/adpcmenc.c | 40 ++++++++++++++++++++++++++++++++++++++++
libavcodec/allcodecs.c | 1 +
libavcodec/version.h | 4 ++--
5 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/Changelog b/Changelog
index 21a4be731b..4bbb0fa6ff 100644
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,7 @@ version <next>:
- Cintel RAW decoder
- VDPAU accelerated VP9 10/12bit decoding
- afreqshift and aphaseshift filters
+- High Voltage Software ADPCM encoder
version 4.3:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9c49d8c01a..93a7eccc85 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -864,6 +864,7 @@ OBJS-$(CONFIG_ADPCM_G726LE_DECODER) += g726.o
OBJS-$(CONFIG_ADPCM_G726LE_ENCODER) += g726.o
OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER) += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_ALP_ENCODER) += adpcmenc.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_IMA_APM_ENCODER) += adpcmenc.o adpcm_data.o
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 6ecdab96d6..ee13faa4cb 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -157,6 +157,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
avctx->block_align = (2 + avctx->channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8;
break;
case AV_CODEC_ID_ADPCM_IMA_SSI:
+ case AV_CODEC_ID_ADPCM_IMA_ALP:
avctx->frame_size = s->block_size * 2 / avctx->channels;
avctx->block_align = s->block_size;
break;
@@ -204,6 +205,25 @@ static inline uint8_t adpcm_ima_compress_sample(ADPCMChannelStatus *c,
return nibble;
}
+static inline uint8_t adpcm_ima_alp_compress_sample(ADPCMChannelStatus *c, int16_t sample)
+{
+ const int delta = sample - c->prev_sample;
+ const int step = ff_adpcm_step_table[c->step_index];
+ const int sign = (delta < 0) * 8;
+
+ int nibble = FFMIN(abs(delta) * 4 / step, 7);
+ int diff = (step * nibble) >> 2;
+ if (sign)
+ diff = -diff;
+
+ nibble = sign | nibble;
+
+ c->prev_sample += diff;
+ c->prev_sample = av_clip_int16(c->prev_sample);
+ c->step_index = av_clip(c->step_index + ff_adpcm_index_table[nibble], 0, 88);
+ return nibble;
+}
+
static inline uint8_t adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c,
int16_t sample)
{
@@ -552,6 +572,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
st = avctx->channels == 2;
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)
pkt_size = (frame->nb_samples * avctx->channels) / 2;
else
@@ -655,6 +676,24 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
flush_put_bits(&pb);
break;
}
+ case AV_CODEC_ID_ADPCM_IMA_ALP:
+ {
+ PutBitContext pb;
+ init_put_bits(&pb, dst, pkt_size);
+
+ av_assert0(avctx->trellis == 0);
+
+ for (n = frame->nb_samples / 2; n > 0; n--) {
+ for (ch = 0; ch < avctx->channels; ch++) {
+ put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, *samples++));
+ put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, samples[st]));
+ }
+ samples += avctx->channels;
+ }
+
+ flush_put_bits(&pb);
+ break;
+ }
case AV_CODEC_ID_ADPCM_SWF:
{
PutBitContext pb;
@@ -889,6 +928,7 @@ AVCodec ff_ ## name_ ## _encoder = { \
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_ARGO, adpcm_argo, sample_fmts_p, 0, "ADPCM Argonaut Games");
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_APM, adpcm_ima_apm, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Ubisoft APM");
+ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_ALP, adpcm_ima_alp, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA High Voltage Software ALP");
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");
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 82dee16973..16fd92b802 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -615,6 +615,7 @@ extern AVCodec ff_adpcm_g726le_encoder;
extern AVCodec ff_adpcm_g726le_decoder;
extern AVCodec ff_adpcm_ima_amv_decoder;
extern AVCodec ff_adpcm_ima_alp_decoder;
+extern AVCodec ff_adpcm_ima_alp_encoder;
extern AVCodec ff_adpcm_ima_apc_decoder;
extern AVCodec ff_adpcm_ima_apm_decoder;
extern AVCodec ff_adpcm_ima_apm_encoder;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index d03d290379..02ffa95749 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 111
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR 112
+#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