1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec: add ADPCM AGM decoder

This commit is contained in:
Paul B Mahol 2019-04-10 12:10:09 +02:00
parent 7be8f7ac81
commit d0f24df648
8 changed files with 72 additions and 3 deletions

View File

@ -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

View File

@ -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");

View File

@ -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;

View File

@ -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,

View File

@ -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 */
{

View File

@ -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, \

View File

@ -605,5 +605,6 @@ const AVCodecGuid ff_codec_wav_guids[] = {
{ AV_CODEC_ID_ATRAC9, { 0xD2, 0x42, 0xE1, 0x47, 0xBA, 0x36, 0x8D, 0x4D, 0x88, 0xFC, 0x61, 0x65, 0x4F, 0x8C, 0x83, 0x6C } },
{ AV_CODEC_ID_EAC3, { 0xAF, 0x87, 0xFB, 0xA7, 0x02, 0x2D, 0xFB, 0x42, 0xA4, 0xD4, 0x05, 0xCD, 0x93, 0x84, 0x3B, 0xDD } },
{ AV_CODEC_ID_MP2, { 0x2B, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA } },
{ AV_CODEC_ID_ADPCM_AGM,{ 0x82, 0xEC, 0x1F, 0x6A, 0xCA, 0xDB, 0x19, 0x45, 0xBD, 0xE7, 0x56, 0xD3, 0xB3, 0xEF, 0x98, 0x1D } },
{ AV_CODEC_ID_NONE }
};

View File

@ -33,7 +33,7 @@
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 58
#define LIBAVFORMAT_VERSION_MINOR 27
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \