add RIFX support, including Punch-Out! (with WiiH)

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@655 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2009-05-25 20:59:50 +00:00
parent 2d7e680cc4
commit fc1e4c4c9b
4 changed files with 222 additions and 0 deletions

View File

@ -115,6 +115,8 @@ VGMSTREAM * init_vgmstream_svs(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_riff(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_rifx(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_pos(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_nwa(STREAMFILE * streamFile);

View File

@ -361,3 +361,214 @@ fail:
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}
VGMSTREAM * init_vgmstream_rifx(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[260];
off_t file_size = -1;
int channel_count = 0;
int sample_count = 0;
int fact_sample_count = -1;
int sample_rate = 0;
int coding_type = -1;
off_t start_offset = -1;
int interleave = -1;
off_t wiih_offset = -1;
uint32_t wiih_size = 0;
int loop_flag = 0;
off_t loop_start_offset = -1;
off_t loop_end_offset = -1;
uint32_t riff_size;
uint32_t data_size = 0;
uint32_t block_size = 0;
int FormatChunkFound = 0;
int DataChunkFound = 0;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("wav",filename_extension(filename)) &&
strcasecmp("lwav",filename_extension(filename)))
{
goto fail;
}
/* check header */
if ((uint32_t)read_32bitBE(0,streamFile)!=0x52494658) /* "RIFX" */
goto fail;
/* check for WAVE form */
if ((uint32_t)read_32bitBE(8,streamFile)!=0x57415645) /* "WAVE" */
goto fail;
riff_size = read_32bitBE(4,streamFile);
file_size = get_streamfile_size(streamFile);
/* check for tructated RIFF */
if (file_size < riff_size+8) goto fail;
/* read through chunks to verify format and find metadata */
{
off_t current_chunk = 0xc; /* start with first chunk */
while (current_chunk < file_size && current_chunk < riff_size+8) {
uint32_t chunk_type = read_32bitBE(current_chunk,streamFile);
off_t chunk_size = read_32bitBE(current_chunk+4,streamFile);
if (current_chunk+8+chunk_size > file_size) goto fail;
switch(chunk_type) {
case 0x666d7420: /* "fmt " */
/* only one per file */
if (FormatChunkFound) goto fail;
FormatChunkFound = 1;
sample_rate = read_32bitBE(current_chunk+0x0c,streamFile);
channel_count = read_16bitBE(current_chunk+0x0a,streamFile);
block_size = read_16bitBE(current_chunk+0x14,streamFile);
switch ((uint16_t)read_16bitBE(current_chunk+0x8,streamFile)) {
case 1: /* PCM */
switch (read_16bitBE(current_chunk+0x16,streamFile)) {
case 16:
coding_type = coding_PCM16BE;
interleave = 2;
break;
case 8:
coding_type = coding_PCM8_U_int;
interleave = 1;
break;
default:
goto fail;
}
break;
case 0xFFF0:
coding_type = coding_NGC_DSP;
interleave = 8;
break;
default:
goto fail;
}
break;
case 0x64617461: /* data */
/* at most one per file */
if (DataChunkFound) goto fail;
DataChunkFound = 1;
start_offset = current_chunk + 8;
data_size = chunk_size;
break;
case 0x736D706C: /* smpl */
/* check loop count */
if (read_32bitBE(current_chunk+0x24, streamFile)==1)
{
/* check loop info */
if (read_32bitBE(current_chunk+0x2c+4, streamFile)==0)
{
loop_flag = 1;
loop_start_offset =
read_32bitBE(current_chunk+0x2c+8, streamFile);
loop_end_offset =
read_32bitBE(current_chunk+0x2c+0xc,streamFile);
}
}
break;
case 0x66616374: /* fact */
if (chunk_size != 4) break;
fact_sample_count = read_32bitBE(current_chunk+8, streamFile);
break;
case 0x57696948: /* WiiH */
wiih_size = read_32bitBE(current_chunk+4, streamFile);
wiih_offset = current_chunk+8;
break;
default:
/* ignorance is bliss */
break;
}
current_chunk += 8+chunk_size;
}
}
if (!FormatChunkFound || !DataChunkFound) goto fail;
switch (coding_type) {
case coding_PCM16BE:
sample_count = data_size/2/channel_count;
break;
case coding_PCM8_U_int:
sample_count = data_size/channel_count;
break;
case coding_NGC_DSP:
/* the only way of getting DSP info right now */
if (wiih_offset < 0 || wiih_size != 0x2e*channel_count) goto fail;
sample_count = data_size/8/channel_count*14;
break;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = sample_count;
vgmstream->sample_rate = sample_rate;
vgmstream->coding_type = coding_type;
if (channel_count > 1 && coding_type != coding_PCM8_U_int)
vgmstream->layout_type = layout_interleave;
else
vgmstream->layout_type = layout_none;
vgmstream->interleave_block_size = interleave;
if (coding_type == coding_MS_IMA)
vgmstream->interleave_block_size = block_size;
if (loop_flag) {
if (loop_start_offset >= 0)
{
vgmstream->loop_start_sample = loop_start_offset;
vgmstream->loop_end_sample = loop_end_offset;
vgmstream->meta_type = meta_RIFX_WAVE_smpl;
}
}
else
{
vgmstream->meta_type = meta_RIFX_WAVE;
}
/* read from WiiH */
if (wiih_offset >= 0) {
int i,j;
for (i=0;i<channel_count;i++) {
for (j=0;j<16;j++)
vgmstream->ch[i].adpcm_coef[j] = read_16bitBE(wiih_offset + i * 0x2e + j * 2,streamFile);
vgmstream->ch[i].adpcm_history1_16 = read_16bitBE(wiih_offset + i * 0x2e + 4,streamFile);
vgmstream->ch[i].adpcm_history2_16 = read_16bitBE(wiih_offset + i * 0x2e + 6,streamFile);
}
}
/* open the file, set up each channel */
{
int i;
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,
STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!vgmstream->ch[0].streamfile) goto fail;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = vgmstream->ch[0].streamfile;
vgmstream->ch[i].offset = vgmstream->ch[i].channel_start_offset =
start_offset+i*interleave;
}
}
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}

View File

@ -72,6 +72,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
init_vgmstream_amts,
init_vgmstream_svs,
init_vgmstream_riff,
init_vgmstream_rifx,
init_vgmstream_pos,
init_vgmstream_nwa,
init_vgmstream_eacs,
@ -1920,6 +1921,12 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case meta_RIFF_WAVE_smpl:
snprintf(temp,TEMPSIZE,"RIFF WAVE header with sample looping info");
break;
case meta_RIFX_WAVE:
snprintf(temp,TEMPSIZE,"RIFX WAVE header");
break;
case meta_RIFX_WAVE_smpl:
snprintf(temp,TEMPSIZE,"RIFX WAVE header with sample looping info");
break;
case meta_PCM:
snprintf(temp,TEMPSIZE,"PCM file with custom header");
break;

View File

@ -369,6 +369,8 @@ typedef enum {
meta_RIFF_WAVE_labl_Marker, /* RIFF w/ loop Markers in LIST-adtl-labl */
meta_RIFF_WAVE_smpl, /* RIFF w/ loop data in smpl chunk */
meta_RIFF_WAVE_MWV, /* .mwv RIFF w/ loop data in ctrl chunk pflt */
meta_RIFX_WAVE, /* RIFX, for big-endian WAVs */
meta_RIFX_WAVE_smpl, /* RIFX w/ loop data in smpl chunk */
meta_NWA, /* Visual Art's NWA */
meta_NWA_NWAINFOINI, /* NWA w/ NWAINFO.INI for looping */
meta_NWA_GAMEEXEINI, /* NWA w/ Gameexe.ini for looping */