diff options
author | Paul B Mahol <onemda@gmail.com> | 2019-04-10 12:10:09 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2019-04-11 11:58:34 +0200 |
commit | d0f24df648f46e4c9a385e12a057fbade21427db (patch) | |
tree | f1caceb1d36beac9e486d92f928d87adc8ecee77 /libavcodec | |
parent | 7be8f7ac8143f4ae144c4951ddc5d42d466a9e23 (diff) | |
download | ffmpeg-d0f24df648f46e4c9a385e12a057fbade21427db.tar.gz |
avcodec: add ADPCM AGM decoder
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 1 | ||||
-rw-r--r-- | libavcodec/adpcm.c | 58 | ||||
-rw-r--r-- | libavcodec/allcodecs.c | 1 | ||||
-rw-r--r-- | libavcodec/avcodec.h | 1 | ||||
-rw-r--r-- | libavcodec/codec_desc.c | 7 | ||||
-rw-r--r-- | libavcodec/version.h | 4 |
6 files changed, 70 insertions, 2 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index de873c1643..02849f91ec 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -808,6 +808,7 @@ OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o adx.o OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o adx.o OBJS-$(CONFIG_ADPCM_AFC_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_AGM_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_AICA_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_DTK_DECODER) += adpcm.o adpcm_data.o diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index aa9c7c5c4f..ede0130bf1 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -177,6 +177,50 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) return 0; } +static inline int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble) +{ + int delta, pred, step, add; + + pred = c->predictor; + delta = nibble & 7; + step = c->step; + add = (delta * 2 + 1) * step; + if (add < 0) + add = add + 7; + + if ((nibble & 8) == 0) + pred = av_clip(pred + (add >> 3), -32767, 32767); + else + pred = av_clip(pred - (add >> 3), -32767, 32767); + + switch (delta) { + case 7: + step *= 0x99; + break; + case 6: + c->step = av_clip(c->step * 2, 127, 24576); + c->predictor = pred; + return pred; + case 5: + step *= 0x66; + break; + case 4: + step *= 0x4d; + break; + default: + step *= 0x39; + break; + } + + if (step < 0) + step += 0x3f; + + c->step = step >> 6; + c->step = av_clip(c->step, 127, 24576); + c->predictor = pred; + return pred; +} + static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift) { int step_index; @@ -549,6 +593,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, header_size = 0; switch (avctx->codec->id) { case AV_CODEC_ID_ADPCM_4XM: + case AV_CODEC_ID_ADPCM_AGM: case AV_CODEC_ID_ADPCM_IMA_DAT4: case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break; case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break; @@ -863,6 +908,18 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } break; + case AV_CODEC_ID_ADPCM_AGM: + for (i = 0; i < avctx->channels; i++) + c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); + for (i = 0; i < avctx->channels; i++) + c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16); + + for (n = 0; n < nb_samples >> (1 - st); n++) { + int v = bytestream2_get_byteu(&gb); + *samples++ = adpcm_agm_expand_nibble(&c->status[0], v & 0xF); + *samples++ = adpcm_agm_expand_nibble(&c->status[st], v >> 4 ); + } + break; case AV_CODEC_ID_ADPCM_MS: { int block_predictor; @@ -1729,6 +1786,7 @@ AVCodec ff_ ## name_ ## _decoder = { \ /* Note: Do not forget to add new entries to the Makefile as well. */ ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC"); +ADPCM_DECODER(AV_CODEC_ID_ADPCM_AGM, sample_fmts_s16, adpcm_agm, "ADPCM AmuseGraphics Movie"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_AICA, sample_fmts_s16p, adpcm_aica, "ADPCM Yamaha AICA"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK"); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 71fd74a07e..9ae8a779b3 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -574,6 +574,7 @@ extern AVCodec ff_adpcm_4xm_decoder; extern AVCodec ff_adpcm_adx_encoder; extern AVCodec ff_adpcm_adx_decoder; extern AVCodec ff_adpcm_afc_decoder; +extern AVCodec ff_adpcm_agm_decoder; extern AVCodec ff_adpcm_aica_decoder; extern AVCodec ff_adpcm_ct_decoder; extern AVCodec ff_adpcm_dtk_decoder; diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cafc65fce5..4218cff6c4 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -539,6 +539,7 @@ enum AVCodecID { AV_CODEC_ID_ADPCM_AICA, AV_CODEC_ID_ADPCM_IMA_DAT4, AV_CODEC_ID_ADPCM_MTAF, + AV_CODEC_ID_ADPCM_AGM, /* AMR */ AV_CODEC_ID_AMR_NB = 0x12000, diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 80c21a8c6c..8295221d15 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -2255,6 +2255,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("ADPCM MTAF"), .props = AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_ADPCM_AGM, + .type = AVMEDIA_TYPE_AUDIO, + .name = "adpcm_agm", + .long_name = NULL_IF_CONFIG_SMALL("ADPCM AmuseGraphics Movie AGM"), + .props = AV_CODEC_PROP_LOSSY, + }, /* AMR */ { diff --git a/libavcodec/version.h b/libavcodec/version.h index 02cb5c3ec1..be4408cda2 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 48 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MINOR 49 +#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ |