2011-03-23 04:17:53 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* .KLBS (L@VE ONCE PS3 */
|
|
|
|
VGMSTREAM * init_vgmstream_ps3_klbs(STREAMFILE *streamFile)
|
2011-05-31 17:42:11 +02:00
|
|
|
{
|
2011-03-23 04:17:53 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2011-03-23 04:17:53 +01:00
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
size_t fileLength;
|
|
|
|
off_t readOffset = 0;
|
|
|
|
off_t start_offset;
|
|
|
|
off_t loop_start_offset = 0;
|
|
|
|
off_t loop_end_offset = 0;
|
2011-03-23 04:17:53 +01:00
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
uint8_t testBuffer[0x10];
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
2011-03-23 04:17:53 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2011-03-24 03:29:09 +01:00
|
|
|
if (strcasecmp("bnk",filename_extension(filename))) goto fail;
|
2011-03-23 04:17:53 +01:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x20,streamFile) != 0x6B6C4253)
|
|
|
|
goto fail;
|
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
// get file length
|
|
|
|
fileLength = get_streamfile_size(streamFile);
|
|
|
|
|
|
|
|
// Find loop start
|
|
|
|
start_offset = read_32bitBE(0x10,streamFile);
|
|
|
|
readOffset = start_offset;
|
|
|
|
|
|
|
|
do {
|
|
|
|
readOffset += (off_t)read_streamfile(testBuffer, readOffset, 0x10, streamFile);
|
|
|
|
|
|
|
|
// Loop Start ...
|
|
|
|
if(testBuffer[0x01] == 0x06)
|
|
|
|
{
|
|
|
|
loop_start_offset = readOffset - 0x10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (streamFile->get_offset(streamFile)<((int32_t)fileLength));
|
|
|
|
|
|
|
|
// start at last line of file and move up
|
|
|
|
readOffset = (int32_t)fileLength - 0x10;
|
|
|
|
|
|
|
|
// Find loop end
|
|
|
|
do {
|
|
|
|
readOffset -= (off_t)read_streamfile(testBuffer, readOffset, 0x10, streamFile);
|
|
|
|
|
|
|
|
// Loop End ...
|
|
|
|
if((testBuffer[0x01]==0x03) && (testBuffer[0x03]!=0x77))
|
|
|
|
{
|
|
|
|
loop_end_offset = readOffset + 0x20;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (readOffset > 0);
|
|
|
|
|
|
|
|
// setup loops
|
|
|
|
if (loop_start_offset > 0)
|
|
|
|
{
|
|
|
|
loop_flag = 1;
|
|
|
|
|
|
|
|
// if we have a start loop, use EOF if end loop is not found
|
|
|
|
if (loop_end_offset == 0)
|
|
|
|
{
|
|
|
|
loop_end_offset = (int32_t)fileLength - 0x10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loop_flag = 0;
|
|
|
|
}
|
2011-03-23 04:17:53 +01:00
|
|
|
|
|
|
|
channel_count = 2;
|
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
/* build the VGMSTREAM */
|
2011-03-23 04:17:53 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
/* fill in the vital statistics */
|
2011-05-31 17:42:11 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = read_32bitBE(0x90, streamFile);
|
|
|
|
vgmstream->meta_type = meta_PS3_KLBS;
|
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
vgmstream->channels = channel_count;
|
2011-03-23 04:17:53 +01:00
|
|
|
vgmstream->sample_rate = 48000;
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
2017-11-10 22:22:04 +01:00
|
|
|
vgmstream->num_samples = ((vgmstream->interleave_block_size * channel_count)/16/channel_count*28);
|
2011-03-23 04:17:53 +01:00
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
if (loop_flag)
|
|
|
|
{
|
|
|
|
vgmstream->loop_start_sample = loop_start_offset/16/channel_count*28;
|
|
|
|
vgmstream->loop_end_sample = loop_end_offset/16/channel_count*28;
|
|
|
|
}
|
2011-03-23 04:17:53 +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;
|
|
|
|
}
|