rwsd working

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@87 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-05-06 02:58:29 +00:00
parent 80d1f3c470
commit ac0c0f68ff
2 changed files with 36 additions and 38 deletions

View File

@ -2,7 +2,7 @@
#include "../util.h" #include "../util.h"
/* RWSD is quite similar to BRSTM, but can contain several streams. /* RWSD is quite similar to BRSTM, but can contain several streams.
* Still, a lot of games use it for single streams. We only support the * Still, some games use it for single streams. We only support the
* single stream form here */ * single stream form here */
VGMSTREAM * init_vgmstream_rwsd(const char * const filename) { VGMSTREAM * init_vgmstream_rwsd(const char * const filename) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
@ -10,36 +10,46 @@ VGMSTREAM * init_vgmstream_rwsd(const char * const filename) {
coding_t coding_type; coding_t coding_type;
off_t head_offset; off_t wave_offset;
size_t head_length; size_t wave_length;
int codec_number; int codec_number;
int channel_count; int channel_count;
int loop_flag; int loop_flag;
off_t start_offset; off_t start_offset;
size_t stream_size;
/* check extension, case insensitive */ /* check extension, case insensitive */
if (strcasecmp("brstm",filename_extension(filename))) goto fail; if (strcasecmp("rwsd",filename_extension(filename))) goto fail;
/* try to open the file for header reading */ /* try to open the file for header reading */
infile = open_streamfile(filename); infile = open_streamfile(filename);
if (!infile) goto fail; if (!infile) goto fail;
/* check header */ /* check header */
if ((uint32_t)read_32bitBE(0,infile)!=0x5253544D || /* "RSTM" */ if ((uint32_t)read_32bitBE(0,infile)!=0x52575344 || /* "RWSD" */
(uint32_t)read_32bitBE(4,infile)!=0xFEFF0100) (uint32_t)read_32bitBE(4,infile)!=0xFEFF0102)
goto fail; goto fail;
/* get head offset, check */ /* ideally we would look through the chunk list for a WAVE chunk,
head_offset = read_32bitBE(0x10,infile); * but it's always in the same order */
if ((uint32_t)read_32bitBE(head_offset,infile)!=0x48454144) /* "HEAD" */ /* get WAVE offset, check */
wave_offset = read_32bitBE(0x18,infile);
if ((uint32_t)read_32bitBE(wave_offset,infile)!=0x57415645) /* "WAVE" */
goto fail;
/* get WAVE size, check */
wave_length = read_32bitBE(0x1c,infile);
if (read_32bitBE(wave_offset+4,infile)!=wave_length)
goto fail; goto fail;
head_length = read_32bitBE(0x14,infile);
/* check type details */ /* check wave count */
codec_number = read_8bit(head_offset+0x20,infile); if (read_32bitBE(wave_offset+8,infile) != 1)
loop_flag = read_8bit(head_offset+0x21,infile); goto fail; /* only support 1 */
channel_count = read_8bit(head_offset+0x22,infile);
/* get type details */
codec_number = read_8bit(wave_offset+0x10,infile);
loop_flag = read_8bit(wave_offset+0x11,infile);
channel_count = read_8bit(wave_offset+0x12,infile);
switch (codec_number) { switch (codec_number) {
case 0: case 0:
@ -63,40 +73,32 @@ VGMSTREAM * init_vgmstream_rwsd(const char * const filename) {
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
/* fill in the vital statistics */ /* fill in the vital statistics */
vgmstream->num_samples = read_32bitBE(head_offset+0x2c,infile); vgmstream->num_samples = read_32bitBE(wave_offset+0x1c,infile);
vgmstream->sample_rate = (uint16_t)read_16bitBE(head_offset+0x24,infile); vgmstream->sample_rate = (uint16_t)read_16bitBE(wave_offset+0x14,infile);
/* channels and loop flag are set by allocate_vgmstream */ /* channels and loop flag are set by allocate_vgmstream */
vgmstream->loop_start_sample = read_32bitBE(head_offset+0x28,infile); vgmstream->loop_start_sample = read_32bitBE(wave_offset+0x18,infile);
vgmstream->loop_end_sample = vgmstream->num_samples; vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->coding_type = coding_type; vgmstream->coding_type = coding_type;
if (channel_count==1) vgmstream->layout_type = layout_none;
vgmstream->layout_type = layout_none;
else
vgmstream->layout_type = layout_interleave_shortblock;
vgmstream->meta_type = meta_RSTM;
vgmstream->interleave_block_size = read_32bitBE(head_offset+0x38,infile); vgmstream->meta_type = meta_RWSD;
vgmstream->interleave_smallblock_size = read_32bitBE(head_offset+0x48,infile);
if (vgmstream->coding_type == coding_NGC_DSP) { if (vgmstream->coding_type == coding_NGC_DSP) {
off_t coef_offset; off_t coef_offset;
off_t coef_offset1;
off_t coef_offset2;
int i,j; int i,j;
coef_offset1=read_32bitBE(head_offset+0x1c,infile); coef_offset=0x6c;
coef_offset2=read_32bitBE(head_offset+0x10+coef_offset1,infile);
coef_offset=coef_offset2+0x10;
for (j=0;j<vgmstream->channels;j++) { for (j=0;j<vgmstream->channels;j++) {
for (i=0;i<16;i++) { for (i=0;i<16;i++) {
vgmstream->ch[j].adpcm_coef[i]=read_16bitBE(head_offset+coef_offset+j*0x38+i*2,infile); vgmstream->ch[j].adpcm_coef[i]=read_16bitBE(wave_offset+coef_offset+j*0x30+i*2,infile);
} }
} }
} }
start_offset = read_32bitBE(head_offset+0x30,infile); start_offset = read_32bitBE(8,infile);
stream_size = read_32bitBE(wave_offset+0x50,infile);
close_streamfile(infile); infile=NULL; close_streamfile(infile); infile=NULL;
@ -104,18 +106,14 @@ VGMSTREAM * init_vgmstream_rwsd(const char * const filename) {
{ {
int i; int i;
for (i=0;i<channel_count;i++) { for (i=0;i<channel_count;i++) {
if (vgmstream->layout_type==layout_interleave_shortblock) vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
vgmstream->interleave_block_size);
else
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
0x1000); 0x1000);
if (!vgmstream->ch[i].streamfile) goto fail; if (!vgmstream->ch[i].streamfile) goto fail;
vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset= vgmstream->ch[i].offset=
start_offset + i*vgmstream->interleave_block_size; start_offset + i*stream_size;
} }
} }

View File

@ -6,7 +6,7 @@ export STRIP=strip
.PHONY: libvgmstream.a .PHONY: libvgmstream.a
test: libvgmstream.a test.o test: libvgmstream.a test.o
$(CC) test.o $(LDFLAGS) -o test $(CC) test.o $(LDFLAGS) $(CFLAGS) -o test
$(STRIP) test $(STRIP) test
test.o: test.c test.o: test.c