2008-07-25 19:49:09 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* RKV (from Legacy of Kain - Blood Omen 2) */
|
|
|
|
VGMSTREAM * init_vgmstream_ps2_rkv(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
2009-09-09 22:57:52 +02:00
|
|
|
off_t start_offset=0;
|
2008-12-16 16:48:21 +01:00
|
|
|
int loop_flag;
|
2008-07-25 19:49:09 +02:00
|
|
|
int channel_count;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("rkv",filename_extension(filename))) goto fail;
|
|
|
|
|
2009-09-09 22:57:52 +02:00
|
|
|
// Some RKV got info @ offset 0
|
|
|
|
// Some other @ offset 4
|
|
|
|
if(read_32bitLE(0,streamFile)==0)
|
|
|
|
start_offset=4;
|
2008-07-25 19:49:09 +02:00
|
|
|
|
2009-09-09 22:57:52 +02:00
|
|
|
loop_flag = (read_32bitLE(start_offset+4,streamFile)!=0xFFFFFFFF);
|
|
|
|
channel_count = read_32bitLE(start_offset+0x0c,streamFile)+1;
|
2008-07-25 19:49:09 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
vgmstream->channels = channel_count;
|
2009-09-09 22:57:52 +02:00
|
|
|
vgmstream->sample_rate = read_32bitLE(start_offset,streamFile);
|
2008-07-25 19:49:09 +02:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
2009-09-09 22:57:52 +02:00
|
|
|
|
|
|
|
// sometimes sample count is not set on the header
|
|
|
|
vgmstream->num_samples = (get_streamfile_size(streamFile)-0x800)/16*28/channel_count;
|
|
|
|
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(start_offset+4,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(start_offset+8,streamFile);
|
2008-07-25 19:49:09 +02:00
|
|
|
}
|
|
|
|
|
2009-09-09 22:57:52 +02:00
|
|
|
start_offset = 0x800;
|
|
|
|
|
|
|
|
if((get_streamfile_size(streamFile)-0x800)%0x400)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_interleave_shortblock;
|
|
|
|
vgmstream->interleave_smallblock_size=((get_streamfile_size(streamFile)-0x800)%0x400)/channel_count;
|
|
|
|
} else {
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
}
|
2008-07-25 19:49:09 +02:00
|
|
|
|
2009-09-09 22:57:52 +02:00
|
|
|
vgmstream->interleave_block_size = 0x400;
|
|
|
|
vgmstream->meta_type = meta_PS2_RKV;
|
2008-07-25 19:49:09 +02:00
|
|
|
/* open the file for reading */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
STREAMFILE * file;
|
|
|
|
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!file) goto fail;
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = file;
|
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=start_offset+
|
|
|
|
vgmstream->interleave_block_size*i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|