add .wsi support

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@260 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-06-29 01:30:13 +00:00
parent 221ebc16a6
commit 98e0469264
13 changed files with 228 additions and 3 deletions

View File

@ -89,6 +89,7 @@ File types supported by this version of vgmstream:
- .ogg, .logg (Ogg Vorbis)
- .sad (GC DSP ADPCM)
- .bmdx (PSX ADPCM)
- .wsi (Wii DSP ADPCM)
Enjoy!
-hcs

View File

@ -17,7 +17,8 @@ LAYOUT_OBJS=layout/ast_blocked.o \
layout/nolayout.o \
layout/xa_blocked.o \
layout/caf_blocked.o \
layout/ea_block.o
layout/ea_block.o \
layout/wsi_blocked.o
META_OBJS=meta/adx_header.o \
meta/afc_header.o \

View File

@ -4,6 +4,6 @@ AM_CFLAGS = -Wall @CFLAGS@ -I$(top_builddir) -I$(top_srcdir)
AM_MAKEFLAGS=-f Makefile.unix
liblayout_la_LDFLAGS =
liblayout_la_SOURCES = ast_blocked.c blocked.c caf_blocked.c ea_block.c halpst_blocked.c interleave.c nolayout.c xa_blocked.c
liblayout_la_SOURCES = ast_blocked.c blocked.c caf_blocked.c ea_block.c halpst_blocked.c interleave.c nolayout.c xa_blocked.c wsi_blocked.c
EXTRA_DIST = layout.h

View File

@ -57,6 +57,9 @@ void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM *
case layout_caf_blocked:
caf_block_update(vgmstream->next_block_offset,vgmstream);
break;
case layout_wsi_blocked:
wsi_block_update(vgmstream->next_block_offset,vgmstream);
break;
default:
break;
}

View File

@ -16,6 +16,8 @@ void ea_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void caf_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void wsi_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
void render_vgmstream_nolayout(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream);

23
src/layout/wsi_blocked.c Normal file
View File

@ -0,0 +1,23 @@
#include "layout.h"
#include "../vgmstream.h"
/* set up for the block at the given offset */
void wsi_block_update(off_t block_offset, VGMSTREAM * vgmstream) {
int i;
/* assume that all channels have the same size for this block */
vgmstream->current_block_offset = block_offset;
/* current_block_size is the data size in this block, so subtract header */
vgmstream->current_block_size = read_32bitBE(
vgmstream->current_block_offset,
vgmstream->ch[0].streamfile) - 0x10;
vgmstream->next_block_offset =
vgmstream->current_block_offset +
(vgmstream->current_block_size + 0x10) * vgmstream->channels;
for (i=0;i<vgmstream->channels;i++) {
vgmstream->ch[i].offset = vgmstream->current_block_offset +
0x10 + (vgmstream->current_block_size+0x10)*i;
}
}

View File

@ -454,6 +454,10 @@
RelativePath=".\layout\xa_blocked.c"
>
</File>
<File
RelativePath=".\layout\wsi_blocked.c"
>
</File>
</Filter>
</Filter>
</Files>

View File

@ -89,4 +89,6 @@ VGMSTREAM * init_vgmstream_sadb(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ps2_bmdx(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_wsi(STREAMFILE * streamFile);
#endif

View File

@ -1,4 +1,5 @@
#include "meta.h"
#include "../layout/layout.h"
#include "../coding/coding.h"
#include "../util.h"
@ -701,3 +702,179 @@ fail:
return NULL;
}
/* .wsi as found in Alone in the Dark for Wii */
/* These appear to be standard .dsp, but interleaved in a blocked format */
VGMSTREAM * init_vgmstream_wsi(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[260];
struct dsp_header header[2];
off_t start_offset[2];
int channel_count;
size_t est_block_size = 0;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("wsi",filename_extension(filename))) goto fail;
/* I don't know if this is actually the channel count, or a block type
for the first block. Won't know until I see a mono .wsi */
channel_count = read_32bitBE(0x04,streamFile);
/* I've only allocated two headers, and I want to be alerted if a mono
.wsi shows up */
if (channel_count != 2) goto fail;
/* check for consistent block headers */
{
off_t check_offset;
off_t block_size_has_been;
int i;
check_offset = read_32bitBE(0x0,streamFile);
if (check_offset < 8) goto fail;
block_size_has_been = check_offset;
/* check 4 blocks, to get an idea */
for (i=0;i<4*channel_count;i++) {
off_t block_size;
block_size = read_32bitBE(check_offset,streamFile);
/* expect at least the block header */
if (block_size < 0x10) goto fail;
/* expect the channel numbers to alternate */
if (i%channel_count+1 != read_32bitBE(check_offset+8,streamFile)) goto fail;
/* expect every block in a set of channels to have the same size */
if (i%channel_count==0) block_size_has_been = block_size;
else if (block_size != block_size_has_been) goto fail;
/* get an estimate of block size for buffer sizing */
if (block_size > est_block_size) est_block_size = block_size;
check_offset += block_size;
}
}
/* look at DSP headers */
{
off_t check_offset;
int i;
check_offset = read_32bitBE(0x0,streamFile);
for (i=0;i<channel_count;i++) {
off_t block_size;
block_size = read_32bitBE(check_offset,streamFile);
/* make sure block is actually big enough to hold the dsp header
and beginning of first frame */
if (block_size < 0x61+0x10) goto fail;
if (read_dsp_header(&header[i], check_offset+0x10, streamFile)) goto fail;
start_offset[i] = check_offset + 0x60+0x10;
/* check initial predictor/scale */
if (header[i].initial_ps != (uint8_t)read_8bit(check_offset+0x60+0x10,streamFile))
goto fail;
/* check type==0 and gain==0 */
if (header[i].format || header[i].gain)
goto fail;
#if 0
/* difficult to use this with blocks, but might be worth doing */
if (header[i].loop_flag) {
off_t loop_off;
/* check loop predictor/scale */
loop_off = header[i].loop_start_offset/16*8;
if (header[i].loop_ps != (uint8_t)read_8bit(start_offset+loop_off,streamFile))
goto fail;
}
#endif
check_offset += block_size;
}
} /* done looking at headers */
/* check for agreement (two channels only) */
if (
header[0].sample_count != header[1].sample_count ||
header[0].nibble_count != header[1].nibble_count ||
header[0].sample_rate != header[1].sample_rate ||
header[0].loop_flag != header[1].loop_flag ||
header[0].loop_start_offset != header[1].loop_start_offset ||
header[0].loop_end_offset != header[1].loop_end_offset
) goto fail;
vgmstream = allocate_vgmstream(channel_count,header[0].loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = header[0].sample_count;
vgmstream->sample_rate = header[0].sample_rate;
vgmstream->loop_start_sample = dsp_nibbles_to_samples(
header[0].loop_start_offset);
vgmstream->loop_end_sample = dsp_nibbles_to_samples(
header[0].loop_end_offset)+1;
/* don't know why, but it does happen*/
if (vgmstream->loop_end_sample > vgmstream->num_samples)
vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_wsi_blocked;
vgmstream->meta_type = meta_DSP_WSI;
/* coeffs */
{
int i,j;
for (j=0;j<channel_count;j++) {
for (i=0;i<16;i++) {
vgmstream->ch[j].adpcm_coef[i] = header[j].coef[i];
}
}
/* initial history */
/* always 0 that I've ever seen, but for completeness... */
vgmstream->ch[j].adpcm_history1_16 = header[j].initial_hist1;
vgmstream->ch[j].adpcm_history2_16 = header[j].initial_hist2;
}
/* open the file for reading */
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,est_block_size*4);
if (!vgmstream->ch[0].streamfile) goto fail;
wsi_block_update(read_32bitBE(0,streamFile),vgmstream);
{
int i;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = vgmstream->ch[0].streamfile;
vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=start_offset[i];
}
}
/* first block isn't full of musics */
vgmstream->current_block_size -= 0x60;
return vgmstream;
fail:
/* clean up anything we may have opened */
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}

View File

@ -60,6 +60,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
#endif
init_vgmstream_sadb,
init_vgmstream_ps2_bmdx,
init_vgmstream_wsi,
};
#define INIT_VGMSTREAM_FCNS (sizeof(init_vgmstream_fcns)/sizeof(init_vgmstream_fcns[0]))
@ -268,6 +269,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
case layout_xa_blocked:
case layout_ea_blocked:
case layout_caf_blocked:
case layout_wsi_blocked:
render_vgmstream_blocked(buffer,sample_count,vgmstream);
break;
}
@ -690,6 +692,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case layout_caf_blocked:
snprintf(temp,TEMPSIZE,"CAF blocked");
break;
case layout_wsi_blocked:
snprintf(temp,TEMPSIZE,".wsi blocked");
break;
#ifdef VGM_USE_VORBIS
case layout_ogg_vorbis:
snprintf(temp,TEMPSIZE,"Ogg");
@ -883,6 +888,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case meta_PS2_BMDX:
snprintf(temp,TEMPSIZE,"Beatmania .bmdx header");
break;
case meta_DSP_WSI:
snprintf(temp,TEMPSIZE,".wsi header");
break;
default:
snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET");
}

View File

@ -53,6 +53,7 @@ typedef enum {
layout_xa_blocked,
layout_ea_blocked,
layout_caf_blocked,
layout_wsi_blocked,
#if 0
layout_strm_blocked, /* */
#endif
@ -78,6 +79,7 @@ typedef enum {
meta_DSP_GCM,
meta_DSP_STR, /* Conan .str files */
meta_DSP_SADB, /* .sad */
meta_DSP_WSI, /* .wsi */
/* Nintendo */
meta_STRM, /* STRM */

View File

@ -60,6 +60,7 @@ gchar *vgmstream_exts [] = {
"logg",
"sad",
"bmdx",
"wsi",
/* terminator */
NULL
};

View File

@ -117,7 +117,8 @@ char * extension_list[] = {
"genh\0GENH Audio File (*.GENH)\0",
"logg\0LOGG Audio File (*.LOGG)\0",
"sad\0SAD Audio File (*.SAD)\0",
"bmdx\0BMDX Audio File (*.BMDX)\n",
"bmdx\0BMDX Audio File (*.BMDX)\0",
"wsi\0WSI Audio File (*.WSI)\0",
};
void about(HWND hwndParent) {