forked from ffmpegwasm/ffmpeg.wasm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avcodec: add support for Cunning Developments' ADPCM
Signed-off-by: Zane van Iperen <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
- Loading branch information
Showing
10 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* Simon & Schuster Interactive ADPCM decoder by Zane van Iperen ([email protected]) | ||
* Ubisoft ADPCM decoder by Zane van Iperen ([email protected]) | ||
* High Voltage Software ALP decoder by Zane van Iperen ([email protected]) | ||
* Cunning Developments decoder by Zane van Iperen ([email protected]) | ||
* | ||
* This file is part of FFmpeg. | ||
* | ||
|
@@ -109,6 +110,9 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) | |
unsigned int max_channels = 2; | ||
|
||
switch(avctx->codec->id) { | ||
case AV_CODEC_ID_ADPCM_IMA_CUNNING: | ||
max_channels = 1; | ||
break; | ||
case AV_CODEC_ID_ADPCM_DTK: | ||
case AV_CODEC_ID_ADPCM_EA: | ||
min_channels = 2; | ||
|
@@ -325,6 +329,26 @@ static inline int16_t adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nib | |
return (int16_t)c->predictor; | ||
} | ||
|
||
static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, int8_t nibble) | ||
{ | ||
int step_index; | ||
int predictor; | ||
int step; | ||
|
||
nibble = sign_extend(nibble & 0xF, 4); | ||
|
||
step = ff_adpcm_ima_cunning_step_table[c->step_index]; | ||
step_index = c->step_index + ff_adpcm_ima_cunning_index_table[abs(nibble)]; | ||
step_index = av_clip(step_index, 0, 60); | ||
|
||
predictor = c->predictor + step * nibble; | ||
|
||
c->predictor = av_clip_int16(predictor); | ||
c->step_index = step_index; | ||
|
||
return 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; | ||
|
@@ -713,6 +737,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, | |
/* simple 4-bit adpcm */ | ||
case AV_CODEC_ID_ADPCM_CT: | ||
case AV_CODEC_ID_ADPCM_IMA_APC: | ||
case AV_CODEC_ID_ADPCM_IMA_CUNNING: | ||
case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: | ||
case AV_CODEC_ID_ADPCM_IMA_OKI: | ||
case AV_CODEC_ID_ADPCM_IMA_WS: | ||
|
@@ -1304,6 +1329,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, | |
samples += avctx->channels; | ||
} | ||
break; | ||
case AV_CODEC_ID_ADPCM_IMA_CUNNING: | ||
for (n = 0; n < nb_samples / 2; n++) { | ||
int v = bytestream2_get_byteu(&gb); | ||
*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v & 0x0F); | ||
*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v >> 4); | ||
} | ||
break; | ||
case AV_CODEC_ID_ADPCM_IMA_OKI: | ||
for (n = nb_samples >> (1 - st); n > 0; n--) { | ||
int v = bytestream2_get_byteu(&gb); | ||
|
@@ -2053,6 +2085,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, | |
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"); | ||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_CUNNING, sample_fmts_s16, adpcm_ima_cunning, "ADPCM IMA Cunning Developments"); | ||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DAT4, sample_fmts_s16, adpcm_ima_dat4, "ADPCM IMA Eurocom DAT4"); | ||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3"); | ||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters