avcodec: Implement Acorn Replay IMA ADPCM decoder

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
This commit is contained in:
Cameron Cawley 2021-05-07 17:50:47 +01:00 committed by Zane van Iperen
parent b4e7fc4b4b
commit 5c7313c740
No known key found for this signature in database
GPG Key ID: 68616B2D8AC4DCC5
9 changed files with 33 additions and 1 deletions

View File

@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
version <next>:
- ADPCM IMA Westwood encoder
- Westwood AUD muxer
- ADPCM IMA Acorn Replay decoder
version 4.4:

View File

@ -1126,6 +1126,7 @@ following image formats are supported:
@item ADPCM Electronic Arts XAS @tab @tab X
@item ADPCM G.722 @tab X @tab X
@item ADPCM G.726 @tab X @tab X
@item ADPCM IMA Acorn Replay @tab @tab X
@item ADPCM IMA AMV @tab X @tab X
@tab Used in AMV files
@item ADPCM IMA Cunning Developments @tab @tab X

View File

@ -868,6 +868,7 @@ OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o
OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o
OBJS-$(CONFIG_ADPCM_G726LE_DECODER) += g726.o
OBJS-$(CONFIG_ADPCM_G726LE_ENCODER) += g726.o
OBJS-$(CONFIG_ADPCM_IMA_ACORN_DECODER) += adpcm.o adpcm_data.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

View File

@ -747,6 +747,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
switch (avctx->codec->id) {
case AV_CODEC_ID_ADPCM_4XM:
case AV_CODEC_ID_ADPCM_AGM:
case AV_CODEC_ID_ADPCM_IMA_ACORN:
case AV_CODEC_ID_ADPCM_IMA_DAT4:
case AV_CODEC_ID_ADPCM_IMA_MOFLEX:
case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
@ -1665,6 +1666,23 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
}
break;
case AV_CODEC_ID_ADPCM_IMA_ACORN:
for (channel = 0; channel < avctx->channels; channel++) {
cs = &c->status[channel];
cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
cs->step_index = bytestream2_get_le16u(&gb) & 0xFF;
if (cs->step_index > 88u){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
channel, cs->step_index);
return AVERROR_INVALIDDATA;
}
}
for (n = nb_samples >> (1 - st); n > 0; n--) {
int byte = bytestream2_get_byteu(&gb);
*samples++ = adpcm_ima_expand_nibble(&c->status[0], byte & 0x0F, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], byte >> 4, 3);
}
break;
case AV_CODEC_ID_ADPCM_IMA_AMV:
av_assert0(avctx->channels == 1);
@ -2160,6 +2178,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1,
ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ACORN, sample_fmts_s16, adpcm_ima_acorn, "ADPCM IMA Acorn Replay");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APM, sample_fmts_s16, adpcm_ima_apm, "ADPCM IMA Ubisoft APM");

View File

@ -619,6 +619,7 @@ extern const AVCodec ff_adpcm_g726_encoder;
extern const AVCodec ff_adpcm_g726_decoder;
extern const AVCodec ff_adpcm_g726le_encoder;
extern const AVCodec ff_adpcm_g726le_decoder;
extern const AVCodec ff_adpcm_ima_acorn_decoder;
extern const AVCodec ff_adpcm_ima_amv_decoder;
extern const AVCodec ff_adpcm_ima_amv_encoder;
extern const AVCodec ff_adpcm_ima_alp_decoder;

View File

@ -2462,6 +2462,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA MobiClip MOFLEX"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
{
.id = AV_CODEC_ID_ADPCM_IMA_ACORN,
.type = AVMEDIA_TYPE_AUDIO,
.name = "adpcm_ima_acorn",
.long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Acorn Replay"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
},
/* AMR */
{

View File

@ -398,6 +398,7 @@ enum AVCodecID {
AV_CODEC_ID_ADPCM_IMA_MTF,
AV_CODEC_ID_ADPCM_IMA_CUNNING,
AV_CODEC_ID_ADPCM_IMA_MOFLEX,
AV_CODEC_ID_ADPCM_IMA_ACORN,
/* AMR */
AV_CODEC_ID_AMR_NB = 0x12000,

View File

@ -699,6 +699,7 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
return 0;
return frame_bytes * 28;
case AV_CODEC_ID_ADPCM_4XM:
case AV_CODEC_ID_ADPCM_IMA_ACORN:
case AV_CODEC_ID_ADPCM_IMA_DAT4:
case AV_CODEC_ID_ADPCM_IMA_ISS:
return (frame_bytes - 4 * ch) * 2 / ch;

View File

@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 59
#define LIBAVCODEC_VERSION_MINOR 0
#define LIBAVCODEC_VERSION_MINOR 1
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \