2008-12-18 07:51:26 +01:00
|
|
|
#include "meta.h"
|
2010-09-15 21:37:54 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-12-18 07:51:26 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* FSB1 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb1(STREAMFILE *streamFile) {
|
2009-09-15 08:22:01 +02:00
|
|
|
|
2008-12-18 07:51:26 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* int fsb1_included_files; */
|
|
|
|
int fsb1_format;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("fsb",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534231) /* "FSB1" */
|
|
|
|
goto fail;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* "Check if the FSB is used as
|
|
|
|
conatiner or as single file" */
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0x01000000)
|
|
|
|
goto fail;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = 2;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* build the VGMSTREAM */
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* This will be tricky ;o) */
|
|
|
|
fsb1_format = read_32bitBE(0x44,streamFile);
|
|
|
|
switch (fsb1_format) {
|
|
|
|
case 0x40008800: /* PS2 (Operation Genesis) */
|
|
|
|
case 0x41008800: /* PS2 (Operation Genesis) */
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x34,streamFile))*28/16/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x30,streamFile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
}
|
|
|
|
/* fill in the vital statistics */
|
2008-12-18 07:51:26 +01:00
|
|
|
start_offset = 0x50;
|
2009-12-19 23:30:14 +01:00
|
|
|
vgmstream->channels = channel_count;
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x38,streamFile);
|
|
|
|
vgmstream->meta_type = meta_FSB1;
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2011-02-08 13:56:16 +01:00
|
|
|
/* FSB3.0 and FSB3.1 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb3(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
int fsb_headerlen;
|
|
|
|
int channel_count;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int FSBFlag = 0;
|
|
|
|
int i, c;
|
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
|
|
|
|
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)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
channel_count = read_16bitLE(0x56,streamFile);
|
|
|
|
fsb_headerlen = read_32bitLE(0x08,streamFile);
|
|
|
|
|
|
|
|
FSBFlag = read_32bitLE(0x48,streamFile);
|
|
|
|
|
|
|
|
if (FSBFlag&0x2 || FSBFlag&0x4 || FSBFlag&0x6)
|
|
|
|
loop_flag = 1;
|
|
|
|
|
|
|
|
/* 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));
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
vgmstream->coding_type = coding_XBOX;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
|
|
|
else if (FSBFlag&0x00800000)
|
|
|
|
{ // PS2 ADPCM
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
if (channel_count == 1)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
|
|
|
else if (channel_count > 1)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FSBFlag&0x02000000)
|
|
|
|
{ // Nintendo DSP
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2008-12-18 07:51:26 +01:00
|
|
|
|
|
|
|
/* FSB4 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb4(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
int fsb4_format;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2009-05-13 22:18:30 +02:00
|
|
|
if (strcasecmp("fsb",filename_extension(filename)) &&
|
|
|
|
strcasecmp("wii",filename_extension(filename))) goto fail;
|
2008-12-18 07:51:26 +01:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534234) /* "FSB4" */
|
|
|
|
goto fail;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* "Check if the FSB is used as
|
|
|
|
conatiner or as single file" */
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0x01000000)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (read_32bitBE(0x60,streamFile) == 0x40008800 ||
|
2009-05-13 00:15:22 +02:00
|
|
|
read_32bitBE(0x60,streamFile) == 0x40000802 ||
|
2010-10-21 20:10:58 +02:00
|
|
|
read_32bitBE(0x60,streamFile) == 0x40100802 ||
|
|
|
|
read_32bitBE(0x60,streamFile) == 0x40004020) {
|
2009-12-19 23:30:14 +01:00
|
|
|
loop_flag = 1;
|
|
|
|
} else {
|
|
|
|
loop_flag = 0;
|
|
|
|
}
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2010-02-27 23:10:52 +01:00
|
|
|
#if 0
|
2009-05-13 00:15:22 +02:00
|
|
|
if (read_32bitBE(0x60,streamFile) != 0x20000882 &&
|
2009-05-13 00:59:14 +02:00
|
|
|
read_32bitBE(0x60,streamFile) != 0x20100002 &&
|
2009-05-13 01:39:45 +02:00
|
|
|
read_32bitBE(0x60,streamFile) != 0x20100882 &&
|
2009-05-13 01:19:24 +02:00
|
|
|
read_32bitBE(0x60,streamFile) != 0x20100802 &&
|
|
|
|
read_32bitBE(0x60,streamFile) != 0x20100082 &&
|
2009-05-13 00:59:14 +02:00
|
|
|
read_32bitBE(0x60,streamFile) != 0x20000802) {
|
2009-05-13 00:15:22 +02:00
|
|
|
channel_count = 2;
|
|
|
|
} else {
|
|
|
|
channel_count = 1;
|
|
|
|
}
|
2010-02-27 23:10:52 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
channel_count = (uint16_t)read_16bitLE(0x6E,streamFile);
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* build the VGMSTREAM */
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
2009-12-19 23:30:14 +01:00
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
vgmstream->channels = channel_count;
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x64,streamFile);
|
2009-12-19 23:30:14 +01:00
|
|
|
fsb4_format = read_32bitBE(0x60,streamFile);
|
|
|
|
switch (fsb4_format) {
|
2010-10-21 20:10:58 +02:00
|
|
|
/* PC Blade Kitten */
|
|
|
|
case 0x40004020:
|
2010-10-21 22:22:52 +02:00
|
|
|
case 0x20004000:
|
2010-10-21 20:10:58 +02:00
|
|
|
vgmstream->coding_type = coding_MS_IMA;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->interleave_block_size = 0x24*vgmstream->channels;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x54,streamFile)/0x24/vgmstream->channels)*((0x24-4)*2);
|
|
|
|
//vgmstream->num_samples = read_32bitLE(0x50,streamFile);
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x58,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x5C,streamFile);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-19 23:30:14 +01:00
|
|
|
/* PS2 (Spider Man - Web of Shadows), Speed Racer */
|
|
|
|
case 0x40008800:
|
2010-02-15 10:02:31 +01:00
|
|
|
case 0x20008800: // Silent Hill: Shattered Memories
|
2009-12-19 23:30:14 +01:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x54,streamFile))*28/16/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x50,streamFile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* WII (de Blob, Night at the Museum) */
|
2009-01-28 03:50:28 +01:00
|
|
|
case 0x40000802:
|
2009-05-13 00:59:14 +02:00
|
|
|
case 0x40000882:
|
2009-05-13 00:15:22 +02:00
|
|
|
case 0x40100802:
|
2009-12-19 23:30:14 +01:00
|
|
|
case 0x40200802:
|
2011-06-21 04:34:31 +02:00
|
|
|
case 0x00000802:
|
2010-08-13 16:08:00 +02:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x50,streamFile);
|
|
|
|
}
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
if (read_32bitLE(0x14,streamFile)==0x20 ||
|
|
|
|
read_32bitLE(0x14,streamFile)==0x00)
|
|
|
|
{
|
|
|
|
/* Night at the Museum */
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
|
|
|
vgmstream->interleave_block_size = 2;
|
|
|
|
}
|
|
|
|
else if (read_32bitLE(0x14,streamFile)==0x10 ||
|
|
|
|
read_32bitLE(0x14,streamFile)==0x30)
|
|
|
|
{
|
|
|
|
/* de Blob, NatM sfx */
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x54,streamFile)/channel_count;
|
|
|
|
}
|
2010-08-13 16:08:00 +02:00
|
|
|
else if (read_32bitLE(0x14,streamFile)==0x40) {
|
|
|
|
/* M. Night Shamylan The Last Airbender */
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
|
|
|
vgmstream->interleave_block_size = 2;
|
|
|
|
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x58,streamFile);
|
|
|
|
}
|
|
|
|
}
|
2009-12-19 23:30:14 +01:00
|
|
|
else goto fail;
|
|
|
|
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x54,streamFile)/8/channel_count*14);
|
|
|
|
break;
|
|
|
|
|
2009-05-13 00:15:22 +02:00
|
|
|
/* Night at the Museum */
|
|
|
|
case 0x20000882:
|
2009-05-13 00:59:14 +02:00
|
|
|
case 0x20000802:
|
2009-05-13 00:15:22 +02:00
|
|
|
case 0x20100002:
|
2009-05-13 01:39:45 +02:00
|
|
|
case 0x20100882:
|
2009-05-13 01:19:24 +02:00
|
|
|
case 0x20100802:
|
|
|
|
case 0x20100082:
|
2009-05-13 00:15:22 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->num_samples = (read_32bitLE(0x54,streamFile)/8/channel_count*14);
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x50,streamFile);
|
|
|
|
}
|
|
|
|
break;
|
2010-05-31 04:55:41 +02:00
|
|
|
|
|
|
|
/* Rocket Knight (PC) */
|
|
|
|
case 0x50210000:
|
2010-06-01 06:19:06 +02:00
|
|
|
case 0x30210000:
|
|
|
|
case 0x30011000:
|
|
|
|
case 0x20005000:
|
|
|
|
case 0x30011080:
|
|
|
|
case 0x30211000:
|
|
|
|
case 0x40005020:
|
|
|
|
case 0x20204000:
|
|
|
|
case 0x40204020:
|
|
|
|
case 0x50011000:
|
|
|
|
case 0x20205000:
|
2010-06-29 17:52:07 +02:00
|
|
|
case 0x30610080:
|
2010-09-20 01:11:49 +02:00
|
|
|
case 0x50210080: /* Another Century's Episode R (PS3) */
|
2010-09-24 01:52:16 +02:00
|
|
|
case 0x50010800: /* Toy Story 3 (PS3) */
|
2010-05-31 04:55:41 +02:00
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x2;
|
2010-06-14 03:41:28 +02:00
|
|
|
vgmstream->num_samples = (read_32bitLE(0x5C,streamFile));
|
2010-05-31 04:55:41 +02:00
|
|
|
if (loop_flag) {
|
2010-06-14 03:41:28 +02:00
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x58,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x5C,streamFile);
|
2010-05-31 04:55:41 +02:00
|
|
|
}
|
|
|
|
break;
|
2009-12-19 23:30:14 +01:00
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-12-18 07:51:26 +01:00
|
|
|
|
2009-05-12 23:21:24 +02:00
|
|
|
start_offset = read_32bitLE(0x08,streamFile)+0x30;
|
|
|
|
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream->meta_type = meta_FSB4;
|
|
|
|
|
2009-01-28 03:50:28 +01:00
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
|
|
|
int c,i;
|
|
|
|
for (c=0;c<channel_count;c++) {
|
|
|
|
for (i=0;i<16;i++)
|
|
|
|
{
|
|
|
|
vgmstream->ch[c].adpcm_coef[i] =
|
|
|
|
read_16bitBE(0x80+c*0x2e + i*2,streamFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-18 07:51:26 +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;
|
|
|
|
|
2010-10-21 20:36:14 +02:00
|
|
|
|
|
|
|
if (vgmstream->coding_type == coding_MS_IMA) {
|
|
|
|
// both IMA channels work with same bytes
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=start_offset;
|
|
|
|
} else {
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
2008-12-18 07:51:26 +01:00
|
|
|
vgmstream->ch[i].offset=start_offset+
|
|
|
|
vgmstream->interleave_block_size*i;
|
2010-10-21 20:36:14 +02:00
|
|
|
}
|
2008-12-18 07:51:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-05 22:27:50 +01:00
|
|
|
|
2009-03-30 00:50:51 +02:00
|
|
|
/* FSB4 with "WAV" Header, found in "Deadly Creatures (WII)"
|
|
|
|
16 byte "WAV" header which holds the filesize...*/
|
2009-03-05 22:27:50 +01:00
|
|
|
VGMSTREAM * init_vgmstream_fsb4_wav(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
2009-12-19 23:30:14 +01:00
|
|
|
int loop_flag;
|
|
|
|
int channel_count;
|
2009-03-30 00:50:51 +02:00
|
|
|
int fsb_headerlength;
|
2009-03-05 22:27:50 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("fsb",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
2009-03-30 00:50:51 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x00574156) /* 0x0\"WAV" */
|
2009-03-05 22:27:50 +01:00
|
|
|
goto fail;
|
2009-03-30 00:50:51 +02:00
|
|
|
if (read_32bitBE(0x10,streamFile) != 0x46534234) /* "FSB4" */
|
2009-03-05 22:27:50 +01:00
|
|
|
goto fail;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
channel_count = (uint16_t)read_16bitLE(0x7E,streamFile);
|
2009-03-30 00:50:51 +02:00
|
|
|
|
|
|
|
if (channel_count > 2) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop_flag = (read_32bitBE(0x70,streamFile) == 0x40000802);
|
|
|
|
fsb_headerlength = read_32bitLE(0x18,streamFile);
|
2009-03-05 22:27:50 +01:00
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* build the VGMSTREAM */
|
2009-03-05 22:27:50 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2009-12-19 23:30:14 +01:00
|
|
|
/* fill in the vital statistics */
|
2009-03-30 00:50:51 +02:00
|
|
|
start_offset = fsb_headerlength + 0x40;
|
2009-12-19 23:30:14 +01:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x74,streamFile);
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
2009-03-05 22:27:50 +01:00
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
|
|
|
vgmstream->interleave_block_size = 0x2;
|
2009-03-30 00:50:51 +02:00
|
|
|
vgmstream->num_samples = (read_32bitLE(0x64,streamFile)/8/channel_count*14);
|
2009-03-05 22:27:50 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
2009-03-30 00:50:51 +02:00
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x60,streamFile);
|
2009-12-19 23:30:14 +01:00
|
|
|
}
|
2009-03-05 22:27:50 +01:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_FSB4_WAV;
|
|
|
|
|
2009-03-12 10:27:11 +01:00
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
|
|
|
int i;
|
|
|
|
for (i=0;i<16;i++) {
|
2009-03-30 00:50:51 +02:00
|
|
|
vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(0x90+i*2,streamFile);
|
2009-03-12 10:27:11 +01:00
|
|
|
}
|
|
|
|
if (vgmstream->channels == 2) {
|
|
|
|
for (i=0;i<16;i++) {
|
2009-04-03 03:16:57 +02:00
|
|
|
vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(0xBE + i*2,streamFile);
|
2009-03-12 10:27:11 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-05 22:27:50 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-15 21:37:54 +02:00
|
|
|
// FSB MPEG TEST
|
|
|
|
VGMSTREAM * init_vgmstream_fsb_mpeg(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
int channel_count;
|
|
|
|
int loop_flag;
|
|
|
|
long sample_rate = 0;
|
|
|
|
long num_samples = 0;
|
|
|
|
uint8_t mp3ID;
|
|
|
|
long rate;
|
|
|
|
int channels,encoding;
|
|
|
|
// int FSBFlag;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
mpeg_codec_data *mpeg_data = NULL;
|
|
|
|
coding_t mpeg_coding_type = coding_MPEG1_L3;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("fsb",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534234) /* "FSB4" */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* "Check if the FSB is used as conatiner or as single file" */
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0x01000000)
|
2010-09-16 13:53:36 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Check channel count, multi-channel not supported and will be refused */
|
2010-09-20 01:11:49 +02:00
|
|
|
if ((read_16bitLE(0x6E,streamFile) != 0x2) &&
|
|
|
|
(read_16bitLE(0x6E,streamFile) != 0x1))
|
2010-09-15 21:37:54 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
start_offset = read_32bitLE(0x08,streamFile)+0x30; //read_32bitBE(0x4,streamFile);
|
|
|
|
mp3ID = read_8bit(start_offset,streamFile);
|
|
|
|
if (mp3ID != 0xFF)
|
|
|
|
goto fail;
|
2010-09-16 19:29:45 +02:00
|
|
|
|
|
|
|
/* Still WIP */
|
|
|
|
if (read_32bitBE(0x80,streamFile)==0x53594E43)
|
|
|
|
loop_flag = 1;
|
|
|
|
else
|
|
|
|
loop_flag = 0;
|
2010-09-15 21:37:54 +02:00
|
|
|
|
|
|
|
num_samples = (read_32bitLE(0x5C,streamFile));
|
|
|
|
|
|
|
|
#ifdef VGM_USE_MPEG
|
2011-01-19 14:54:59 +01:00
|
|
|
mpeg_data = init_mpeg_codec_data(streamFile, start_offset, -1, -1, &mpeg_coding_type, &rate, &channels); // -1 to not check sample rate or channels
|
2010-09-15 21:37:54 +02:00
|
|
|
if (!mpeg_data) goto fail;
|
|
|
|
|
|
|
|
channel_count = channels;
|
|
|
|
sample_rate = rate;
|
|
|
|
|
|
|
|
#else
|
|
|
|
// reject if no MPEG support
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
vgmstream->num_samples = num_samples;
|
|
|
|
vgmstream->channels = channel_count;
|
2010-09-16 19:29:45 +02:00
|
|
|
|
|
|
|
/* Still WIP */
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x58,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x5c,streamFile);
|
|
|
|
}
|
2010-09-15 21:37:54 +02:00
|
|
|
vgmstream->meta_type = meta_FSB_MPEG;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
/* NOTE: num_samples seems to be quite wrong for MPEG */
|
|
|
|
vgmstream->codec_data = mpeg_data;
|
|
|
|
vgmstream->layout_type = layout_mpeg;
|
|
|
|
vgmstream->coding_type = mpeg_coding_type;
|
|
|
|
#else
|
|
|
|
// reject if no MPEG support
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x18,streamFile)/960*1152;
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x1C,streamFile)/960*1152;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* open the file for reading */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
STREAMFILE * file;
|
|
|
|
if(vgmstream->layout_type == layout_interleave)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
else if(vgmstream->layout_type == layout_mpeg) {
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,MPEG_BUFFER_SIZE);
|
|
|
|
vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset=start_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else { goto fail; }
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
if (mpeg_data) {
|
|
|
|
mpg123_delete(mpeg_data->m);
|
|
|
|
free(mpeg_data);
|
|
|
|
|
|
|
|
if (vgmstream) {
|
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|