From 9e8a7e89a1264c5197f26c86bf8a6f8d043ad379 Mon Sep 17 00:00:00 2001 From: halleyscometsw Date: Wed, 3 Mar 2010 05:14:33 +0000 Subject: [PATCH] 16-bit support for .his git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@753 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- src/meta/his.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/meta/his.c b/src/meta/his.c index d95af742..345de95f 100644 --- a/src/meta/his.c +++ b/src/meta/his.c @@ -2,12 +2,14 @@ #include "../util.h" /* Her Interactive Sound .his (Nancy Drew) */ +/* A somewhat transformed RIFF WAVE */ VGMSTREAM * init_vgmstream_his(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; char filename[260]; int channel_count; int loop_flag = 0; + int bps = 0; off_t start_offset; const uint8_t header_magic_expected[0x16] = "Her Interactive Sound\x1a"; uint8_t header_magic[0x16]; @@ -18,7 +20,6 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *streamFile) { /* check header magic */ if (0x16 != streamFile->read(streamFile, header_magic, 0, 0x16)) goto fail; - if (memcmp(header_magic_expected, header_magic, 0x16)) goto fail; /* data chunk label */ @@ -26,36 +27,59 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *streamFile) { start_offset = 0x2c; - /* channel count is there twice, or one is bytes per frame */ channel_count = read_16bitLE(0x16,streamFile); - if (read_16bitLE(0x20,streamFile) != channel_count) goto fail; - /* 8-bit expected */ - if (read_16bitLE(0x22,streamFile) != 8) goto fail; + /* 8-bit or 16-bit expected */ + switch (read_16bitLE(0x22,streamFile)) + { + case 8: + bps = 1; + break; + case 16: + bps = 2; + break; + default: + goto fail; + } + + /* check bytes per frame */ + if (read_16bitLE(0x20,streamFile) != channel_count*bps) goto fail; /* check size */ - /* file size -8, I assume taken from RIFF, though it doesn't describe this format well */ + /* file size -8 */ if ((read_32bitLE(0x1c,streamFile)+8) != get_streamfile_size(streamFile)) goto fail; /* data chunk size, assume it occupies the rest of the file */ - if ((read_32bitLE(0x28,streamFile)+start_offset) != get_streamfile_size(streamFile)) - goto fail; + //if ((read_32bitLE(0x28,streamFile)+start_offset) != get_streamfile_size(streamFile)) + // goto fail; /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; /* fill in the vital statistics */ - vgmstream->num_samples = read_32bitLE(0x28,streamFile) / channel_count; + vgmstream->num_samples = read_32bitLE(0x28,streamFile) / channel_count / bps; vgmstream->sample_rate = read_32bitLE(0x18,streamFile); - vgmstream->coding_type = coding_PCM8_U; vgmstream->meta_type = meta_HIS; vgmstream->layout_type = layout_none; - if (channel_count == 2) + if (bps == 2) { - vgmstream->coding_type = coding_PCM8_U_int; - vgmstream->interleave_block_size = 1; + vgmstream->coding_type = coding_PCM16LE; + if (channel_count == 2) + { + vgmstream->coding_type = coding_PCM16LE_int; + vgmstream->interleave_block_size = 2; + } + } + else // bps == 1 + { + vgmstream->coding_type = coding_PCM8_U; + if (channel_count == 2) + { + vgmstream->coding_type = coding_PCM8_U_int; + vgmstream->interleave_block_size = 1; + } } /* open the file for reading */