Clean .WSI

This commit is contained in:
bnnm 2018-03-23 18:34:37 +01:00
parent 7b1fed0720
commit 8bb9fa5f4a
7 changed files with 68 additions and 148 deletions

View File

@ -556,7 +556,7 @@ static const layout_info layout_info_list[] = {
{layout_blocked_ea_schl, "blocked (EA SCHl)"},
{layout_blocked_ea_1snh, "blocked (EA 1SNh)"},
{layout_blocked_caf, "blocked (CAF)"},
{layout_wsi_blocked, ".wsi blocked"},
{layout_blocked_wsi, "blocked (WSI)"},
{layout_xvas_blocked, ".xvas blocked"},
{layout_str_snds_blocked, ".str SNDS blocked"},
{layout_ws_aud_blocked, "Westwood Studios .aud blocked"},
@ -650,7 +650,7 @@ static const meta_info meta_info_list[] = {
{meta_DSP_SADB, "Procyon Studio SADB header"},
{meta_SADL, "Procyon Studio SADL header"},
{meta_PS2_BMDX, "Beatmania .bmdx header"},
{meta_DSP_WSI, ".wsi header"},
{meta_DSP_WSI, "Alone in the Dark .WSI header"},
{meta_AIFC, "Audio Interchange File Format AIFF-C"},
{meta_AIFF, "Audio Interchange File Format"},
{meta_STR_SNDS, ".str SNDS SHDR chunk"},

View File

@ -89,8 +89,8 @@ void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM *
case layout_blocked_caf:
block_update_caf(vgmstream->next_block_offset,vgmstream);
break;
case layout_wsi_blocked:
wsi_block_update(vgmstream->next_block_offset,vgmstream);
case layout_blocked_wsi:
block_update_wsi(vgmstream->next_block_offset,vgmstream);
break;
case layout_str_snds_blocked:
str_snds_block_update(vgmstream->next_block_offset,vgmstream);

View File

@ -18,8 +18,7 @@ void xa_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_ea_schl(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_ea_1snh(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_caf(off_t block_offset, VGMSTREAM * vgmstream);
void wsi_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_wsi(off_t block_offset, VGMSTREAM * vgmstream);
void str_snds_block_update(off_t block_offset, VGMSTREAM * vgmstream);

View File

@ -1,23 +1,21 @@
#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) {
/* .wsi - headered blocks with a single channel */
void block_update_wsi(off_t block_offset, VGMSTREAM * vgmstream) {
STREAMFILE* streamFile = vgmstream->ch[0].streamfile;
int i;
off_t channel_block_size;
/* assume that all channels have the same size for this block */
channel_block_size = read_32bitBE(block_offset, streamFile);
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;
vgmstream->current_block_size = channel_block_size - 0x10; /* remove header */
vgmstream->next_block_offset = block_offset + channel_block_size*vgmstream->channels;
for (i=0;i<vgmstream->channels;i++) {
vgmstream->ch[i].offset = vgmstream->current_block_offset +
0x10 + (vgmstream->current_block_size+0x10)*i;
for (i = 0; i < vgmstream->channels; i++) {
vgmstream->ch[i].offset = block_offset + channel_block_size*i + 0x10;
}
}

View File

@ -875,180 +875,103 @@ 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 */
#define WSI_MAX_CHANNELS 2
/* .wsi - blocked dsp [Alone in the Dark (Wii)] */
VGMSTREAM * init_vgmstream_wsi(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
struct dsp_header header[2];
off_t start_offset[2];
off_t start_offset, header_offset;
size_t header_spacing;
struct dsp_header ch_header[WSI_MAX_CHANNELS];
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;
/* checks */
if (!check_extensions(streamFile, "wsi"))
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 */
* 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_offset;
off_t block_size_has_been;
int i;
check_offset = read_32bitBE(0x0,streamFile);
if (check_offset < 8) goto fail;
block_offset = read_32bitBE(0x00,streamFile);
if (block_offset < 0x08) goto fail;
block_size_has_been = check_offset;
block_size_has_been = block_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);
for (i = 0; i < 4*channel_count; i++) {
off_t block_size = read_32bitBE(block_offset,streamFile);
/* expect at least the block header */
if (block_size < 0x10) goto fail;
if (block_size < 0x10)
goto fail; /* expect at least the block header */
if (i%channel_count+1 != read_32bitBE(block_offset+0x08,streamFile))
goto fail; /* expect the channel numbers to alternate */
/* expect the channel numbers to alternate */
if (i%channel_count+1 != read_32bitBE(check_offset+8,streamFile)) goto fail;
if (i%channel_count==0)
block_size_has_been = block_size;
else if (block_size != block_size_has_been)
goto fail; /* expect every block in a set of channels to have the same size */
/* 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;
block_offset += block_size;
}
}
/* look at DSP headers */
start_offset = read_32bitBE(0x00, streamFile);
header_offset = start_offset + 0x10;
header_spacing = read_32bitBE(start_offset,streamFile);
{
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;
/* read dsp */
if (!dsp_load_header(ch_header, channel_count, streamFile,header_offset,header_spacing)) goto fail;
if (!check_dsp_format(ch_header, channel_count)) goto fail;
if (!check_dsp_samples(ch_header, channel_count)) goto fail;
//if (!check_dsp_initial_ps(ch_header, channel_count, streamFile,start_offset,interleave)) goto fail;
//if (!check_dsp_loop_ps(ch_header, channel_count, streamFile,start_offset,interleave)) goto fail;
vgmstream = allocate_vgmstream(channel_count,header[0].loop_flag);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,ch_header[0].loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
/* incomplete last frame is missing */
vgmstream->num_samples = header[0].sample_count/14*14;
vgmstream->sample_rate = header[0].sample_rate;
vgmstream->sample_rate = ch_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->num_samples = ch_header[0].sample_count / 14 * 14; /* remove incomplete last frame */
vgmstream->loop_start_sample = dsp_nibbles_to_samples(ch_header[0].loop_start_offset);
vgmstream->loop_end_sample = dsp_nibbles_to_samples(ch_header[0].loop_end_offset)+1;
if (vgmstream->loop_end_sample > vgmstream->num_samples) /* don't know why, but it does happen*/
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;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_blocked_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;
}
}
setup_vgmstream_dsp(vgmstream, ch_header);
/* open the file for reading */
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,est_block_size*4);
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
if (!vgmstream->ch[0].streamfile) goto fail;
wsi_block_update(read_32bitBE(0,streamFile),vgmstream);
block_update_wsi(start_offset,vgmstream);
/* first block has DSP header */
{
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];
vgmstream->current_block_size -= 0x60;
for (i = 0; i < vgmstream->channels; i++) {
vgmstream->ch[i].offset += 0x60;
}
}
/* 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);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -897,7 +897,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
case layout_blocked_ea_schl:
case layout_blocked_ea_1snh:
case layout_blocked_caf:
case layout_wsi_blocked:
case layout_blocked_wsi:
case layout_str_snds_blocked:
case layout_ws_aud_blocked:
case layout_matx_blocked:

View File

@ -221,7 +221,7 @@ typedef enum {
layout_blocked_ea_schl,
layout_blocked_ea_1snh,
layout_blocked_caf,
layout_wsi_blocked,
layout_blocked_wsi,
layout_str_snds_blocked,
layout_ws_aud_blocked,
layout_matx_blocked,