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

ADPCM AFC decoder

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2012-11-19 10:51:44 +00:00
parent 08e26e7f5c
commit 32cd3a7c16
10 changed files with 64 additions and 1 deletions

View File

@ -755,6 +755,7 @@ following image formats are supported:
@tab Used in some Sega Saturn console games.
@item ADPCM Microsoft @tab X @tab X
@item ADPCM MS IMA @tab X @tab X
@item ADPCM Nintendo Gamecube AFC @tab @tab X
@item ADPCM Nintendo Gamecube THP @tab @tab X
@item ADPCM QT IMA @tab X @tab X
@item ADPCM SEGA CRI ADX @tab X @tab X

View File

@ -566,6 +566,7 @@ OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o
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_CT_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o adpcm_data.o
OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o adpcm_data.o

View File

@ -145,6 +145,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
case AV_CODEC_ID_ADPCM_EA_R3:
case AV_CODEC_ID_ADPCM_EA_XAS:
case AV_CODEC_ID_ADPCM_THP:
case AV_CODEC_ID_ADPCM_AFC:
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
break;
case AV_CODEC_ID_ADPCM_IMA_WS:
@ -575,6 +576,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
*coded_samples -= *coded_samples % 14;
nb_samples = (buf_size - 80) / (8 * ch) * 14;
break;
case AV_CODEC_ID_ADPCM_AFC:
nb_samples = buf_size / (9 * ch) * 16;
break;
case AV_CODEC_ID_ADPCM_XA:
nb_samples = (buf_size / 128) * 224 / ch;
break;
@ -1232,6 +1236,44 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
*samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
}
break;
case AV_CODEC_ID_ADPCM_AFC:
for (channel = 0; channel < avctx->channels; channel++) {
int prev1 = c->status[channel].sample1;
int prev2 = c->status[channel].sample2;
samples = samples_p[channel];
/* Read in every sample for this channel. */
for (i = 0; i < nb_samples / 16; i++) {
int byte = bytestream2_get_byteu(&gb);
int scale = 1 << (byte >> 4);
int index = byte & 0xf;
int factor1 = ff_adpcm_afc_coeffs[0][index];
int factor2 = ff_adpcm_afc_coeffs[1][index];
/* Decode 16 samples. */
for (n = 0; n < 16; n++) {
int32_t sampledat;
if (n & 1) {
sampledat = sign_extend(byte, 4);
} else {
byte = bytestream2_get_byteu(&gb);
sampledat = sign_extend(byte >> 4, 4);
}
sampledat = ((prev1 * factor1 + prev2 * factor2) +
((sampledat * scale) << 11)) >> 11;
*samples = av_clip_int16(sampledat);
prev2 = prev1;
prev1 = *samples++;
}
}
c->status[channel].sample1 = prev1;
c->status[channel].sample2 = prev2;
}
bytestream2_seek(&gb, 0, SEEK_END);
break;
case AV_CODEC_ID_ADPCM_THP:
{
int table[2][16];
@ -1314,6 +1356,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_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");

View File

@ -76,3 +76,8 @@ const int8_t ff_adpcm_yamaha_difflookup[] = {
1, 3, 5, 7, 9, 11, 13, 15,
-1, -3, -5, -7, -9, -11, -13, -15
};
const int16_t ff_adpcm_afc_coeffs[2][16] = {
{ 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, 64512, 64512, 63488 },
{ 0, 0, 2048, 1024, 63488, 64000, 64512, 62976, 63288, 63236, 62464, 63488, 64512, 1024, 0, 0 }
};

View File

@ -35,5 +35,6 @@ extern const uint8_t ff_adpcm_AdaptCoeff1[];
extern const int8_t ff_adpcm_AdaptCoeff2[];
extern const int16_t ff_adpcm_yamaha_indexscale[];
extern const int8_t ff_adpcm_yamaha_difflookup[];
extern const int16_t ff_adpcm_afc_coeffs[2][16];
#endif /* AVCODEC_ADPCM_DATA_H */

View File

@ -387,6 +387,7 @@ void avcodec_register_all(void)
/* ADPCM codecs */
REGISTER_DECODER (ADPCM_4XM, adpcm_4xm);
REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx);
REGISTER_DECODER (ADPCM_AFC, adpcm_afc);
REGISTER_DECODER (ADPCM_CT, adpcm_ct);
REGISTER_DECODER (ADPCM_EA, adpcm_ea);
REGISTER_DECODER (ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa);

View File

@ -352,6 +352,7 @@ enum AVCodecID {
AV_CODEC_ID_ADPCM_G722,
AV_CODEC_ID_ADPCM_IMA_APC,
AV_CODEC_ID_VIMA = MKBETAG('V','I','M','A'),
AV_CODEC_ID_ADPCM_AFC = MKBETAG('A','F','C',' '),
/* AMR */
AV_CODEC_ID_AMR_NB = 0x12000,

View File

@ -1756,6 +1756,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA CRYO APC"),
.props = AV_CODEC_PROP_LOSSY,
},
{
.id = AV_CODEC_ID_ADPCM_AFC,
.type = AVMEDIA_TYPE_AUDIO,
.name = "adpcm_afc",
.long_name = NULL_IF_CONFIG_SMALL("ADPCM Nintendo Gamecube AFC"),
.props = AV_CODEC_PROP_LOSSY,
},
/* AMR */
{

View File

@ -29,7 +29,7 @@
#include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 75
#define LIBAVCODEC_VERSION_MINOR 76
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

View File

@ -43,6 +43,9 @@ static int ast_read_header(AVFormatContext *s)
avio_skip(s->pb, 8);
codec = avio_rb16(s->pb);
switch (codec) {
case 0:
st->codec->codec_id = AV_CODEC_ID_ADPCM_AFC;
break;
case 1:
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE_PLANAR;
break;