From 34d4d9d16f14cf5a240cffc95cbd8a781d68477b Mon Sep 17 00:00:00 2001 From: fastelbja Date: Mon, 19 May 2008 11:39:30 +0000 Subject: [PATCH] add GMS Support (PS1 & PS2) git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@174 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- src/libvgmstream.vcproj | 4 ++ src/meta/meta.h | 2 + src/meta/psx_gms.c | 82 +++++++++++++++++++++++++++++++++++++++++ src/vgmstream.c | 6 ++- src/vgmstream.h | 1 + winamp/in_vgmstream.c | 3 +- 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/meta/psx_gms.c diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index a22a5e3c..20ba9514 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -282,6 +282,10 @@ RelativePath=".\meta\psx_cdxa.c" > + + diff --git a/src/meta/meta.h b/src/meta/meta.h index f0245686..fd01a969 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -59,4 +59,6 @@ VGMSTREAM * init_vgmstream_raw(const char * const filename); VGMSTREAM * init_vgmstream_ps2_vag(const char * const filename); +VGMSTREAM * init_vgmstream_psx_gms(const char * const filename); + #endif diff --git a/src/meta/psx_gms.c b/src/meta/psx_gms.c new file mode 100644 index 00000000..bd6d53ca --- /dev/null +++ b/src/meta/psx_gms.c @@ -0,0 +1,82 @@ +#include "meta.h" +#include "../util.h" + +/* GMS + + PSX GMS format has no recognition ID. + This format was used essentially in Grandia Games but + can be easily used by other header format as the format of the header is very simple + + known extensions : GMS + + 2008-05-19 - Fastelbja : First version ... +*/ + +VGMSTREAM * init_vgmstream_psx_gms(const char * const filename) { + VGMSTREAM * vgmstream = NULL; + STREAMFILE * infile = NULL; + + int loop_flag=0; + int channel_count; + off_t start_offset; + int i; + + /* check extension, case insensitive */ + if (strcasecmp("gms",filename_extension(filename))) goto fail; + + /* try to open the file for header reading */ + infile = open_streamfile(filename); + if (!infile) goto fail; + + /* check loop */ + loop_flag = (read_32bitLE(0x20,infile)==0); + + /* Always stereo files */ + channel_count=read_32bitLE(0x00,infile); + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + vgmstream->channels = channel_count; + vgmstream->sample_rate = read_32bitLE(0x04,infile); + + vgmstream->coding_type = coding_PSX; + vgmstream->num_samples = read_32bitLE(0x1C,infile); + + /* Get loop point values */ + if(vgmstream->loop_flag) { + vgmstream->loop_start_sample = read_32bitLE(0x14,infile); + vgmstream->loop_end_sample = read_32bitLE(0x1C,infile); + } + + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x800; + vgmstream->meta_type = meta_PSX_GMS; + + start_offset = 0x800; + + close_streamfile(infile); infile=NULL; + + /* open the file for reading by each channel */ + { + for (i=0;ich[i].streamfile = open_streamfile_buffer(filename,vgmstream->interleave_block_size); + + if (!vgmstream->ch[i].streamfile) goto fail; + + vgmstream->ch[i].channel_start_offset= + vgmstream->ch[i].offset= + (off_t)(start_offset+vgmstream->interleave_block_size*i); + } + } + + return vgmstream; + + /* clean up anything we may have opened */ +fail: + if (infile) close_streamfile(infile); + if (vgmstream) close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/vgmstream.c b/src/vgmstream.c index 07479910..8805fca5 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -15,7 +15,7 @@ * List of functions that will recognize files. These should correspond pretty * directly to the metadata types */ -#define INIT_VGMSTREAM_FCNS 28 +#define INIT_VGMSTREAM_FCNS 29 VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { init_vgmstream_adx, /* 0 */ init_vgmstream_brstm, /* 1 */ @@ -45,6 +45,7 @@ VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { init_vgmstream_ngc_dsp_std_int, /* 25 */ init_vgmstream_raw, /* 26 */ init_vgmstream_ps2_vag, /* 27 */ + init_vgmstream_psx_gms /* 28 */ }; @@ -678,6 +679,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { break; case meta_PS2_pGAV: snprintf(temp,TEMPSIZE,"Sony VAG Stereo Little Endian header (pGAV)"); + break; + case meta_PSX_GMS: + snprintf(temp,TEMPSIZE,"assumed Grandia GMS file by .gms extension"); break; default: snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET"); diff --git a/src/vgmstream.h b/src/vgmstream.h index 118aae2d..3d8e121a 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -91,6 +91,7 @@ typedef enum { meta_PS2_VAGi, /* VAGi Interleaved File */ meta_PS2_VAGp, /* VAGp Mono File */ meta_PS2_pGAV, /* VAGp with Little Endian Header */ + meta_PSX_GMS, /* GMS File (used in PS1 & PS2) */ meta_PSX_XA, /* CD-XA with RIFF header */ diff --git a/winamp/in_vgmstream.c b/winamp/in_vgmstream.c index c3441df7..776a6bff 100644 --- a/winamp/in_vgmstream.c +++ b/winamp/in_vgmstream.c @@ -74,7 +74,7 @@ int fade_samples = 0; #define EXTENSION_LIST_SIZE 1024 char working_extension_list[EXTENSION_LIST_SIZE] = {0}; -#define EXTENSION_COUNT 28 +#define EXTENSION_COUNT 29 char * extension_list[EXTENSION_COUNT] = { "adx\0ADX Audio File (*.ADX)\0", "afc\0AFC Audio File (*.AFC)\0", @@ -104,6 +104,7 @@ char * extension_list[EXTENSION_COUNT] = { "mss\0MSS Audio File (*.MSS)\0", "raw\0RAW Audio File (*.RAW)\0", "vag\0VAG Audio File (*.VAG)\0", + "gms\0GMS Audio File (*.GMS)\0", }; void about(HWND hwndParent) {