2009-09-15 08:22:01 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2010-02-15 10:02:31 +01:00
|
|
|
/* FSB3.0 & FSB3.1*/
|
2009-09-15 08:22:01 +02:00
|
|
|
VGMSTREAM * init_vgmstream_fsb3(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
int fsb_headerlen;
|
2010-02-15 10:02:31 +01:00
|
|
|
int loop_flag;
|
|
|
|
int channel_count;
|
2009-09-15 08:22:01 +02:00
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2010-02-15 10:02:31 +01:00
|
|
|
if (strcasecmp("fsb",filename_extension(filename)) &&
|
|
|
|
strcasecmp("lfsb",filename_extension(filename)))
|
|
|
|
goto fail;
|
2009-09-15 08:22:01 +02:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534233) goto fail; /* "FSB3" */
|
2010-02-15 10:02:31 +01:00
|
|
|
|
|
|
|
/* "Check if the FSB is used as conatiner or as single file" */
|
|
|
|
if (read_32bitLE(0x04,streamFile) != 0x1) goto fail;
|
|
|
|
|
|
|
|
/* Check if we're dealing with a FSB3.0 or FSB3.1 file */
|
2009-09-15 08:22:01 +02:00
|
|
|
if ((read_32bitBE(0x10,streamFile) != 0x00000300) &&
|
|
|
|
(read_32bitBE(0x10,streamFile) != 0x01000300))
|
|
|
|
goto fail;
|
|
|
|
|
2010-02-15 10:02:31 +01:00
|
|
|
if (read_32bitBE(0x48,streamFile) == 0x02000806) { // Metroid Prime 3
|
2009-10-06 19:30:04 +02:00
|
|
|
loop_flag = 1;
|
|
|
|
} else {
|
2010-02-15 10:02:31 +01:00
|
|
|
loop_flag = 0;
|
2009-10-06 19:30:04 +02:00
|
|
|
}
|
|
|
|
|
2009-09-15 08:22:01 +02:00
|
|
|
channel_count = read_16bitLE(0x56,streamFile);
|
|
|
|
fsb_headerlen = read_32bitLE(0x08,streamFile);
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
// fsb_format = ;
|
2010-02-15 10:02:31 +01:00
|
|
|
switch (((uint8_t)read_8bit(0x4A, streamFile)) >> 4) {
|
2009-09-15 08:22:01 +02:00
|
|
|
case 0x0: // Nintendo DSP
|
2010-02-15 10:02:31 +01:00
|
|
|
// Hack to support an illegal coding flag
|
|
|
|
if (read_32bitBE(0x48,streamFile) == 0x50010000) { // Fantastic 4: Rise of the Silver Surfer
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile))/2/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile))/2/channel_count;
|
|
|
|
}
|
|
|
|
if (channel_count == 1) {
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
} else if (channel_count > 1) {
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile))*14/8/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile))*14/8/channel_count;
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
2010-02-15 10:02:31 +01:00
|
|
|
if (channel_count == 1) {
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
} else if (channel_count > 1) {
|
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
|
|
|
vgmstream->interleave_block_size = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-09-15 08:22:01 +02:00
|
|
|
case 0x4: // XBOX IMA ADPCM
|
2010-02-15 10:02:31 +01:00
|
|
|
vgmstream->coding_type = coding_XBOX;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->num_samples = read_32bitLE(0x0C,streamFile)*64/36/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x0C,streamFile)*64/36/channel_count;
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
2010-02-15 10:02:31 +01:00
|
|
|
break;
|
2009-09-15 08:22:01 +02:00
|
|
|
case 0x8: // PS2 APDCM
|
2010-02-15 10:02:31 +01:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile))*28/16/channel_count;
|
2009-09-15 08:22:01 +02:00
|
|
|
if (loop_flag) {
|
2010-02-15 10:02:31 +01:00
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile))*28/16/channel_count;
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
2010-02-15 10:02:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
2009-09-15 08:22:01 +02:00
|
|
|
start_offset = fsb_headerlen+0x18;
|
|
|
|
vgmstream->sample_rate = (read_32bitLE(0x4C, streamFile));
|
|
|
|
|
|
|
|
if (read_32bitBE(0x10,streamFile) == 0x00000300) {
|
|
|
|
vgmstream->meta_type = meta_FSB3_0;
|
|
|
|
} else if (read_32bitBE(0x10,streamFile) == 0x01000300) {
|
|
|
|
vgmstream->meta_type = meta_FSB3_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
|
|
|
int i,c;
|
|
|
|
for (c=0;c<channel_count;c++) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[c].adpcm_coef[i] =
|
|
|
|
read_16bitBE(0x68+c*0x2e +i*2,streamFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (vgmstream->coding_type == coding_XBOX) {
|
|
|
|
/* xbox interleaving is a little odd */
|
|
|
|
vgmstream->ch[i].channel_start_offset=start_offset;
|
|
|
|
} else {
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
start_offset+vgmstream->interleave_block_size*i;
|
|
|
|
}
|
|
|
|
vgmstream->ch[i].offset = vgmstream->ch[i].channel_start_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|