X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fadpcm.c;h=ede0130bf1a22b9e4eb69f4aed776bb5f36c530d;hb=2e254bb897471b4a4db2b846947fc6c00faac3e6;hp=cd3bbd33c2e44536e8cc2b6ef8fcf43056400e9d;hpb=14fe81b3a88dfe4dbac12e8715f9a3f05b5ef1bf;p=ffmpeg diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index cd3bbd33c2e..ede0130bf1a 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; @@ -1679,7 +1736,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, break; default: - return -1; + av_assert0(0); // unsupported codec_id should not happen } if (avpkt->size && bytestream2_tell(&gb) == 0) { @@ -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");