From 87bc10bd82a725f42f202a33041b9da53e7f2837 Mon Sep 17 00:00:00 2001 From: bxaimc Date: Tue, 19 Oct 2010 02:16:08 +0000 Subject: [PATCH] Added initial support for SGH+SGB file pairs from Folklore (PS3) No support for individual SGB and Non-PS ADPCM files. git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@867 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- fb2k/in_vgmstream.cpp | 2 ++ src/Makefile | 3 +- src/libvgmstream.vcproj | 6 +++- src/meta/Makefile.unix.am | 1 + src/meta/meta.h | 2 ++ src/meta/ps3_sgh_sgb.c | 76 +++++++++++++++++++++++++++++++++++++++ src/vgmstream.c | 5 ++- src/vgmstream.h | 1 + unix/data.c | 1 + winamp/in_vgmstream.c | 1 + 10 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/meta/ps3_sgh_sgb.c diff --git a/fb2k/in_vgmstream.cpp b/fb2k/in_vgmstream.cpp index 985922d7..ef93eaeb 100644 --- a/fb2k/in_vgmstream.cpp +++ b/fb2k/in_vgmstream.cpp @@ -418,6 +418,7 @@ bool input_vgmstream::g_is_our_path(const char * p_path,const char * p_extension if(!stricmp_utf8(p_extension,"seg")) return 1; if(!stricmp_utf8(p_extension,"sfl")) return 1; if(!stricmp_utf8(p_extension,"sfs")) return 1; + if(!stricmp_utf8(p_extension,"sgb")) return 1; if(!stricmp_utf8(p_extension,"sl3")) return 1; if(!stricmp_utf8(p_extension,"sli")) return 1; if(!stricmp_utf8(p_extension,"smp")) return 1; @@ -703,6 +704,7 @@ DECLARE_MULTIPLE_FILE_TYPE("SDT Audio File (*.SDT)", sdt); DECLARE_MULTIPLE_FILE_TYPE("SEG Audio File (*.SEG)", seg); DECLARE_MULTIPLE_FILE_TYPE("SFL Audio File (*.SFL)", sfl); DECLARE_MULTIPLE_FILE_TYPE("SFS Audio File (*.SFS)", sfs); +DECLARE_MULTIPLE_FILE_TYPE("SGB Audio File (*.SGB)", sgb); DECLARE_MULTIPLE_FILE_TYPE("SL3 Audio File (*.SL3)", sl3); DECLARE_MULTIPLE_FILE_TYPE("SLI Audio File (*.SLI)", sli); DECLARE_MULTIPLE_FILE_TYPE("SMP Audio File (*.SMP)", smp); diff --git a/src/Makefile b/src/Makefile index fa7ba68a..5089a565 100644 --- a/src/Makefile +++ b/src/Makefile @@ -258,7 +258,8 @@ META_OBJS=meta/adx_header.o \ meta/baf.o \ meta/ps3_msf.o \ meta/nub.o \ - meta/ps3_past.o + meta/ps3_past.o \ + meta/ps3_sgb_sgh.o OBJECTS=vgmstream.o streamfile.o util.o $(CODING_OBJS) $(LAYOUT_OBJS) $(META_OBJS) diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 4a7a33d3..fbe09b93 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -1,7 +1,7 @@  + + diff --git a/src/meta/Makefile.unix.am b/src/meta/Makefile.unix.am index fe9860fc..baa9f9ad 100644 --- a/src/meta/Makefile.unix.am +++ b/src/meta/Makefile.unix.am @@ -211,5 +211,6 @@ libmeta_la_SOURCES += baf.c libmeta_la_SOURCES += ps3_msf.c libmeta_la_SOURCES += nub.c libmeta_la_SOURCES += ps3_past.c +libmeta_la_SOURCES += ps3_sgh_sgb.c EXTRA_DIST = meta.h diff --git a/src/meta/meta.h b/src/meta/meta.h index ff547c87..840e6e25 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -537,5 +537,7 @@ VGMSTREAM * init_vgmstream_nub_vag(STREAMFILE* streamFile); VGMSTREAM * init_vgmstream_ps3_past(STREAMFILE* streamFile); +VGMSTREAM * init_vgmstream_ps3_sgh_sgb(STREAMFILE* streamFile); + #endif diff --git a/src/meta/ps3_sgh_sgb.c b/src/meta/ps3_sgh_sgb.c new file mode 100644 index 00000000..aedff5bf --- /dev/null +++ b/src/meta/ps3_sgh_sgb.c @@ -0,0 +1,76 @@ +#include "meta.h" +#include "../util.h" + +/* SGH+SGB (from Folklore) */ +VGMSTREAM * init_vgmstream_ps3_sgh_sgb(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + off_t start_offset; + STREAMFILE * streamFileSGH = NULL; + char filename[260]; + char filenameSGH[260]; + int i; + int channel_count; + int loop_flag; + + /* check extension, case insensitive */ + streamFile->get_name(streamFile,filename,sizeof(filename)); + if (strcasecmp("sgb",filename_extension(filename))) goto fail; + + strcpy(filenameSGH,filename); + strcpy(filenameSGH+strlen(filenameSGH)-3,"sgh"); + + streamFileSGH = streamFile->open(streamFile,filenameSGH,STREAMFILE_DEFAULT_BUFFER_SIZE); + if (!streamFileSGH) goto fail; + + /* check header */ + if (read_32bitBE(0x00,streamFileSGH) != 0x53475844) /* "SGXD" */ + goto fail; + + channel_count = read_32bitLE(0x6C,streamFileSGH); + if (read_32bitBE(0x44,streamFileSGH)==0xFFFFFFFF) + loop_flag = 0; + else + loop_flag = 1; + + /* 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(0x2C,streamFileSGH); + vgmstream->num_samples = read_32bitLE(0xC,streamFileSGH)*28/32; + vgmstream->coding_type = coding_PSX; + if(loop_flag) { + vgmstream->loop_start_sample = read_32bitLE(0x44,streamFileSGH); + vgmstream->loop_end_sample = read_32bitLE(0x48,streamFileSGH); + } + + + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x10; + vgmstream->meta_type = meta_PS3_SGH_SGB; + + /* 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/vgmstream.c b/src/vgmstream.c index b5d08c8b..231f2f85 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -290,7 +290,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = { init_vgmstream_fsb_mpeg, init_vgmstream_nub_vag, init_vgmstream_ps3_past, - + init_vgmstream_ps3_sgh_sgb, }; #define INIT_VGMSTREAM_FCNS (sizeof(init_vgmstream_fcns)/sizeof(init_vgmstream_fcns[0])) @@ -2707,6 +2707,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { break; case meta_PS3_PAST: snprintf(temp,TEMPSIZE,"SNDP header"); + break; + case meta_PS3_SGH_SGB: + snprintf(temp,TEMPSIZE,"SGH+SGB SGXD header"); break; default: snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET"); diff --git a/src/vgmstream.h b/src/vgmstream.h index d8321b9d..89072314 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -494,6 +494,7 @@ typedef enum { meta_PS3_MSF, /* MSF header */ meta_NUB_VAG, /* VAG from Nub archives */ meta_PS3_PAST, /* Bakugan Battle Brawlers (PS3) */ + meta_PS3_SGH_SGB, /* Folklore (PS3) */ } meta_t; typedef struct { diff --git a/unix/data.c b/unix/data.c index 92c51da0..babf97c2 100644 --- a/unix/data.c +++ b/unix/data.c @@ -179,6 +179,7 @@ gchar *vgmstream_exts [] = { "seg", "sfl", "sfs", + "sgb", "sl3", "sli", "smp", diff --git a/winamp/in_vgmstream.c b/winamp/in_vgmstream.c index 8418af2a..976c8926 100644 --- a/winamp/in_vgmstream.c +++ b/winamp/in_vgmstream.c @@ -246,6 +246,7 @@ char * extension_list[] = { "seg\0SEG Audio File (*.SEG)\0", "sfl\0SFL Audio File (*.SFL)\0", "sfs\0SFS Audio File (*.SFS)\0", + "sgb\0SGB Audio File (*.SGB)\0", "sl3\0SL3 Audio File (*.SL3)\0", "sli\0SLI Audio File (*.SLI)\0", "smp\0SMP Audio File (*.SMP)\0",