From 40c23dc3f56f1f4dcdd0a36d94a7057b211ba7a4 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 24 Feb 2019 11:34:09 +0100 Subject: [PATCH] Add Vicious Cycle .mus [Dinotopia (Xbox/GC)] --- src/formats.c | 1 + src/libvgmstream.vcproj | 12 +++-- src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/meta.h | 2 + src/meta/mus_vc.c | 79 ++++++++++++++++++++++++++++++++ src/vgmstream.c | 1 + src/vgmstream.h | 1 + 8 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 src/meta/mus_vc.c diff --git a/src/formats.c b/src/formats.c index d6b58b01..cc28be94 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1172,6 +1172,7 @@ static const meta_info meta_info_list[] = { {meta_DSF, "Ocean DSF header"}, {meta_208, "Ocean .208 header"}, {meta_DSP_DS2, "LucasArts .DS2 header"}, + {meta_MUS_VC, "Vicious Cycle .MUS header"}, }; diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 52b81040..f0fa94ef 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -704,10 +704,14 @@ RelativePath=".\meta\mogg.c" > - - + + + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 81cd6900..3061f781 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -288,6 +288,7 @@ + $(IntDir)%(Filename)1.obj $(IntDir)%(Filename)1.xdc diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index c53d15a5..5417cf02 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -439,6 +439,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/meta.h b/src/meta/meta.h index 27a1f954..bc82fd78 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -833,4 +833,6 @@ VGMSTREAM * init_vgmstream_208(STREAMFILE * streamFile); VGMSTREAM * init_vgmstream_ffdl(STREAMFILE * streamFile); +VGMSTREAM * init_vgmstream_mus_vc(STREAMFILE * streamFile); + #endif /*_META_H*/ diff --git a/src/meta/mus_vc.c b/src/meta/mus_vc.c new file mode 100644 index 00000000..1159b5ce --- /dev/null +++ b/src/meta/mus_vc.c @@ -0,0 +1,79 @@ +#include "meta.h" +#include "../coding/coding.h" + +/* .MUS - Vicious Cycle games [Dinotopia: The Sunstone Odyssey (GC/Xbox), Robotech: Battlecry (PS2/Xbox)] */ +VGMSTREAM * init_vgmstream_mus_vc(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + off_t start_offset; + int loop_flag, channel_count, sample_rate; + int big_endian, type; + int32_t(*read_32bit)(off_t, STREAMFILE*) = NULL; + + + /* checks */ + if (!check_extensions(streamFile, "mus")) + goto fail; + + if (read_32bitBE(0x08,streamFile) != 0xBBBBBBBB && + read_32bitBE(0x14,streamFile) != 0xBBBBBBBB && + read_32bitBE(0x2c,streamFile) != 0xBEBEBEBE) + goto fail; + + big_endian = (read_32bitBE(0x00,streamFile) == 0xFBBFFBBF); + read_32bit = big_endian ? read_32bitBE : read_32bitLE; + + type = read_32bit(0x04, streamFile); + /* 0x08: pseudo size? */ + /* other fields may be chunk sizes and lesser stuff */ + /* 0x88: codec header */ + + channel_count = read_32bit(0x54,streamFile); /* assumed */ + if (channel_count != 1) goto fail; + sample_rate = read_32bit(0x58,streamFile); + loop_flag = 1; /* most files repeat except small jingles, but smaller ambient tracks also repeat */ + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_MUS_VC; + vgmstream->sample_rate = sample_rate; + + switch(type) { + case 0x01: + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_none; + vgmstream->num_samples = dsp_bytes_to_samples(read_32bit(0xB0,streamFile), vgmstream->channels); + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = vgmstream->num_samples; + + start_offset = 0xB8; + dsp_read_coefs_be(vgmstream,streamFile,0x88,0x00); + dsp_read_hist_be (vgmstream,streamFile,0xac,0x00); + break; + + case 0x02: + vgmstream->coding_type = coding_XBOX_IMA; + vgmstream->layout_type = layout_none; + vgmstream->num_samples = xbox_ima_bytes_to_samples(read_32bit(0x9a,streamFile), vgmstream->channels); + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = vgmstream->num_samples; + + start_offset = 0x9e; + break; + + default: + goto fail; + } + + read_string(vgmstream->stream_name,0x14, 0x34,streamFile); /* repeated at 0x64, size at 0x30/0x60 */ + + if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/vgmstream.c b/src/vgmstream.c index 01209f9a..403116aa 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -467,6 +467,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_208, init_vgmstream_dsp_ds2, init_vgmstream_ffdl, + init_vgmstream_mus_vc, /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */ diff --git a/src/vgmstream.h b/src/vgmstream.h index a62bd481..7b000c69 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -720,6 +720,7 @@ typedef enum { meta_DSF, meta_208, meta_DSP_DS2, + meta_MUS_VC, } meta_t;