diff options
author | Zane van Iperen | 2020-03-08 12:09:02 +0000 |
---|---|---|
committer | Michael Niedermayer | 2020-03-09 01:43:51 +0100 |
commit | d90413e1e52ca453078f4cfd948466ffb591df21 (patch) | |
tree | 8e3e50362e5c7775894d48864820f7d457616d55 /libavcodec/adpcm.c | |
parent | 0830e9116f786572865a9c800a9156d0c4294f27 (diff) |
avcodec: add decoder for High Voltage Software's ALP ADPCM
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/adpcm.c')
-rw-r--r-- | libavcodec/adpcm.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 5f152ee6ef..c69cac3379 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -15,6 +15,7 @@ * Argonaut Games ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com) * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com) * Ubisoft ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com) + * High Voltage Software ALP decoder by Zane van Iperen (zane@zanevaniperen.com) * * This file is part of FFmpeg. * @@ -280,6 +281,29 @@ static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibb return (int16_t)c->predictor; } +static inline int16_t adpcm_ima_alp_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift) +{ + int step_index; + int predictor; + int sign, delta, diff, step; + + step = ff_adpcm_step_table[c->step_index]; + step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble]; + step_index = av_clip(step_index, 0, 88); + + sign = nibble & 8; + delta = nibble & 7; + diff = (delta * step) >> shift; + predictor = c->predictor; + if (sign) predictor -= diff; + else predictor += diff; + + c->predictor = av_clip_int16(predictor); + c->step_index = step_index; + + return (int16_t)c->predictor; +} + static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps) { int nibble, step_index, predictor, sign, delta, diff, step, shift; @@ -675,6 +699,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, case AV_CODEC_ID_ADPCM_AICA: case AV_CODEC_ID_ADPCM_IMA_SSI: case AV_CODEC_ID_ADPCM_IMA_APM: + case AV_CODEC_ID_ADPCM_IMA_ALP: nb_samples = buf_size * 2 / ch; break; } @@ -1247,6 +1272,16 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, samples += avctx->channels; } break; + case AV_CODEC_ID_ADPCM_IMA_ALP: + for (n = nb_samples / 2; n > 0; n--) { + for (channel = 0; channel < avctx->channels; channel++) { + int v = bytestream2_get_byteu(&gb); + *samples++ = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4 , 2); + samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2); + } + samples += avctx->channels; + } + break; case AV_CODEC_ID_ADPCM_IMA_OKI: while (bytestream2_get_bytes_left(&gb) > 0) { int v = bytestream2_get_byteu(&gb); @@ -1997,6 +2032,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SSI, sample_fmts_s16, adpcm_ima_ssi, "ADPCM IMA Simon & Schuster Interactive"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG"); +ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ALP, sample_fmts_s16, adpcm_ima_alp, "ADPCM IMA High Voltage Software ALP"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood"); ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft"); |