From f29012edb71f51172901fae33e3c893164ac06f7 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 22 Sep 2018 17:45:02 +0200 Subject: [PATCH] Add Capcom .adpcm [Resident Evil: Revelations (Switch)] --- src/formats.c | 1 + src/libvgmstream.vcproj | 4 +++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/adpcm_capcom.c | 49 ++++++++++++++++++++++++++++++++ src/meta/meta.h | 2 ++ src/vgmstream.c | 1 + src/vgmstream.h | 1 + 8 files changed, 62 insertions(+) create mode 100644 src/meta/adpcm_capcom.c diff --git a/src/formats.c b/src/formats.c index 072f7065..ccab8be0 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1092,6 +1092,7 @@ static const meta_info meta_info_list[] = { {meta_DERF, "Xilam DERF header"}, {meta_UTK, "Maxis UTK header"}, {meta_NXA, "Entergram NXA header"}, + {meta_ADPCM_CAPCOM, "Capcom .ADPCM header"}, }; diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 89e0e24e..2d479cec 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -332,6 +332,10 @@ RelativePath=".\meta\acm.c" > + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 8a4445e3..40a7df1f 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -204,6 +204,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index cf058c9f..3d9f168f 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -211,6 +211,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/adpcm_capcom.c b/src/meta/adpcm_capcom.c new file mode 100644 index 00000000..e55ee8d2 --- /dev/null +++ b/src/meta/adpcm_capcom.c @@ -0,0 +1,49 @@ +#include "meta.h" +#include "../coding/coding.h" +#include "../util.h" + + +/* .ADX - from Capcom games [Resident Evil: Revelations (Switch), Monster Hunter XX (Switch)] */ +VGMSTREAM * init_vgmstream_adpcm_capcom(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + off_t start_offset; + int loop_flag, channel_count; + + + /* checks */ + if (!check_extensions(streamFile,"adpcm")) + goto fail; + if (read_32bitBE(0x00,streamFile) != 0x02000000) + goto fail; + + channel_count = read_16bitLE(0x04, streamFile); + if (channel_count > 2) goto fail; /* header size seems fixed for mono/stereo */ + /* 0x08: channel size */ + /* 0x0c-14: some config/id? (may be shared between files) */ + loop_flag = read_16bitLE(0x68, streamFile); + + start_offset = 0xd8; /* also fixed for mono/stereo */ + + + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_ADPCM_CAPCOM; + vgmstream->sample_rate = read_32bitLE(0x64,streamFile); /* from first headerm repeated at +0x60 */ + vgmstream->num_samples = read_32bitLE(0x60, streamFile); + vgmstream->loop_start_sample = read_32bitLE(0x6c, streamFile); + vgmstream->loop_end_sample = read_32bitLE(0x70, streamFile) + 1; + + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = read_16bitLE(0x06, streamFile); + dsp_read_coefs_le(vgmstream,streamFile, 0x18, 0x60); + + if (!vgmstream_open_stream(vgmstream,streamFile, start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/meta.h b/src/meta/meta.h index c6cbecce..d129fd2f 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -789,4 +789,6 @@ VGMSTREAM * init_vgmstream_derf(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_utk(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_adpcm_capcom(STREAMFILE *streamFile); + #endif /*_META_H*/ diff --git a/src/vgmstream.c b/src/vgmstream.c index 9727c5b7..67369771 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -439,6 +439,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_xau_konami, init_vgmstream_derf, init_vgmstream_utk, + init_vgmstream_adpcm_capcom, /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ diff --git a/src/vgmstream.h b/src/vgmstream.h index 94a63e29..a42e97b4 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -704,6 +704,7 @@ typedef enum { meta_DERF, /* Stupid Invaders (PC) */ meta_UTK, meta_NXA, + meta_ADPCM_CAPCOM, } meta_t;