2008-05-24 17:11:32 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* XWAV
|
|
|
|
|
|
|
|
XWAV use the common RIFF/WAVE format with Codec ID = 0x0069
|
|
|
|
It has been renamed to xwav to avoid vgmstream to handle all RIFF/WAV format
|
|
|
|
known extensions : XWAV
|
|
|
|
|
|
|
|
2008-05-24 - Fastelbja : First version ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
VGMSTREAM * init_vgmstream_xbox_xwav(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2008-05-24 17:11:32 +02:00
|
|
|
|
|
|
|
int loop_flag=0;
|
|
|
|
int channel_count;
|
|
|
|
off_t start_offset;
|
2008-09-29 23:06:12 +02:00
|
|
|
int i,j=0;
|
2008-05-24 17:11:32 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("xwav",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* Check for headers */
|
|
|
|
if(!((read_32bitBE(0x00,streamFile)==0x52494646) &&
|
|
|
|
(read_32bitBE(0x08,streamFile)==0x57415645) &&
|
|
|
|
(read_32bitBE(0x0C,streamFile)==0x666D7420) &&
|
|
|
|
(read_16bitLE(0x14,streamFile)==0x0069)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* No loop on wavm */
|
2008-09-29 23:06:12 +02:00
|
|
|
if(read_32bitBE(0x28,streamFile)==0x77736D70)
|
|
|
|
loop_flag = 1;
|
|
|
|
else
|
|
|
|
loop_flag = 0;
|
2008-05-24 17:11:32 +02:00
|
|
|
|
|
|
|
/* Always stereo files */
|
|
|
|
channel_count=read_16bitLE(0x16,streamFile);
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2008-09-29 23:06:12 +02:00
|
|
|
/* hack for loop wave found on Dynasty warriors */
|
|
|
|
if(loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x4C,streamFile);
|
|
|
|
vgmstream->loop_end_sample = vgmstream->loop_start_sample + read_32bitLE(0x50,streamFile);
|
|
|
|
}
|
|
|
|
|
2008-05-24 17:11:32 +02:00
|
|
|
/* fill in the vital statistics */
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x18,streamFile);
|
|
|
|
|
|
|
|
/* search for "data" */
|
|
|
|
start_offset=0x1C;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(read_32bitBE(start_offset,streamFile)==0x64617461)
|
|
|
|
break;
|
|
|
|
start_offset+=4;
|
2008-06-03 20:41:26 +02:00
|
|
|
} while (start_offset<(off_t)get_streamfile_size(streamFile));
|
2008-05-24 17:11:32 +02:00
|
|
|
|
2008-06-03 20:41:26 +02:00
|
|
|
if(start_offset>=(off_t)get_streamfile_size(streamFile))
|
2008-05-24 17:11:32 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
start_offset+=4;
|
|
|
|
|
|
|
|
vgmstream->coding_type = coding_XBOX;
|
|
|
|
vgmstream->num_samples = read_32bitLE(start_offset,streamFile) / 36 * 64 / vgmstream->channels;
|
2008-08-10 22:08:03 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2008-05-24 17:11:32 +02:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_XBOX_RIFF;
|
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
|
2008-09-29 23:06:12 +02:00
|
|
|
{
|
|
|
|
if(channel_count>2) {
|
|
|
|
for (i=0;i<channel_count;i++,j++) {
|
|
|
|
if((j&2) && (i!=0)) {
|
|
|
|
j=0;
|
|
|
|
start_offset+=36*2;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,36);
|
|
|
|
vgmstream->ch[i].offset = start_offset+4;
|
|
|
|
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,36);
|
|
|
|
vgmstream->ch[i].offset = start_offset+4;
|
|
|
|
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
}
|
|
|
|
}
|
2008-05-24 17:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|