From b1aaf2ba85fb2e5c96cbaa22f03abbccdcfbf552 Mon Sep 17 00:00:00 2001 From: fastelbja Date: Tue, 13 May 2008 19:53:31 +0000 Subject: [PATCH] adding svag support - fixing implicit warning on vs2005 for ps2_xxx functions git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@114 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- readme.txt | 114 ++++++++++++++++++++------------------- src/Makefile | 97 ++++++++++++++++----------------- src/coding/psx_decoder.c | 24 ++++++--- src/libvgmstream.vcproj | 4 ++ src/meta/meta.h | 2 + src/meta/ps2_ads.c | 2 +- src/meta/ps2_exst.c | 24 ++++----- src/meta/ps2_int.c | 2 +- src/meta/ps2_npsf.c | 2 +- src/meta/ps2_rxw.c | 2 +- src/meta/ps2_svag.c | 88 ++++++++++++++++++++++++++++++ src/vgmstream.c | 6 ++- src/vgmstream.h | 2 + winamp/in_vgmstream.c | 3 +- 14 files changed, 242 insertions(+), 130 deletions(-) create mode 100644 src/meta/ps2_svag.c diff --git a/readme.txt b/readme.txt index 4b530d71..68e3b99a 100644 --- a/readme.txt +++ b/readme.txt @@ -1,56 +1,58 @@ -vgmstream - -This is vgmstream, a library for playing streamed audio from video games. -It is very much under development. There are two end-user bits, a command -line decoder called "test", and a simple Winamp plugin called "in_vgmstream". - ---- test --- -Usage: test.exe [-o outfile.wav] [-l loop count] - [-f fade time] [-ipcmxeE] infile -Options: - -o outfile.wav: name of output .wav file, default is dump.wav - -l loop count: loop count, default 2.0 - -f fade time: fade time (seconds), default 10.0 - -i: ignore looping information and play the whole stream once - -p: output to stdout (for piping into another program) - -P: output to stdout even if stdout is a terminal - -c: loop forever (continuously) - -m: print metadata only, don't decode - -x: decode and print adxencd command line to encode as ADX - -e: force end-to-end looping - -E: force end-to-end looping even if file has real loop points - -Typical usage would be: -test -o happy.wav happy.adx -to decode happy.adx to happy.wav. - ---- in_vgmstream --- -Drop the in_vgmstream.dll in your Winamp plugins directory. There is no -configuration or seeking yet. - ---- -File types supported by this version of vgmstream: -- .adx (CRI ADX ADPCM) -- .brstm (RSTM: GC/Wii DSP ADPCM, 8/16 bit PCM) -- .strm (STRM: NDS IMA ADPCM, 8/16 bit PCM) -- .adp (GC DTK ADPCM) -- .agsc (GC DSP ADPCM) -- .rsf (CCITT G.721 ADPCM) -- .afc (GC AFC ADPCM) -- .ast (GC/Wii AFC ADPCM, 16 bit PCM) -- .hps (GC DSP ADPCM) -- .dsp (GC DSP ADPCM) - - standard, with dual file stereo - - RS03 - - Cstr - - .stm -- .gcsw (16 bit PCM) -- .ads/.ss2 (PSX ADPCM) -- .npsf (PSX ADPCM) -- .rwsd (Wii DSP ADPCM, 8/16 bit PCM) -- .xa (CD-ROM XA audio) -- .rxw (PSX ADPCM) -- .int (16 bit PCM) - -Enjoy! --hcs +vgmstream + +This is vgmstream, a library for playing streamed audio from video games. +It is very much under development. There are two end-user bits, a command +line decoder called "test", and a simple Winamp plugin called "in_vgmstream". + +--- test --- +Usage: test.exe [-o outfile.wav] [-l loop count] + [-f fade time] [-ipcmxeE] infile +Options: + -o outfile.wav: name of output .wav file, default is dump.wav + -l loop count: loop count, default 2.0 + -f fade time: fade time (seconds), default 10.0 + -i: ignore looping information and play the whole stream once + -p: output to stdout (for piping into another program) + -P: output to stdout even if stdout is a terminal + -c: loop forever (continuously) + -m: print metadata only, don't decode + -x: decode and print adxencd command line to encode as ADX + -e: force end-to-end looping + -E: force end-to-end looping even if file has real loop points + +Typical usage would be: +test -o happy.wav happy.adx +to decode happy.adx to happy.wav. + +--- in_vgmstream --- +Drop the in_vgmstream.dll in your Winamp plugins directory. There is no +configuration or seeking yet. + +--- +File types supported by this version of vgmstream: +- .adx (CRI ADX ADPCM) +- .brstm (RSTM: GC/Wii DSP ADPCM, 8/16 bit PCM) +- .strm (STRM: NDS IMA ADPCM, 8/16 bit PCM) +- .adp (GC DTK ADPCM) +- .agsc (GC DSP ADPCM) +- .rsf (CCITT G.721 ADPCM) +- .afc (GC AFC ADPCM) +- .ast (GC/Wii AFC ADPCM, 16 bit PCM) +- .hps (GC DSP ADPCM) +- .dsp (GC DSP ADPCM) + - standard, with dual file stereo + - RS03 + - Cstr + - .stm +- .gcsw (16 bit PCM) +- .ads/.ss2 (PSX ADPCM) +- .npsf (PSX ADPCM) +- .rwsd (Wii DSP ADPCM, 8/16 bit PCM) +- .xa (CD-ROM XA audio) +- .rxw (PSX ADPCM) +- .int (16 bit PCM) +- .sts (PSX ADPCM) +- .svag (PSX ADPCM) + +Enjoy! +-hcs diff --git a/src/Makefile b/src/Makefile index 84bb2eed..4a41dd54 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,48 +1,49 @@ -CODING_OBJS=coding/adx_decoder.o \ - coding/g721_decoder.o \ - coding/ima_decoder.o \ - coding/ngc_afc_decoder.o \ - coding/ngc_dsp_decoder.o \ - coding/ngc_dtk_decoder.o \ - coding/pcm_decoder.o \ - coding/psx_decoder.o \ - coding/xa_decoder.o - -LAYOUT_OBJS=layout/ast_blocked.o \ - layout/blocked.o \ - layout/halpst_blocked.o \ - layout/interleave.o \ - layout/nolayout.o \ - layout/xa_blocked.o - -META_OBJS=meta/adx_header.o \ - meta/afc_header.o \ - meta/agsc.o \ - meta/ast.o \ - meta/brstm.o \ - meta/halpst.o \ - meta/nds_strm.o \ - meta/ngc_adpdtk.o \ - meta/rsf.o \ - meta/rs03.o \ - meta/ngc_dsp_std.o \ - meta/Cstr.o \ - meta/gcsw.o \ - meta/ps2_ads.o \ - meta/ps2_npsf.o \ - meta/rwsd.o \ - meta/psx_cdxa.o \ - meta/ps2_rxw.o \ - meta/ps2_int.o \ - meta/ps2_exst.o - -OBJECTS=vgmstream.o streamfile.o util.o $(CODING_OBJS) $(LAYOUT_OBJS) $(META_OBJS) - -libvgmstream.a: $(OBJECTS) - $(AR) crs libvgmstream.a $(OBJECTS) - -vgmstream-deps: - $(CC) $(CFLAGS) -M -o vgmstream-deps - -clean: - rm -f $(OBJECTS) libvgmstream.a +CODING_OBJS=coding/adx_decoder.o \ + coding/g721_decoder.o \ + coding/ima_decoder.o \ + coding/ngc_afc_decoder.o \ + coding/ngc_dsp_decoder.o \ + coding/ngc_dtk_decoder.o \ + coding/pcm_decoder.o \ + coding/psx_decoder.o \ + coding/xa_decoder.o + +LAYOUT_OBJS=layout/ast_blocked.o \ + layout/blocked.o \ + layout/halpst_blocked.o \ + layout/interleave.o \ + layout/nolayout.o \ + layout/xa_blocked.o + +META_OBJS=meta/adx_header.o \ + meta/afc_header.o \ + meta/agsc.o \ + meta/ast.o \ + meta/brstm.o \ + meta/halpst.o \ + meta/nds_strm.o \ + meta/ngc_adpdtk.o \ + meta/rsf.o \ + meta/rs03.o \ + meta/ngc_dsp_std.o \ + meta/Cstr.o \ + meta/gcsw.o \ + meta/ps2_ads.o \ + meta/ps2_npsf.o \ + meta/rwsd.o \ + meta/psx_cdxa.o \ + meta/ps2_rxw.o \ + meta/ps2_int.o \ + meta/ps2_exst.o \ + meta/ps2_svag.o + +OBJECTS=vgmstream.o streamfile.o util.o $(CODING_OBJS) $(LAYOUT_OBJS) $(META_OBJS) + +libvgmstream.a: $(OBJECTS) + $(AR) crs libvgmstream.a $(OBJECTS) + +vgmstream-deps: + $(CC) $(CFLAGS) -M -o vgmstream-deps + +clean: + rm -f $(OBJECTS) libvgmstream.a diff --git a/src/coding/psx_decoder.c b/src/coding/psx_decoder.c index 29dfe174..e51329b2 100644 --- a/src/coding/psx_decoder.c +++ b/src/coding/psx_decoder.c @@ -16,24 +16,32 @@ void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, short scale; int i; int32_t sample_count; + uint8_t flag; int framesin = first_sample/28; predict_nr = read_8bit(stream->offset+framesin*16,stream->streamfile) >> 4; shift_factor = read_8bit(stream->offset+framesin*16,stream->streamfile) & 0xf; - + flag = read_8bit(stream->offset+framesin*16+1,stream->streamfile); + first_sample = first_sample % 28; - + for (i=first_sample,sample_count=0; ioffset+(framesin*16)+2+i/2,stream->streamfile); - scale = ((i&1 ? - sample_byte >> 4 : - sample_byte & 0x0f)<<12); + sample=0; - sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]); - outbuf[sample_count] = clamp16(sample); + if(flag!=0x07) { + + short sample_byte = (short)read_8bit(stream->offset+(framesin*16)+2+i/2,stream->streamfile); + scale = ((i&1 ? + sample_byte >> 4 : + sample_byte & 0x0f)<<12); + + sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]); + } + + outbuf[sample_count] = clamp16(sample); hist2=hist1; hist1=sample; } diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 6ae6b710..51d4fbb8 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -262,6 +262,10 @@ RelativePath=".\meta\ps2_rxw.c" > + + diff --git a/src/meta/meta.h b/src/meta/meta.h index 919154fc..39abdace 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -45,4 +45,6 @@ VGMSTREAM * init_vgmstream_ps2_int(const char * const filename); VGMSTREAM * init_vgmstream_ps2_exst(const char * const filename); +VGMSTREAM * init_vgmstream_ps2_svag(const char * const filename); + #endif diff --git a/src/meta/ps2_ads.c b/src/meta/ps2_ads.c index fc0b1cfd..fc955b4a 100644 --- a/src/meta/ps2_ads.c +++ b/src/meta/ps2_ads.c @@ -79,7 +79,7 @@ VGMSTREAM * init_vgmstream_ps2_ads(const char * const filename) { vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset= - 0x28+vgmstream->interleave_block_size*i; + (off_t)(0x28+vgmstream->interleave_block_size*i); } } diff --git a/src/meta/ps2_exst.c b/src/meta/ps2_exst.c index 4a59c825..537a8da4 100644 --- a/src/meta/ps2_exst.c +++ b/src/meta/ps2_exst.c @@ -1,17 +1,17 @@ #include "meta.h" #include "../util.h" -/* EXST - - PS2 INT format is an interleaved format found in Shadow of the Colossus - The header start with a EXST id. - The headers and bgm datas was separated in the game, and joined in order - to add support for vgmstream - - The interleave value is allways 0x400 - known extensions : .STS - - 2008-05-13 - Fastelbja : First version ... +/* EXST + + PS2 INT format is an interleaved format found in Shadow of the Colossus + The header start with a EXST id. + The headers and bgm datas was separated in the game, and joined in order + to add support for vgmstream + + The interleave value is allways 0x400 + known extensions : .STS + + 2008-05-13 - Fastelbja : First version ... */ VGMSTREAM * init_vgmstream_ps2_exst(const char * const filename) { @@ -71,7 +71,7 @@ VGMSTREAM * init_vgmstream_ps2_exst(const char * const filename) { vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset= - 0x800+vgmstream->interleave_block_size*i; + (off_t)(0x800+vgmstream->interleave_block_size*i); } } diff --git a/src/meta/ps2_int.c b/src/meta/ps2_int.c index bfc2406b..7f5a807e 100644 --- a/src/meta/ps2_int.c +++ b/src/meta/ps2_int.c @@ -34,7 +34,7 @@ VGMSTREAM * init_vgmstream_ps2_int(const char * const filename) { vgmstream->channels = 2; vgmstream->sample_rate = 48000; vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = get_streamfile_size(infile)/4; + vgmstream->num_samples = (int32_t)(get_streamfile_size(infile)/4); vgmstream->interleave_block_size = 0x200; vgmstream->layout_type = layout_interleave; vgmstream->meta_type = meta_PS2_RAW; diff --git a/src/meta/ps2_npsf.c b/src/meta/ps2_npsf.c index 93be1d7f..b0bbd3f8 100644 --- a/src/meta/ps2_npsf.c +++ b/src/meta/ps2_npsf.c @@ -62,7 +62,7 @@ VGMSTREAM * init_vgmstream_ps2_npsf(const char * const filename) { vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset= - start_offset+vgmstream->interleave_block_size*i; + (off_t)(start_offset+vgmstream->interleave_block_size*i); } } diff --git a/src/meta/ps2_rxw.c b/src/meta/ps2_rxw.c index aac7374d..3c84eb9f 100644 --- a/src/meta/ps2_rxw.c +++ b/src/meta/ps2_rxw.c @@ -64,7 +64,7 @@ VGMSTREAM * init_vgmstream_ps2_rxw(const char * const filename) { vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset= - start_offset+vgmstream->interleave_block_size*i; + (off_t)(start_offset+vgmstream->interleave_block_size*i); } } diff --git a/src/meta/ps2_svag.c b/src/meta/ps2_svag.c new file mode 100644 index 00000000..2410283b --- /dev/null +++ b/src/meta/ps2_svag.c @@ -0,0 +1,88 @@ +#include "meta.h" +#include "../util.h" + +/* SVAG + + PS2 SVAG format is an interleaved format found in many konami Games + The header start with a Svag id and have the sentence : + "ALL RIGHTS RESERVED.KONAMITYO Sound Design Dept. " + or "ALL RIGHTS RESERVED.KCE-Tokyo Sound Design Dept. " + + 2008-05-13 - Fastelbja : First version ... + Thx to HCS for his awesome work on shortblock interleave +*/ + +VGMSTREAM * init_vgmstream_ps2_svag(const char * const filename) { + VGMSTREAM * vgmstream = NULL; + STREAMFILE * infile = NULL; + + int loop_flag=0; + int channel_count; + int i; + + /* check extension, case insensitive */ + if (strcasecmp("svag",filename_extension(filename))) goto fail; + + /* try to open the file for header reading */ + infile = open_streamfile(filename); + if (!infile) goto fail; + + /* check SVAG Header */ + if (read_32bitBE(0x00,infile) != 0x53766167) + goto fail; + + /* check loop */ + loop_flag = (read_32bitLE(0x14,infile)==1); + + channel_count=read_16bitLE(0x0C,infile); + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + vgmstream->channels = read_16bitLE(0x0C,infile); + vgmstream->sample_rate = read_32bitLE(0x08,infile); + + /* Compression Scheme */ + vgmstream->coding_type = coding_PSX; + vgmstream->num_samples = read_32bitLE(0x04,infile)/16*28/vgmstream->channels; + + /* Get loop point values */ + if(vgmstream->loop_flag) { + vgmstream->loop_start_sample = read_32bitLE(0x18,infile)/16*28; + vgmstream->loop_end_sample = read_32bitLE(0x04,infile)/16*28/vgmstream->channels; + } + + vgmstream->interleave_block_size = read_32bitLE(0x10,infile); + + /* There's no value on header to get the smallblock_size length */ + /* so we add to calculate it based upon the file length, which can broke things */ + /* with bad ripped stuff ... */ + vgmstream->interleave_smallblock_size = ((get_streamfile_size(infile)-0x800)%(2*vgmstream->interleave_block_size))/2; + vgmstream->layout_type = layout_interleave_shortblock; + vgmstream->meta_type = meta_PS2_SVAG; + + close_streamfile(infile); infile=NULL; + + /* open the file for reading by each channel */ + { + for (i=0;ich[i].streamfile = open_streamfile_buffer(filename,0x8000); + + if (!vgmstream->ch[i].streamfile) goto fail; + + vgmstream->ch[i].channel_start_offset= + vgmstream->ch[i].offset= + (off_t)(0x800+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 b8f56972..1bf23332 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 21 +#define INIT_VGMSTREAM_FCNS 22 VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { init_vgmstream_adx, /* 0 */ init_vgmstream_brstm, /* 1 */ @@ -38,6 +38,7 @@ VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { init_vgmstream_ps2_int, /* 18 */ init_vgmstream_ngc_dsp_stm, /* 19 */ init_vgmstream_ps2_exst, /* 20 */ + init_vgmstream_ps2_svag, /* 21 */ }; @@ -602,6 +603,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { case meta_PS2_EXST: snprintf(temp,TEMPSIZE,"EXST File (Shadow of the Colossus)"); break; + case meta_PS2_SVAG: + snprintf(temp,TEMPSIZE,"Konami SVAG Audio File"); + break; default: snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET"); } diff --git a/src/vgmstream.h b/src/vgmstream.h index 80d1024d..a97cd260 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -79,6 +79,8 @@ typedef enum { meta_PS2_RXW, /* Sony Arc The Lad Sound File */ meta_PS2_RAW, /* RAW Interleaved Format */ meta_PS2_EXST, /* Shadow of Colossus EXST */ + meta_PS2_SVAG, /* Konami SVAG */ + meta_PSX_XA, /* CD-XA with RIFF header */ } meta_t; diff --git a/winamp/in_vgmstream.c b/winamp/in_vgmstream.c index 0952c3cc..2ed96224 100644 --- a/winamp/in_vgmstream.c +++ b/winamp/in_vgmstream.c @@ -45,7 +45,7 @@ int fade_samples = 0; #define EXTENSION_LIST_SIZE 1024 char working_extension_list[EXTENSION_LIST_SIZE] = {0}; -#define EXTENSION_COUNT 19 +#define EXTENSION_COUNT 20 char * extension_list[EXTENSION_COUNT] = { "adx\0ADX Audio File (*.ADX)\0", "afc\0AFC Audio File (*.AFC)\0", @@ -66,6 +66,7 @@ char * extension_list[EXTENSION_COUNT] = { "rxw\0PS2 RXWS File (*.RXW)\0", "int\0PS2 RAW Interleaved PCM (*.INT)\0", "sts\0PS2 EXST Audio File (*.STS)\0", + "svag\0PS2 SVAG Audio File (*.SVAG)\0", }; /* stubs, we don't do anything fancy yet */