| @@ -324,6 +324,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 323 unmodified lines |
| 324 | 324 | case AV_CODEC_ID_ADPCM_IMA_WAV: |
| 325 | 325 | case AV_CODEC_ID_ADPCM_4XM: |
| 326 | 326 | case AV_CODEC_ID_ADPCM_XA: |
| 327 | + case AV_CODEC_ID_ADPCM_XMD: |
| 327 | 328 | case AV_CODEC_ID_ADPCM_EA_R1: |
| 328 | 329 | case AV_CODEC_ID_ADPCM_EA_R2: |
| 329 | 330 | case AV_CODEC_ID_ADPCM_EA_R3: |
| @@ -1043,6 +1044,9 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 713 unmodified lines |
| 1043 | 1044 | case AV_CODEC_ID_ADPCM_XA: |
| 1044 | 1045 | nb_samples = (buf_size / 128) * 224 / ch; |
| 1045 | 1046 | break; |
| 1047 | + case AV_CODEC_ID_ADPCM_XMD: |
| 1048 | + nb_samples = buf_size / (21 * ch) * 32; |
| 1049 | + break; |
| 1046 | 1050 | case AV_CODEC_ID_ADPCM_DTK: |
| 1047 | 1051 | case AV_CODEC_ID_ADPCM_PSX: |
| 1048 | 1052 | nb_samples = buf_size / (16 * ch) * 28; |
| @@ -1553,6 +1557,45 @@ static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 504 unmodified lines |
| 1553 | 1557 | } |
| 1554 | 1558 | bytestream2_seek(&gb, 0, SEEK_END); |
| 1555 | 1559 | ) /* 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 */ |
| 1556 | 1599 | CASE(ADPCM_XA, |
| 1557 | 1600 | int16_t *out0 = samples_p[0]; |
| 1558 | 1601 | int16_t *out1 = samples_p[1]; |
| @@ -2350,5 +2393,6 @@ ADPCM_DECODER(ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Sho · 791 unmodified lines |
| 2350 | 2393 | ADPCM_DECODER(ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)") |
| 2351 | 2394 | ADPCM_DECODER(ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP") |
| 2352 | 2395 | 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") |
| 2353 | 2397 | ADPCM_DECODER(ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha") |
| 2354 | 2398 | ADPCM_DECODER(ADPCM_ZORK, sample_fmts_s16, adpcm_zork, "ADPCM Zork") |