2008-12-03 21:30:18 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* JOE (found in Wall-E and some more Pixar games) */
|
2008-12-03 21:30:18 +01:00
|
|
|
VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2008-12-03 21:30:18 +01:00
|
|
|
off_t start_offset;
|
|
|
|
uint8_t testBuffer[0x10];
|
|
|
|
off_t loopStart = 0;
|
|
|
|
off_t loopEnd = 0;
|
|
|
|
off_t readOffset = 0;
|
2013-07-05 20:48:17 +02:00
|
|
|
off_t blockOffset = 0;
|
|
|
|
off_t sampleOffset = 0;
|
2008-12-03 21:30:18 +01:00
|
|
|
size_t fileLength;
|
2013-07-05 20:48:17 +02:00
|
|
|
size_t dataLength;
|
|
|
|
size_t dataInterleave;
|
2008-12-03 21:30:18 +01:00
|
|
|
int loop_flag;
|
|
|
|
int channel_count;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("joe",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
2009-09-05 15:31:20 +02:00
|
|
|
// if (read_32bitBE(0x0C,streamFile) != 0xCCCCCCCC)
|
|
|
|
// goto fail;
|
2008-12-03 21:30:18 +01:00
|
|
|
|
2008-12-04 21:11:45 +01:00
|
|
|
loop_flag = 1;
|
2008-12-03 21:30:18 +01:00
|
|
|
channel_count = 2;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2013-07-05 20:48:17 +02:00
|
|
|
fileLength = get_streamfile_size(streamFile);
|
|
|
|
dataLength = read_32bitLE(0x4,streamFile);
|
|
|
|
dataInterleave = read_32bitLE(0x8,streamFile);
|
|
|
|
|
2008-12-03 21:30:18 +01:00
|
|
|
/* fill in the vital statistics */
|
2013-07-05 20:48:17 +02:00
|
|
|
start_offset = fileLength - dataLength;
|
2008-12-03 21:30:18 +01:00
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x0,streamFile);
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
2013-07-05 20:48:17 +02:00
|
|
|
vgmstream->num_samples = dataLength*28/16/channel_count;
|
2008-12-03 21:30:18 +01:00
|
|
|
|
|
|
|
|
2009-09-05 15:31:20 +02:00
|
|
|
readOffset = start_offset;
|
2008-12-03 21:30:18 +01:00
|
|
|
do {
|
2013-07-05 20:48:17 +02:00
|
|
|
off_t blockRead = (off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile);
|
|
|
|
|
|
|
|
readOffset += blockRead;
|
|
|
|
blockOffset += blockRead;
|
|
|
|
|
|
|
|
if (blockOffset >= dataInterleave) {
|
|
|
|
readOffset += dataInterleave;
|
|
|
|
blockOffset -= dataInterleave;
|
|
|
|
}
|
2008-12-03 21:30:18 +01:00
|
|
|
|
|
|
|
/* Loop Start */
|
|
|
|
if(testBuffer[0x01]==0x06) {
|
2013-07-05 20:48:17 +02:00
|
|
|
if(loopStart == 0) loopStart = sampleOffset;
|
2008-12-03 21:30:18 +01:00
|
|
|
/* break; */
|
|
|
|
}
|
2013-07-05 20:48:17 +02:00
|
|
|
|
|
|
|
sampleOffset += 28;
|
|
|
|
|
2008-12-03 21:30:18 +01:00
|
|
|
/* Loop End */
|
|
|
|
if(testBuffer[0x01]==0x03) {
|
2013-07-05 20:48:17 +02:00
|
|
|
if(loopEnd == 0) loopEnd = sampleOffset;
|
2008-12-03 21:30:18 +01:00
|
|
|
/* break; */
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (streamFile->get_offset(streamFile)<(int32_t)fileLength);
|
|
|
|
|
2013-07-05 20:48:17 +02:00
|
|
|
if(loopStart == 0 && loopEnd == 0) {
|
2008-12-03 21:30:18 +01:00
|
|
|
loop_flag = 0;
|
2013-07-05 20:48:17 +02:00
|
|
|
vgmstream->num_samples = dataLength*28/16/channel_count;
|
2008-12-03 21:30:18 +01:00
|
|
|
} else {
|
|
|
|
loop_flag = 1;
|
2013-07-05 20:48:17 +02:00
|
|
|
vgmstream->loop_start_sample = loopStart;
|
|
|
|
vgmstream->loop_end_sample = loopEnd;
|
|
|
|
}
|
2008-12-03 21:30:18 +01:00
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
2013-07-05 20:48:17 +02:00
|
|
|
vgmstream->interleave_block_size = dataInterleave;
|
2008-12-16 16:48:21 +01:00
|
|
|
vgmstream->meta_type = meta_PS2_JOE;
|
2008-12-03 21:30:18 +01: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;
|
|
|
|
}
|