From bd8dad46df12cb998ac4e6f1d20b26000391a621 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 10 Aug 2019 17:24:06 +0200 Subject: [PATCH] Clean .rsd and fix some bugs --- src/formats.c | 20 +- src/meta/meta.h | 20 +- src/meta/rsd.c | 1368 +++++++---------------------------------------- src/vgmstream.c | 20 +- src/vgmstream.h | 22 +- 5 files changed, 204 insertions(+), 1246 deletions(-) diff --git a/src/formats.c b/src/formats.c index 861d844e..2c43467c 100644 --- a/src/formats.c +++ b/src/formats.c @@ -904,24 +904,7 @@ static const meta_info meta_info_list[] = { {meta_PS2_MIHB, "Sony MultiStream MIC header"}, {meta_DSP_WII_MUS, "mus header"}, {meta_WII_SNG, "SNG DSP Header"}, - {meta_RSD2VAG, "Radical RSD2/VAG header"}, - {meta_RSD2PCMB, "Radical RSD2/PCMB header"}, - {meta_RSD2XADP, "Radical RSD2/XADP header"}, - {meta_RSD3VAG, "Radical RSD3/VAG header"}, - {meta_RSD3GADP, "Radical RSD3/GADP header"}, - {meta_RSD3PCM, "Radical RSD3/PCM header"}, - {meta_RSD3PCMB, "Radical RSD3/PCMB header"}, - {meta_RSD4PCMB, "Radical RSD4/PCMB header"}, - {meta_RSD4PCM, "Radical RSD4/PCM header"}, - {meta_RSD4RADP, "Radical RSD4/RADP header"}, - {meta_RSD4VAG, "Radical RSD4/VAG header"}, - {meta_RSD6XADP, "Radical RSD6/XADP header"}, - {meta_RSD6VAG, "Radical RSD6/VAG header"}, - {meta_RSD6WADP, "Radical RSD6/WADP header"}, - {meta_RSD6RADP, "Radical RSD6/RADP header"}, - {meta_RSD6XMA, "Radical RSD6/XMA header"}, - {meta_RSD6AT3P, "Radical RSD6/AT3+ header"}, - {meta_RSD6WMA, "Radical RSD6/WMA header"}, + {meta_RSD, "Radical RSD header"}, {meta_DC_ASD, "ASD Header"}, {meta_NAOMI_SPSD, "Naomi SPSD header"}, {meta_FFXI_BGW, "Square Enix .BGW header"}, @@ -1063,7 +1046,6 @@ static const meta_info meta_info_list[] = { {meta_PS2_HSF, "Lowrider 'HSF' header"}, {meta_PS3_IVAG, "PS3 'IVAG' Header"}, {meta_PS2_2PFS, "Konami 2PFS header"}, - {meta_RSD6OOGV, "RSD6/OOGV Header"}, {meta_UBI_CKD, "Ubisoft CKD RIFF header"}, {meta_PS2_VBK, "PS2 VBK Header"}, {meta_OTM, "Otomedius OTM Header"}, diff --git a/src/meta/meta.h b/src/meta/meta.h index e2a26c27..8f128e9c 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -302,25 +302,7 @@ VGMSTREAM * init_vgmstream_ngc_pdt(STREAMFILE * streamFile); VGMSTREAM * init_vgmstream_wii_mus(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd2vag(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd2pcmb(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd2xadp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd3pcm(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd3pcmb(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd3gadp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd3vag(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd4pcmb(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd4pcm(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd4radp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd4vag(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6vag(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6wadp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6xadp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6radp(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6oogv(STREAMFILE* streamFile); -VGMSTREAM * init_vgmstream_rsd6xma(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_rsd6at3p(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_rsd6wma(STREAMFILE * streamFile); +VGMSTREAM * init_vgmstream_rsd(STREAMFILE * streamFile); VGMSTREAM * init_vgmstream_dc_asd(STREAMFILE * streamFile); diff --git a/src/meta/rsd.c b/src/meta/rsd.c index e40b3b74..188de02f 100644 --- a/src/meta/rsd.c +++ b/src/meta/rsd.c @@ -1,1197 +1,229 @@ #include "meta.h" -#include "../util.h" #include "../coding/coding.h" -/* RSD */ -/* RSD2VAG */ -VGMSTREAM * init_vgmstream_rsd2vag(STREAMFILE *streamFile) { + +/* RSD - from Radical Entertainment games */ +VGMSTREAM * init_vgmstream_rsd(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534432) /* RSD2 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x56414720) /* VAG\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitLE(0x14,streamFile); - vgmstream->meta_type = meta_RSD2VAG; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD2PCMB - Big Endian */ -VGMSTREAM * init_vgmstream_rsd2pcmb(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534432) /* RSD2 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x50434D42) /* PCMB */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = read_32bitLE(0x18,streamFile); - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PCM16BE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - } - - - if (channel_count == 1) { - vgmstream->layout_type = layout_none; - } else if (channel_count == 2) { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - } - - - vgmstream->meta_type = meta_RSD2PCMB; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD2XADP */ -VGMSTREAM * init_vgmstream_rsd2xadp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; + off_t start_offset, name_offset; size_t data_size; - - /* check extension */ - if (!check_extensions(streamFile,"rsd")) - goto fail; - - if (read_32bitBE(0x00,streamFile) != 0x52534432) /* RSD2 */ - goto fail; - if (read_32bitBE(0x04,streamFile) != 0x58414450) /* XADP */ - goto fail; - - start_offset = read_32bitLE(0x18,streamFile); /* not sure about this */ - data_size = get_streamfile_size(streamFile); - loop_flag = 0; - channel_count = read_32bitLE(0x08,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, vgmstream->channels); - - vgmstream->coding_type = coding_XBOX_IMA; - vgmstream->layout_type = layout_none; - vgmstream->meta_type = meta_RSD2XADP; - - if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD3VAG */ -VGMSTREAM * init_vgmstream_rsd3vag(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534433) /* RSD3 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x56414720) /* VAG\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitLE(0x14,streamFile); - vgmstream->meta_type = meta_RSD3VAG; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD3GADP */ -VGMSTREAM * init_vgmstream_rsd3gadp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534433) /* RSD3 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x47414450) /* WADP */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = read_32bitLE(0x18,streamFile); - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_NGC_DSP; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - } - - vgmstream->layout_type = layout_none; - vgmstream->meta_type = meta_RSD3GADP; - - if (vgmstream->coding_type == coding_NGC_DSP) { - int i; - for (i=0;i<16;i++) { - vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(0x1D+i*2,streamFile); - } - } - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD3PCM - Little Endian */ -VGMSTREAM * init_vgmstream_rsd3pcm(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534433) /* RSD3 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x50434D20) /* PCM\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = read_32bitLE(0x18,streamFile); - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - } - - - if (channel_count == 1) { - vgmstream->layout_type = layout_none; - } else if (channel_count == 2) { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - } - - vgmstream->meta_type = meta_RSD3PCM; - - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - - -/* RSD3PCMB - Big Endian */ -VGMSTREAM * init_vgmstream_rsd3pcmb(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534433) /* RSD3 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x50434D42) /* PCMB */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = read_32bitLE(0x18,streamFile); - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PCM16BE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)/2/channel_count; - } - - - if (channel_count == 1) { - vgmstream->layout_type = layout_none; - } else if (channel_count == 2) { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - } - - - vgmstream->meta_type = meta_RSD3PCMB; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - - -/* RSD4VAG */ -VGMSTREAM * init_vgmstream_rsd4vag(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534434) /* RSD4 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x56414720) /* VAG\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitLE(0xC,streamFile); - vgmstream->meta_type = meta_RSD4VAG; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD4PCM - Little Endian */ -VGMSTREAM * init_vgmstream_rsd4pcm(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534434) /* RSD4 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x50434D20) /* PCM\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)/2/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - vgmstream->meta_type = meta_RSD4PCM; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - - -/* RSD4PCMB - Big Endian */ -VGMSTREAM * init_vgmstream_rsd4pcmb(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534434) /* RSD4 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x50434D42) /* PCMB */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x80; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PCM16BE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)/2/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)/2/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - vgmstream->meta_type = meta_RSD4PCMB; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD4RADP */ -VGMSTREAM * init_vgmstream_rsd4radp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534434) /* RSD4 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x52414450) /* RADP */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_RAD_IMA; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/0x14/channel_count*32; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)*28/16/channel_count; - } - vgmstream->layout_type = layout_none; - vgmstream->interleave_block_size = 0x14*channel_count; - vgmstream->meta_type = meta_RSD4RADP; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].offset=vgmstream->ch[i].channel_start_offset=start_offset; - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD6RADP */ -VGMSTREAM * init_vgmstream_rsd6radp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x52414450) /* RADP */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_RAD_IMA; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/0x14/channel_count*32; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)*28/16/channel_count; - } - vgmstream->layout_type = layout_none; - vgmstream->interleave_block_size = 0x14*channel_count; - vgmstream->meta_type = meta_RSD6RADP; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].offset=vgmstream->ch[i].channel_start_offset=start_offset; - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD6VAG */ -VGMSTREAM * init_vgmstream_rsd6vag(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - - int loop_flag; - int channel_count; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsd",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x56414720) /* VAG\0x20 */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x800; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = loop_flag; - vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitLE(0xC,streamFile); - vgmstream->meta_type = meta_RSD6VAG; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD6WADP */ -VGMSTREAM * init_vgmstream_rsd6wadp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; - - /* check extension, case insensitive */ - if (!check_extensions(streamFile,"rsd")) - goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x57414450) /* WADP */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - start_offset = 0x800; - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)*28/16/channel_count; - - vgmstream->coding_type = coding_NGC_DSP_subint; - vgmstream->layout_type = layout_none; - vgmstream->interleave_block_size = 0x02; //read_32bitLE(0xC,streamFile); - vgmstream->meta_type = meta_RSD6WADP; - - dsp_read_coefs_be(vgmstream,streamFile,0x1a4,0x28); - - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) - goto fail; - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD6OGG */ -VGMSTREAM * init_vgmstream_rsd6oogv(STREAMFILE *streamFile) { -#ifdef VGM_USE_VORBIS - off_t start_offset; - - /* check extension */ - if (!check_extensions(streamFile, "rsd")) - goto fail; - - /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x4F4F4756) /* OOGV */ - goto fail; - - { - ogg_vorbis_meta_info_t ovmi = {0}; - VGMSTREAM * result = NULL; - - ovmi.meta_type = meta_RSD6OOGV; - - start_offset = 0x800; - result = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi); - - if (result != NULL) { - return result; - } - } - -fail: - /* clean up anything we may have opened */ -#endif - return NULL; -} - -/* RSD6XADP - from Crash Tag Team Racing (Xbox), Scarface (Xbox) */ -VGMSTREAM * init_vgmstream_rsd6xadp(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; - size_t data_size; - - /* check extension */ - if (!check_extensions(streamFile,"rsd")) - goto fail; - - if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x4,streamFile) != 0x58414450) /* XADP */ - goto fail; - - start_offset = 0x800; - data_size = get_streamfile_size(streamFile) - start_offset; - loop_flag = 0; - channel_count = read_32bitLE(0x8,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = read_32bitLE(0x10,streamFile); - vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, vgmstream->channels); - - vgmstream->meta_type = meta_RSD6XADP; - vgmstream->coding_type = (channel_count > 2) ? coding_XBOX_IMA_mch : coding_XBOX_IMA; - vgmstream->layout_type = layout_none; - - - if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD6XMA */ -VGMSTREAM * init_vgmstream_rsd6xma(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; - uint32_t version; - - /* check extension, case insensitive */ - if (!check_extensions(streamFile,"rsd")) - goto fail; - - /* check header */ - if (read_32bitBE(0x0, streamFile) != 0x52534436) /* RSD6 */ - goto fail; - if (read_32bitBE(0x04,streamFile) != 0x584D4120) /* XMA */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x8, streamFile); - version = read_32bitBE(0x80C, streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = read_32bitBE(0x800, streamFile) + read_32bitBE(0x804, streamFile) + 0xc; /* assumed, seek table always at 0x800 */ - vgmstream->channels = channel_count; - vgmstream->meta_type = meta_RSD6XMA; - vgmstream->sample_rate = read_32bitBE(0x818, streamFile); - - switch (version) { - case 0x03010000: { - vgmstream->num_samples = read_32bitBE(0x824, streamFile); - - -#ifdef VGM_USE_FFMPEG - { - ffmpeg_codec_data *ffmpeg_data = NULL; - uint8_t buf[100]; - size_t bytes, datasize, block_size, block_count; - - block_count = read_32bitBE(0x828, streamFile); - block_size = 0x10000; - datasize = read_32bitBE(0x808, streamFile); - - bytes = ffmpeg_make_riff_xma2(buf, 100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size); - ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf, bytes, start_offset, datasize); - if (!ffmpeg_data) goto fail; - vgmstream->codec_data = ffmpeg_data; - vgmstream->coding_type = coding_FFmpeg; - vgmstream->layout_type = layout_none; - - /* for some reason (dev trickery?) .rsd don't set skip in the bitstream, though they should */ - //xma_fix_raw_samples(vgmstream, streamFile, start_offset,datasize, 0, 0,0); - ffmpeg_set_skip_samples(ffmpeg_data, 512+64); - } -#else - goto fail; -#endif - break; - } - case 0x04010000: { - vgmstream->num_samples = read_32bitBE(0x814, streamFile); - - -#ifdef VGM_USE_FFMPEG - { - ffmpeg_codec_data *ffmpeg_data = NULL; - uint8_t buf[100]; - size_t bytes, datasize, block_size, block_count; - - block_count = read_32bitBE(0x830, streamFile); - block_size = 0x10000; - datasize = read_32bitBE(0x808, streamFile); - - bytes = ffmpeg_make_riff_xma2(buf, 100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size); - ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf, bytes, start_offset, datasize); - if (!ffmpeg_data) goto fail; - vgmstream->codec_data = ffmpeg_data; - vgmstream->coding_type = coding_FFmpeg; - vgmstream->layout_type = layout_none; - - /* for some reason (dev trickery?) .rsd don't set skip in the bitstream, though they should */ - //xma_fix_raw_samples(vgmstream, streamFile, start_offset,datasize, 0, 0,0); - ffmpeg_set_skip_samples(ffmpeg_data, 512+64); - } -#else - goto fail; -#endif - break; - } - default: - goto fail; - } - /* open the file for reading */ - if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) - goto fail; - return vgmstream; - -fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} - -/* RSD6AT3+ [Crash of the Titans (PSP)] */ -VGMSTREAM * init_vgmstream_rsd6at3p(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - size_t data_size; - int loop_flag, channel_count; - - - /* check extension, case insensitive */ - if (!check_extensions(streamFile,"rsd")) - goto fail; - - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x52534436) /* "RSD6" */ - goto fail; - if (read_32bitBE(0x04,streamFile) != 0x4154332B) /* "AT3+" */ - goto fail; - - loop_flag = 0; - channel_count = read_32bitLE(0x08, streamFile); - start_offset = 0x800; - data_size = get_streamfile_size(streamFile) - start_offset; - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->meta_type = meta_RSD6AT3P; - vgmstream->sample_rate = read_32bitLE(0x10, streamFile); - -#ifdef VGM_USE_FFMPEG - { - ffmpeg_codec_data *ffmpeg_data = NULL; - - /* full RIFF header at start_offset */ - ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,data_size); - if (!ffmpeg_data) goto fail; - vgmstream->codec_data = ffmpeg_data; - vgmstream->coding_type = coding_FFmpeg; - vgmstream->layout_type = layout_none; - - if (channel_count != ffmpeg_data->channels) goto fail; - - vgmstream->num_samples = ffmpeg_data->totalSamples; /* fact samples */ - - if (ffmpeg_data->skipSamples <= 0) /* in case FFmpeg didn't get them */ - ffmpeg_set_skip_samples(ffmpeg_data, riff_get_fact_skip_samples(streamFile, start_offset)); - } -#else - goto fail; -#endif - - if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} - - -/* RSD6WMA [Scarface (Xbox)] */ -VGMSTREAM * init_vgmstream_rsd6wma(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - size_t data_size; - int loop_flag, channel_count; + int loop_flag, channel_count, sample_rate, interleave; + uint32_t codec; + uint8_t version; /* checks */ if (!check_extensions(streamFile,"rsd")) goto fail; - if (read_32bitBE(0x00,streamFile) != 0x52534436) /* "RSD6" */ - goto fail; - if (read_32bitBE(0x04,streamFile) != 0x574D4120) /* "WMA " */ + if ((read_32bitBE(0x00,streamFile) & 0xFFFFFF00) != 0x52534400) /* "RSD\00" */ goto fail; loop_flag = 0; + + codec = read_32bitBE(0x04,streamFile); channel_count = read_32bitLE(0x08, streamFile); - start_offset = 0x800; + /* 0x0c: always 16? */ + sample_rate = read_32bitLE(0x10, streamFile); + + version = read_8bit(0x03, streamFile); + switch(version) { + case '2': /* known codecs: VAG/XADP/PCMB [The Simpsons: Road Rage] */ + case '3': /* known codecs: VAG/PCM/PCMB/GADP? [Dark Summit] */ + interleave = read_32bitLE(0x14,streamFile); /* VAG only, 0x04 otherwise */ + start_offset = read_32bitLE(0x18,streamFile); + name_offset = 0; + break; + + case '4': /* known codecs: VAG/PCM/RADP/PCMB [The Simpsons: Hit & Run, Tetris Worlds, Hulk] */ + /* 0x14: padding */ + /* 0x18: padding */ + interleave = 0; + start_offset = 0x800; + name_offset = 0; + + /* PCMB/PCM/GADP normally start early but sometimes have padding [The Simpsons: Hit & Run (GC/Xbox)] */ + if ((codec == 0x50434D20 || codec == 0x550434D42 || codec == 0x47414450) + && read_32bitLE(0x80,streamFile) != 0x2D2D2D2D) + start_offset = 0x80; + break; + + case '6': /* known codecs: VAG/XADP/WADP/RADP/OOGV/AT3+/XMA [Hulk 2, Crash Tag Team Racing, Crash: Mind over Mutant, Scarface] */ + /* 0x14: padding */ + name_offset = 0x18; /* dev file path */ + interleave = 0; + start_offset = 0x800; + break; + + default: + goto fail; + } + data_size = get_streamfile_size(streamFile) - start_offset; + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; - vgmstream->meta_type = meta_RSD6WMA; - //vgmstream->num_samples = read_32bitLE(start_offset + 0x00, streamFile) / channel_count / 2; /* may be PCM data size, but not exact */ - vgmstream->sample_rate = read_32bitLE(start_offset + 0x04, streamFile); + vgmstream->meta_type = meta_RSD; + vgmstream->sample_rate = sample_rate; + + switch(codec) { + case 0x50434D20: /* "PCM " [Dark Summit (Xbox), Hulk (PC)] */ + vgmstream->coding_type = coding_PCM16LE; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x2; + + vgmstream->num_samples = pcm_bytes_to_samples(data_size, channel_count, 16); + break; + + case 0x50434D42: /* "PCMB" [The Simpsons: Road Rage (GC), Dark Summit (GC)] */ + vgmstream->coding_type = coding_PCM16BE; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x2; + + vgmstream->num_samples = pcm_bytes_to_samples(data_size, channel_count, 16); + break; + + case 0x56414720: /* "VAG " [The Simpsons: Road Rage (PS2), Crash Tag Team Racing (PSP)] */ + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = (interleave == 0) ? 0x10 : interleave; + + vgmstream->num_samples = ps_bytes_to_samples(data_size, channel_count); + break; + + case 0x58414450: /* "XADP" [The Simpsons: Road Rage (Xbox)], Crash Tag Team Racing (Xbox)] */ + vgmstream->coding_type = (channel_count > 2) ? coding_XBOX_IMA_mch : coding_XBOX_IMA; + vgmstream->layout_type = layout_none; + + vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, vgmstream->channels); + break; + + case 0x47414450: /* "GADP" [Hulk (GC)] */ + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x08; /* assumed, known files are mono */ + dsp_read_coefs_le(vgmstream,streamFile,0x14,0x2e); /* LE! */ + dsp_read_hist_le (vgmstream,streamFile,0x38,0x2e); + + vgmstream->num_samples = dsp_bytes_to_samples(data_size, channel_count); + break; + + case 0x57414450: /* "WADP" [Crash: Mind Over Mutant (Wii)] */ + vgmstream->coding_type = coding_NGC_DSP_subint; + vgmstream->layout_type = layout_none; + vgmstream->interleave_block_size = 0x02; + dsp_read_coefs_be(vgmstream,streamFile,0x1a4,0x28); + dsp_read_hist_be (vgmstream,streamFile,0x1c8,0x28); + + vgmstream->num_samples = dsp_bytes_to_samples(data_size, channel_count); + break; + + case 0x52414450: /* "RADP" [The Simpsons: Hit & Run (GC), Scarface (Wii)] */ + vgmstream->coding_type = coding_RAD_IMA; + vgmstream->layout_type = layout_none; + vgmstream->interleave_block_size = 0x14*channel_count; + + vgmstream->num_samples = data_size / 0x14 / channel_count * 32; /* bytes-to-samples */ + break; + +#ifdef VGM_USE_VORBIS + case 0x4F4F4756: { /* "OOGV" [Scarface (PC)] */ + ogg_vorbis_meta_info_t ovmi = {0}; + + ovmi.meta_type = meta_RSD; + close_vgmstream(vgmstream); + vgmstream = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi); + if (!vgmstream) goto fail; + break; + } +#endif #ifdef VGM_USE_FFMPEG - { - ffmpeg_codec_data *ffmpeg_data = NULL; + case 0x574D4120: { /* "WMA " [Scarface (Xbox)] */ + ffmpeg_codec_data *ffmpeg_data = NULL; - /* mini header + WMA header at start_offset */ - ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset+0x08,data_size); - if (!ffmpeg_data) goto fail; - vgmstream->codec_data = ffmpeg_data; - vgmstream->coding_type = coding_FFmpeg; - vgmstream->layout_type = layout_none; + /* mini header + WMA header at start_offset */ + ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset+0x08,data_size); + if (!ffmpeg_data) goto fail; + vgmstream->codec_data = ffmpeg_data; + vgmstream->coding_type = coding_FFmpeg; + vgmstream->layout_type = layout_none; - vgmstream->num_samples = (int32_t)ffmpeg_data->totalSamples; /* an estimation, sometimes cuts files a bit early */ - } -#else - goto fail; + vgmstream->num_samples = (int32_t)ffmpeg_data->totalSamples; /* an estimation, sometimes cuts files a bit early */ + //vgmstream->num_samples = read_32bitLE(start_offset + 0x00, streamFile) / channel_count / 2; /* may be PCM data size, but not exact */ + vgmstream->sample_rate = read_32bitLE(start_offset + 0x04, streamFile); + break; + } + + case 0x4154332B: { /* "AT3+" [Crash of the Titans (PSP)] */ + ffmpeg_codec_data *ffmpeg_data = NULL; + + /* full RIFF header at start_offset */ + ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,data_size); + if (!ffmpeg_data) goto fail; + vgmstream->codec_data = ffmpeg_data; + vgmstream->coding_type = coding_FFmpeg; + vgmstream->layout_type = layout_none; + + if (ffmpeg_data->skipSamples <= 0) /* in case FFmpeg didn't get them */ + ffmpeg_set_skip_samples(ffmpeg_data, riff_get_fact_skip_samples(streamFile, start_offset)); + + vgmstream->num_samples = ffmpeg_data->totalSamples; /* fact samples */ + break; + } + + case 0x584D4120: { /* "XMA " [Crash of the Titans (X360)-v1, Crash: Mind over Mutant (X360)-v2] */ + ffmpeg_codec_data *ffmpeg_data = NULL; + uint8_t buf[0x100]; + size_t bytes, xma_size, block_size, block_count; + int xma_version; + + + /* skip mini header */ + start_offset = read_32bitBE(0x800, streamFile) + read_32bitBE(0x804, streamFile) + 0xc; /* assumed, seek table always at 0x800 */ + xma_size = read_32bitBE(0x808, streamFile); + xma_version = read_32bitBE(0x80C, streamFile); + + switch (xma_version) { + case 0x03010000: + vgmstream->sample_rate = read_32bitBE(0x818, streamFile); + vgmstream->num_samples = read_32bitBE(0x824, streamFile); + block_count = read_32bitBE(0x828, streamFile); + block_size = 0x10000; + break; + case 0x04010000: + vgmstream->num_samples = read_32bitBE(0x814, streamFile); + vgmstream->sample_rate = read_32bitBE(0x818, streamFile); + block_count = read_32bitBE(0x830, streamFile); + block_size = 0x10000; + break; + default: + goto fail; + } + + bytes = ffmpeg_make_riff_xma2(buf,sizeof(buf), vgmstream->num_samples, xma_size, vgmstream->channels, vgmstream->sample_rate, block_count, block_size); + ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf, bytes, start_offset, xma_size); + if (!ffmpeg_data) goto fail; + vgmstream->codec_data = ffmpeg_data; + vgmstream->coding_type = coding_FFmpeg; + vgmstream->layout_type = layout_none; + + /* for some reason (dev trickery?) .rsd don't set skip in the bitstream, though they should */ + //xma_fix_raw_samples(vgmstream, streamFile, start_offset,xma_size, 0, 0,0); + ffmpeg_set_skip_samples(ffmpeg_data, 512+64); + break; + } #endif + default: + goto fail; + } + + if (name_offset) + read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,streamFile); + if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) goto fail; return vgmstream; diff --git a/src/vgmstream.c b/src/vgmstream.c index 87454406..5781ca97 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -157,21 +157,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_wii_mus, init_vgmstream_dc_asd, init_vgmstream_naomi_spsd, - init_vgmstream_rsd2vag, - init_vgmstream_rsd2pcmb, - init_vgmstream_rsd2xadp, - init_vgmstream_rsd3vag, - init_vgmstream_rsd3gadp, - init_vgmstream_rsd3pcm, - init_vgmstream_rsd3pcmb, - init_vgmstream_rsd4pcmb, - init_vgmstream_rsd4pcm, - init_vgmstream_rsd4radp, - init_vgmstream_rsd4vag, - init_vgmstream_rsd6vag, - init_vgmstream_rsd6wadp, - init_vgmstream_rsd6xadp, - init_vgmstream_rsd6radp, + init_vgmstream_rsd, init_vgmstream_bgw, init_vgmstream_spw, init_vgmstream_ps2_ass, @@ -305,7 +291,6 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_ps3_ivag, init_vgmstream_ps2_2pfs, init_vgmstream_xnb, - init_vgmstream_rsd6oogv, init_vgmstream_ubi_ckd, init_vgmstream_ps2_vbk, init_vgmstream_otm, @@ -335,7 +320,6 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_ogl, init_vgmstream_mc3, init_vgmstream_gtd, - init_vgmstream_rsd6xma, init_vgmstream_ta_aac_x360, init_vgmstream_ta_aac_ps3, init_vgmstream_ta_aac_mobile, @@ -394,8 +378,6 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_waf, init_vgmstream_wave, init_vgmstream_wave_segmented, - init_vgmstream_rsd6at3p, - init_vgmstream_rsd6wma, init_vgmstream_smv, init_vgmstream_nxap, init_vgmstream_ea_wve_au00, diff --git a/src/vgmstream.h b/src/vgmstream.h index e2ced4bc..89c02e7e 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -420,27 +420,7 @@ typedef enum { meta_NGC_PDT, /* Mario Party 6 */ meta_DC_ASD, /* Miss Moonligh */ meta_NAOMI_SPSD, /* Guilty Gear X */ - - meta_RSD2VAG, /* RSD2VAG */ - meta_RSD2PCMB, /* RSD2PCMB */ - meta_RSD2XADP, /* RSD2XADP */ - meta_RSD3VAG, /* RSD3VAG */ - meta_RSD3GADP, /* RSD3GADP */ - meta_RSD3PCM, /* RSD3PCM */ - meta_RSD3PCMB, /* RSD3PCMB */ - meta_RSD4PCMB, /* RSD4PCMB */ - meta_RSD4PCM, /* RSD4PCM */ - meta_RSD4RADP, /* RSD4RADP */ - meta_RSD4VAG, /* RSD4VAG */ - meta_RSD6VAG, /* RSD6VAG */ - meta_RSD6WADP, /* RSD6WADP */ - meta_RSD6XADP, /* RSD6XADP */ - meta_RSD6RADP, /* RSD6RADP */ - meta_RSD6OOGV, /* RSD6OOGV */ - meta_RSD6XMA, /* RSD6XMA */ - meta_RSD6AT3P, /* RSD6AT3+ */ - meta_RSD6WMA, /* RSD6WMA */ - + meta_RSD, meta_PS2_ASS, /* ASS */ meta_SEG, /* Eragon */ meta_NDS_STRM_FFTA2, /* Final Fantasy Tactics A2 */