History

avcodec: add ADPCM XMD decoder

Paul B Mahol committed 3 years ago

Commit 280e6e91 parent 9bfdd858 files · +59 −1Browse files

Unified · Split

8 files
  1. Changelog +1 −0
  2. libavcodec/Makefile +1 −0
  3. libavcodec/adpcm.c +44 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/codec_desc.c +7 −0
  6. libavcodec/codec_id.h +1 −0
  7. libavcodec/utils.c +3 −0
  8. libavcodec/version.h +1 −1
Changelog+1−0
@@ -34,6 +34,7 @@ version <next>: · 33 unmodified lines
3434 - ssim360 video filter
3535 - ffmpeg CLI new options: -enc_stats_pre[_fmt], -enc_stats_post[_fmt]
3636 - hstack_vaapi, vstack_vaapi and xstack_vaapi filters
37+- XMD ADPCM decoder
3738
3839
3940 version 5.1:
libavcodec/Makefile+1−0
@@ -959,6 +959,7 @@ OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o adpcm_data.o · 958 unmodified lines
959959 OBJS-$(CONFIG_ADPCM_THP_LE_DECODER) += adpcm.o adpcm_data.o
960960 OBJS-$(CONFIG_ADPCM_VIMA_DECODER) += vima.o adpcm_data.o
961961 OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o adpcm_data.o
962+OBJS-$(CONFIG_ADPCM_XMD_DECODER) += adpcm.o adpcm_data.o
962963 OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o
963964 OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o
964965 OBJS-$(CONFIG_ADPCM_ZORK_DECODER) += adpcm.o adpcm_data.o
libavcodec/adpcm.c+44−0
@@ -324,6 +324,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 323 unmodified lines
324324 case AV_CODEC_ID_ADPCM_IMA_WAV:
325325 case AV_CODEC_ID_ADPCM_4XM:
326326 case AV_CODEC_ID_ADPCM_XA:
327+ case AV_CODEC_ID_ADPCM_XMD:
327328 case AV_CODEC_ID_ADPCM_EA_R1:
328329 case AV_CODEC_ID_ADPCM_EA_R2:
329330 case AV_CODEC_ID_ADPCM_EA_R3:
@@ -1043,6 +1044,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 713 unmodified lines
10431044 case AV_CODEC_ID_ADPCM_XA:
10441045 nb_samples = (buf_size / 128) * 224 / ch;
10451046 break;
1047+ case AV_CODEC_ID_ADPCM_XMD:
1048+ nb_samples = buf_size / (21 * ch) * 32;
1049+ break;
10461050 case AV_CODEC_ID_ADPCM_DTK:
10471051 case AV_CODEC_ID_ADPCM_PSX:
10481052 nb_samples = buf_size / (16 * ch) * 28;
@@ -1553,6 +1557,45 @@ static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 504 unmodified lines
15531557 }
15541558 bytestream2_seek(&gb, 0, SEEK_END);
15551559 ) /* End of CASE */
1560+ CASE(ADPCM_XMD,
1561+ int bytes_remaining, block = 0;
1562+ while (bytestream2_get_bytes_left(&gb) >= 21 * channels) {
1563+ for (int channel = 0; channel < channels; channel++) {
1564+ int16_t *out = samples_p[channel] + block * 32;
1565+ int16_t history[2];
1566+ uint16_t scale;
1567+
1568+ history[1] = sign_extend(bytestream2_get_le16(&gb), 16);
1569+ history[0] = sign_extend(bytestream2_get_le16(&gb), 16);
1570+ scale = bytestream2_get_le16(&gb);
1571+
1572+ out[0] = history[1];
1573+ out[1] = history[0];
1574+
1575+ for (int n = 0; n < 15; n++) {
1576+ unsigned byte = bytestream2_get_byte(&gb);
1577+ int32_t nibble[2];
1578+
1579+ nibble[0] = sign_extend(byte & 15, 4);
1580+ nibble[1] = sign_extend(byte >> 4, 4);
1581+
1582+ out[2+n*2] = (nibble[0]*(scale<<14) + (history[0]*29336) - (history[1]*13136)) >> 14;
1583+ history[1] = history[0];
1584+ history[0] = out[2+n*2];
1585+
1586+ out[2+n*2+1] = (nibble[1]*(scale<<14) + (history[0]*29336) - (history[1]*13136)) >> 14;
1587+ history[1] = history[0];
1588+ history[0] = out[2+n*2+1];
1589+ }
1590+ }
1591+
1592+ block++;
1593+ }
1594+ bytes_remaining = bytestream2_get_bytes_left(&gb);
1595+ if (bytes_remaining > 0) {
1596+ bytestream2_skip(&gb, bytes_remaining);
1597+ }
1598+ ) /* End of CASE */
15561599 CASE(ADPCM_XA,
15571600 int16_t *out0 = samples_p[0];
15581601 int16_t *out1 = samples_p[1];
@@ -2350,5 +2393,6 @@ ADPCM_DECODER(ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Sho · 791 unmodified lines
23502393 ADPCM_DECODER(ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)")
23512394 ADPCM_DECODER(ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP")
23522395 ADPCM_DECODER(ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA")
2396+ADPCM_DECODER(ADPCM_XMD, sample_fmts_s16p, adpcm_xmd, "ADPCM Konami XMD")
23532397 ADPCM_DECODER(ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha")
23542398 ADPCM_DECODER(ADPCM_ZORK, sample_fmts_s16, adpcm_zork, "ADPCM Zork")
libavcodec/allcodecs.c+1−0
@@ -695,6 +695,7 @@ extern const FFCodec ff_adpcm_thp_decoder; · 694 unmodified lines
695695 extern const FFCodec ff_adpcm_thp_le_decoder;
696696 extern const FFCodec ff_adpcm_vima_decoder;
697697 extern const FFCodec ff_adpcm_xa_decoder;
698+extern const FFCodec ff_adpcm_xmd_decoder;
698699 extern const FFCodec ff_adpcm_yamaha_encoder;
699700 extern const FFCodec ff_adpcm_yamaha_decoder;
700701 extern const FFCodec ff_adpcm_zork_decoder;
libavcodec/codec_desc.c+7−0
@@ -2536,6 +2536,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 2535 unmodified lines
25362536 .long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA Acorn Replay"),
25372537 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
25382538 },
2539+ {
2540+ .id = AV_CODEC_ID_ADPCM_XMD,
2541+ .type = AVMEDIA_TYPE_AUDIO,
2542+ .name = "adpcm_xmd",
2543+ .long_name = NULL_IF_CONFIG_SMALL("ADPCM Konami XMD"),
2544+ .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
2545+ },
25392546
25402547 /* AMR */
25412548 {
libavcodec/codec_id.h+1−0
@@ -413,6 +413,7 @@ enum AVCodecID { · 412 unmodified lines
413413 AV_CODEC_ID_ADPCM_IMA_CUNNING,
414414 AV_CODEC_ID_ADPCM_IMA_MOFLEX,
415415 AV_CODEC_ID_ADPCM_IMA_ACORN,
416+ AV_CODEC_ID_ADPCM_XMD,
416417
417418 /* AMR */
418419 AV_CODEC_ID_AMR_NB = 0x12000,
libavcodec/utils.c+3−0
@@ -769,6 +769,9 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, · 768 unmodified lines
769769 case AV_CODEC_ID_ADPCM_MTAF:
770770 tmp = blocks * (ba - 16LL) * 2 / ch;
771771 break;
772+ case AV_CODEC_ID_ADPCM_XMD:
773+ tmp = blocks * 32;
774+ break;
772775 }
773776 if (tmp) {
774777 if (tmp != (int)tmp)
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929
3030 #include "version_major.h"
3131
32−#define LIBAVCODEC_VERSION_MINOR 59
32+#define LIBAVCODEC_VERSION_MINOR 60
3333 #define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t