mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec: add adpcm MTAF decoder
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
e7c5dbb4d1
commit
8c17eea46f
@ -707,6 +707,7 @@ OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_MTAF_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_PSX_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o adpcm_data.o
|
||||
OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o adpcm_data.o
|
||||
|
@ -107,6 +107,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
|
||||
case AV_CODEC_ID_ADPCM_EA_XAS:
|
||||
max_channels = 6;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
min_channels = 2;
|
||||
max_channels = 8;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_PSX:
|
||||
max_channels = 8;
|
||||
break;
|
||||
@ -159,6 +163,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
|
||||
case AV_CODEC_ID_ADPCM_AFC:
|
||||
case AV_CODEC_ID_ADPCM_DTK:
|
||||
case AV_CODEC_ID_ADPCM_PSX:
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_IMA_WS:
|
||||
@ -342,6 +347,15 @@ static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t
|
||||
return c->predictor;
|
||||
}
|
||||
|
||||
static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
|
||||
{
|
||||
c->predictor += ff_adpcm_mtaf_stepsize[c->step][nibble];
|
||||
c->predictor = av_clip_int16(c->predictor);
|
||||
c->step += ff_adpcm_index_table[nibble];
|
||||
c->step = av_clip_uintp2(c->step, 5);
|
||||
return c->predictor;
|
||||
}
|
||||
|
||||
static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
|
||||
const uint8_t *in, ADPCMChannelStatus *left,
|
||||
ADPCMChannelStatus *right, int channels, int sample_offset)
|
||||
@ -617,6 +631,11 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
||||
buf_size = FFMIN(buf_size, avctx->block_align);
|
||||
nb_samples = (buf_size - 6 * ch) * 2 / ch;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
if (avctx->block_align > 0)
|
||||
buf_size = FFMIN(buf_size, avctx->block_align);
|
||||
nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_SBPRO_2:
|
||||
case AV_CODEC_ID_ADPCM_SBPRO_3:
|
||||
case AV_CODEC_ID_ADPCM_SBPRO_4:
|
||||
@ -887,6 +906,27 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
for (channel = 0; channel < avctx->channels; channel+=2) {
|
||||
bytestream2_skipu(&gb, 4);
|
||||
c->status[channel ].step = bytestream2_get_le16u(&gb);
|
||||
c->status[channel + 1].step = bytestream2_get_le16u(&gb);
|
||||
c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
|
||||
bytestream2_skipu(&gb, 2);
|
||||
c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
|
||||
bytestream2_skipu(&gb, 2);
|
||||
for (n = 0; n < nb_samples; n+=2) {
|
||||
int v = bytestream2_get_byteu(&gb);
|
||||
samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
|
||||
samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 );
|
||||
}
|
||||
for (n = 0; n < nb_samples; n+=2) {
|
||||
int v = bytestream2_get_byteu(&gb);
|
||||
samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
|
||||
samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AV_CODEC_ID_ADPCM_IMA_DK4:
|
||||
for (channel = 0; channel < avctx->channels; channel++) {
|
||||
cs = &c->status[channel];
|
||||
@ -1706,6 +1746,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg,
|
||||
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_s16, adpcm_ms, "ADPCM Microsoft");
|
||||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF");
|
||||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation");
|
||||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
|
||||
ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
|
||||
|
@ -110,3 +110,70 @@ 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 }
|
||||
};
|
||||
|
||||
const int16_t ff_adpcm_mtaf_stepsize[32][16] = {
|
||||
{ 1, 5, 9, 13, 16, 20, 24, 28,
|
||||
-1, -5, -9, -13, -16, -20, -24, -28, },
|
||||
{ 2, 6, 11, 15, 20, 24, 29, 33,
|
||||
-2, -6, -11, -15, -20, -24, -29, -33, },
|
||||
{ 2, 7, 13, 18, 23, 28, 34, 39,
|
||||
-2, -7, -13, -18, -23, -28, -34, -39, },
|
||||
{ 3, 9, 15, 21, 28, 34, 40, 46,
|
||||
-3, -9, -15, -21, -28, -34, -40, -46, },
|
||||
{ 3, 11, 18, 26, 33, 41, 48, 56,
|
||||
-3, -11, -18, -26, -33, -41, -48, -56, },
|
||||
{ 4, 13, 22, 31, 40, 49, 58, 67,
|
||||
-4, -13, -22, -31, -40, -49, -58, -67, },
|
||||
{ 5, 16, 26, 37, 48, 59, 69, 80,
|
||||
-5, -16, -26, -37, -48, -59, -69, -80, },
|
||||
{ 6, 19, 31, 44, 57, 70, 82, 95,
|
||||
-6, -19, -31, -44, -57, -70, -82, -95, },
|
||||
{ 7, 22, 38, 53, 68, 83, 99, 114,
|
||||
-7, -22, -38, -53, -68, -83, -99, -114, },
|
||||
{ 9, 27, 45, 63, 81, 99, 117, 135,
|
||||
-9, -27, -45, -63, -81, -99, -117, -135, },
|
||||
{ 10, 32, 53, 75, 96, 118, 139, 161,
|
||||
-10, -32, -53, -75, -96, -118, -139, -161, },
|
||||
{ 12, 38, 64, 90, 115, 141, 167, 193,
|
||||
-12, -38, -64, -90, -115, -141, -167, -193, },
|
||||
{ 15, 45, 76, 106, 137, 167, 198, 228,
|
||||
-15, -45, -76, -106, -137, -167, -198, -228, },
|
||||
{ 18, 54, 91, 127, 164, 200, 237, 273,
|
||||
-18, -54, -91, -127, -164, -200, -237, -273, },
|
||||
{ 21, 65, 108, 152, 195, 239, 282, 326,
|
||||
-21, -65, -108, -152, -195, -239, -282, -326, },
|
||||
{ 25, 77, 129, 181, 232, 284, 336, 388,
|
||||
-25, -77, -129, -181, -232, -284, -336, -388, },
|
||||
{ 30, 92, 153, 215, 276, 338, 399, 461,
|
||||
-30, -92, -153, -215, -276, -338, -399, -461, },
|
||||
{ 36, 109, 183, 256, 329, 402, 476, 549,
|
||||
-36, -109, -183, -256, -329, -402, -476, -549, },
|
||||
{ 43, 130, 218, 305, 392, 479, 567, 654,
|
||||
-43, -130, -218, -305, -392, -479, -567, -654, },
|
||||
{ 52, 156, 260, 364, 468, 572, 676, 780,
|
||||
-52, -156, -260, -364, -468, -572, -676, -780, },
|
||||
{ 62, 186, 310, 434, 558, 682, 806, 930,
|
||||
-62, -186, -310, -434, -558, -682, -806, -930, },
|
||||
{ 73, 221, 368, 516, 663, 811, 958, 1106,
|
||||
-73, -221, -368, -516, -663, -811, -958, -1106, },
|
||||
{ 87, 263, 439, 615, 790, 966, 1142, 1318,
|
||||
-87, -263, -439, -615, -790, -966, -1142, -1318, },
|
||||
{ 104, 314, 523, 733, 942, 1152, 1361, 1571,
|
||||
-104, -314, -523, -733, -942, -1152, -1361, -1571, },
|
||||
{ 124, 374, 623, 873, 1122, 1372, 1621, 1871,
|
||||
-124, -374, -623, -873, -1122, -1372, -1621, -1871, },
|
||||
{ 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
|
||||
-148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
|
||||
{ 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
|
||||
-177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
|
||||
{ 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
|
||||
-210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
|
||||
{ 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
|
||||
-251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
|
||||
{ 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
|
||||
-299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
|
||||
{ 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
|
||||
-356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
|
||||
{ 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
|
||||
-424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
|
||||
};
|
||||
|
@ -41,5 +41,6 @@ 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];
|
||||
extern const int16_t ff_adpcm_mtaf_stepsize[32][16];
|
||||
|
||||
#endif /* AVCODEC_ADPCM_DATA_H */
|
||||
|
@ -524,6 +524,7 @@ void avcodec_register_all(void)
|
||||
REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
|
||||
REGISTER_DECODER(ADPCM_IMA_WS, adpcm_ima_ws);
|
||||
REGISTER_ENCDEC (ADPCM_MS, adpcm_ms);
|
||||
REGISTER_DECODER(ADPCM_MTAF, adpcm_mtaf);
|
||||
REGISTER_DECODER(ADPCM_PSX, adpcm_psx);
|
||||
REGISTER_DECODER(ADPCM_SBPRO_2, adpcm_sbpro_2);
|
||||
REGISTER_DECODER(ADPCM_SBPRO_3, adpcm_sbpro_3);
|
||||
|
@ -489,6 +489,7 @@ enum AVCodecID {
|
||||
AV_CODEC_ID_ADPCM_PSX,
|
||||
AV_CODEC_ID_ADPCM_AICA,
|
||||
AV_CODEC_ID_ADPCM_IMA_DAT4,
|
||||
AV_CODEC_ID_ADPCM_MTAF,
|
||||
|
||||
/* AMR */
|
||||
AV_CODEC_ID_AMR_NB = 0x12000,
|
||||
|
@ -2690,6 +2690,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
|
||||
.long_name = NULL_IF_CONFIG_SMALL("DST (Direct Stream Transfer)"),
|
||||
.props = AV_CODEC_PROP_LOSSLESS,
|
||||
},
|
||||
{
|
||||
.id = AV_CODEC_ID_ADPCM_MTAF,
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.name = "adpcm_mtaf",
|
||||
.long_name = NULL_IF_CONFIG_SMALL("ADPCM MTAF"),
|
||||
.props = AV_CODEC_PROP_LOSSY,
|
||||
},
|
||||
|
||||
/* subtitle codecs */
|
||||
{
|
||||
|
@ -3601,6 +3601,8 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
|
||||
return blocks * ((ba - 4 * ch) * 2 / ch);
|
||||
case AV_CODEC_ID_ADPCM_MS:
|
||||
return blocks * (2 + (ba - 7 * ch) * 2 / ch);
|
||||
case AV_CODEC_ID_ADPCM_MTAF:
|
||||
return blocks * (ba - 16) * 2 / ch;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "libavutil/version.h"
|
||||
|
||||
#define LIBAVCODEC_VERSION_MAJOR 57
|
||||
#define LIBAVCODEC_VERSION_MINOR 42
|
||||
#define LIBAVCODEC_VERSION_MINOR 43
|
||||
#define LIBAVCODEC_VERSION_MICRO 100
|
||||
|
||||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
||||
|
Loading…
Reference in New Issue
Block a user