From 781eb970404c202a07d1dced5cc8ddd114476879 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 8 Jul 2017 11:02:22 +0200 Subject: [PATCH] Move nds_strm_ffta2 to its own file for clarity --- src/libvgmstream.vcproj | 4 ++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/nds_strm.c | 67 +------------------------------- src/meta/nds_strm_ffta2.c | 67 ++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 66 deletions(-) create mode 100644 src/meta/nds_strm_ffta2.c diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 3ea793d0..fe76a124 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -522,6 +522,10 @@ RelativePath=".\meta\nds_strm.c" > + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 2bfcc7ef..8e806133 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -247,6 +247,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 2e2eedf4..b08160f3 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -289,6 +289,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/nds_strm.c b/src/meta/nds_strm.c index 74b9c7d2..c41cd9ed 100644 --- a/src/meta/nds_strm.c +++ b/src/meta/nds_strm.c @@ -1,6 +1,7 @@ #include "meta.h" #include "../util.h" +/* STRM - common Nintendo NDS streaming format */ VGMSTREAM * init_vgmstream_nds_strm(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; char filename[PATH_LIMIT]; @@ -103,69 +104,3 @@ fail: if (vgmstream) close_vgmstream(vgmstream); return NULL; } - - -/* STRM (from Final Fantasy Tactics A2 - Fuuketsu no Grimoire) */ -VGMSTREAM * init_vgmstream_nds_strm_ffta2(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("strm",filename_extension(filename))) goto fail; - - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x52494646 || /* RIFF */ - read_32bitBE(0x08,streamFile) != 0x494D4120) /* "IMA " */ - goto fail; - - loop_flag = (read_32bitLE(0x20,streamFile) !=0); - channel_count = read_32bitLE(0x24,streamFile); - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - start_offset = 0x2C; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x0C,streamFile); - vgmstream->coding_type = coding_IMA_int; - vgmstream->num_samples = (read_32bitLE(0x04,streamFile)-start_offset); - if (loop_flag) { - vgmstream->loop_start_sample = read_32bitLE(0x20,streamFile); - vgmstream->loop_end_sample = read_32bitLE(0x28,streamFile); - } - - vgmstream->interleave_block_size = 0x80; - vgmstream->interleave_smallblock_size = (vgmstream->loop_end_sample)%((vgmstream->loop_end_sample)/vgmstream->interleave_block_size); - vgmstream->layout_type = layout_interleave_shortblock; - vgmstream->meta_type = meta_NDS_STRM_FFTA2; - - /* 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; - - /* clean up anything we may have opened */ -fail: - if (vgmstream) close_vgmstream(vgmstream); - return NULL; -} diff --git a/src/meta/nds_strm_ffta2.c b/src/meta/nds_strm_ffta2.c new file mode 100644 index 00000000..8c6551c1 --- /dev/null +++ b/src/meta/nds_strm_ffta2.c @@ -0,0 +1,67 @@ +#include "meta.h" +#include "../util.h" + +/* STRM (from Final Fantasy Tactics A2 - Fuuketsu no Grimoire) */ +VGMSTREAM * init_vgmstream_nds_strm_ffta2(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("strm",filename_extension(filename))) goto fail; + + /* check header */ + if (read_32bitBE(0x00,streamFile) != 0x52494646 || /* RIFF */ + read_32bitBE(0x08,streamFile) != 0x494D4120) /* "IMA " */ + goto fail; + + loop_flag = (read_32bitLE(0x20,streamFile) !=0); + channel_count = read_32bitLE(0x24,streamFile); + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + start_offset = 0x2C; + vgmstream->channels = channel_count; + vgmstream->sample_rate = read_32bitLE(0x0C,streamFile); + vgmstream->coding_type = coding_IMA_int; + vgmstream->num_samples = (read_32bitLE(0x04,streamFile)-start_offset); + if (loop_flag) { + vgmstream->loop_start_sample = read_32bitLE(0x20,streamFile); + vgmstream->loop_end_sample = read_32bitLE(0x28,streamFile); + } + + vgmstream->interleave_block_size = 0x80; + vgmstream->interleave_smallblock_size = (vgmstream->loop_end_sample)%((vgmstream->loop_end_sample)/vgmstream->interleave_block_size); + vgmstream->layout_type = layout_interleave_shortblock; + vgmstream->meta_type = meta_NDS_STRM_FFTA2; + + /* 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; + + /* clean up anything we may have opened */ +fail: + if (vgmstream) close_vgmstream(vgmstream); + return NULL; +}