2009-09-15 08:22:01 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2010-10-03 11:34:44 +02:00
|
|
|
/* FSB3.0 and FSB3.1 */
|
2010-09-14 21:40:36 +02:00
|
|
|
|
2009-09-15 08:22:01 +02:00
|
|
|
VGMSTREAM * init_vgmstream_fsb3(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
int fsb_headerlen;
|
2010-04-20 22:26:10 +02:00
|
|
|
int channel_count;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int FSBFlag = 0;
|
|
|
|
int i, c;
|
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
|
|
|
|
2010-04-20 22:26:10 +02:00
|
|
|
if (strcasecmp("fsb",filename_extension(filename)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check header for "FSB3" string */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534233)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* "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 file */
|
|
|
|
if ((read_32bitBE(0x10,streamFile) != 0x00000300) &&
|
|
|
|
((read_32bitBE(0x10,streamFile) != 0x01000300)))
|
2009-09-15 08:22:01 +02:00
|
|
|
goto fail;
|
|
|
|
|
2010-04-20 22:26:10 +02:00
|
|
|
channel_count = read_16bitLE(0x56,streamFile);
|
|
|
|
fsb_headerlen = read_32bitLE(0x08,streamFile);
|
2009-10-06 19:30:04 +02:00
|
|
|
|
2010-04-20 22:26:10 +02:00
|
|
|
FSBFlag = read_32bitLE(0x48,streamFile);
|
2009-09-15 08:22:01 +02:00
|
|
|
|
2010-04-20 22:26:10 +02:00
|
|
|
if (FSBFlag&0x2 || FSBFlag&0x4 || FSBFlag&0x6)
|
|
|
|
loop_flag = 1;
|
|
|
|
|
2009-09-15 08:22:01 +02:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
start_offset = fsb_headerlen+0x18;
|
|
|
|
vgmstream->sample_rate = (read_32bitLE(0x4C, streamFile));
|
|
|
|
|
2010-09-14 21:40:36 +02:00
|
|
|
|
|
|
|
// Get the Decoder
|
|
|
|
if (FSBFlag&0x00000100)
|
|
|
|
{ // Ignore format and treat as RAW PCM
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
if (channel_count == 1)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
|
|
|
else if (channel_count > 1)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FSBFlag&0x00400000)
|
|
|
|
{ // XBOX IMA
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->coding_type = coding_XBOX;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
2010-09-14 21:40:36 +02:00
|
|
|
else if (FSBFlag&0x00800000)
|
|
|
|
{ // PS2 ADPCM
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
2010-09-14 21:40:36 +02:00
|
|
|
if (channel_count == 1)
|
|
|
|
{
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2010-09-14 21:40:36 +02:00
|
|
|
}
|
|
|
|
else if (channel_count > 1)
|
|
|
|
{
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
}
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
2010-09-14 21:40:36 +02:00
|
|
|
else if (FSBFlag&0x02000000)
|
|
|
|
{ // Nintendo DSP
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
2010-09-14 21:40:36 +02:00
|
|
|
if (channel_count == 1)
|
|
|
|
{
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2010-09-14 21:40:36 +02:00
|
|
|
}
|
|
|
|
else if (channel_count > 1)
|
|
|
|
{
|
2010-04-20 22:26:10 +02:00
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
|
|
|
vgmstream->interleave_block_size = 2;
|
|
|
|
}
|
2010-09-14 21:40:36 +02:00
|
|
|
// read coeff(s), DSP only
|
|
|
|
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);
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-20 22:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vgmstream->num_samples = read_32bitLE(0x38,streamFile);
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x40,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x44,streamFile);
|
2009-09-15 08:22:01 +02:00
|
|
|
}
|
2010-09-14 21:40:36 +02:00
|
|
|
|
2009-09-15 08:22:01 +02:00
|
|
|
|
2010-09-14 21:40:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-15 08:22:01 +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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|