2008-07-14 13:02:39 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* comment from hcs:
|
|
|
|
((uint8_t)read_8bit(offset, file))&0xf for the low nibble,
|
|
|
|
((uint8_t)read_8bit(offset, file)) >> 4 for the high one
|
|
|
|
*/
|
2008-11-15 12:38:14 +01:00
|
|
|
/* FSB1 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb1(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
/* int fsb1_included_files; */
|
|
|
|
int fsb1_format;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* "Check if the FSB is used as
|
|
|
|
conatiner or as single file" */
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0x01000000)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = 2;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
start_offset = 0x50;
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x38,streamFile);
|
|
|
|
vgmstream->meta_type = meta_FSB1;
|
|
|
|
|
|
|
|
|
|
|
|
/* open the file for reading */
|
2008-11-24 19:27:28 +01:00
|
|
|
{
|
2008-11-15 12:38:14 +01:00
|
|
|
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;
|
2008-11-24 19:27:28 +01:00
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=start_offset+
|
|
|
|
vgmstream->interleave_block_size*i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-11-15 12:38:14 +01:00
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FSB3 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb3(STREAMFILE *streamFile) {
|
2008-07-14 13:02:39 +02:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
|
2008-07-15 19:08:39 +02:00
|
|
|
/* int fsb3_included_files; */
|
2008-07-14 13:02:39 +02:00
|
|
|
int fsb3_headerlen = 0x18;
|
2008-07-14 18:07:23 +02:00
|
|
|
int fsb3_format;
|
2008-07-14 13:02:39 +02:00
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("fsb",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
2008-07-14 18:07:23 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x46534233) /* "FSB3" */
|
2008-07-14 13:02:39 +02:00
|
|
|
goto fail;
|
2008-07-15 19:08:39 +02:00
|
|
|
|
|
|
|
/* "Check if the FSB is used as
|
|
|
|
conatiner or as single file" */
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0x01000000)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
2008-07-14 13:02:39 +02:00
|
|
|
|
2008-07-15 19:08:39 +02:00
|
|
|
if (read_32bitBE(0x48,streamFile) == 0x02000806) {
|
2008-07-14 15:30:26 +02:00
|
|
|
loop_flag = 1;
|
|
|
|
} else {
|
|
|
|
loop_flag = 0; /* (read_32bitLE(0x08,streamFile)!=0); */
|
|
|
|
}
|
2008-07-14 13:02:39 +02:00
|
|
|
|
2008-07-15 19:08:39 +02:00
|
|
|
/* Channel check
|
|
|
|
if (read_16bitLE(0x56,streamFile) == 2) {
|
|
|
|
channel_count = 2;
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
channel_count = read_16bitLE(0x56,streamFile);
|
|
|
|
|
|
|
|
|
2008-07-14 13:02:39 +02:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2008-07-14 14:31:19 +02:00
|
|
|
/* This will be tricky ;o) */
|
|
|
|
fsb3_format = read_32bitBE(0x48,streamFile);
|
|
|
|
switch (fsb3_format) {
|
|
|
|
case 0x40008800: /* PS2 (Agent Hugo, Flat Out 2) */
|
|
|
|
case 0x41008800: /* PS2 (Flat Out) */
|
2008-07-14 18:07:23 +02:00
|
|
|
case 0x42008800: /* PS2 (Jackass - The Game) */
|
2008-07-15 19:08:39 +02:00
|
|
|
case 0x01008804: /* PS2 (Cold Fear) */
|
2008-11-27 22:08:48 +01:00
|
|
|
case 0x02008804: /* PS2 (Shrek - Smash 'n Crash */
|
2008-07-14 14:31:19 +02:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2008-07-14 18:07:23 +02:00
|
|
|
vgmstream->interleave_block_size = 0x10;
|
2008-07-14 14:31:19 +02:00
|
|
|
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile))*28/16/channel_count;
|
|
|
|
if (loop_flag) {
|
2008-07-15 05:39:20 +02:00
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x40,streamFile);
|
2008-07-14 14:31:19 +02:00
|
|
|
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile))*28/16/channel_count;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-14 18:07:23 +02:00
|
|
|
case 0x02000806: /* WII (Metroid Prime 3) */
|
|
|
|
case 0x01000806: /* WII (Metroid Prime 3) */
|
|
|
|
case 0x40000802: /* WII (WWE Smackdown Vs. Raw 2008) */
|
2008-11-15 03:23:15 +01:00
|
|
|
case 0x40000882: /* WII (Bully) */
|
2008-10-28 21:14:42 +01:00
|
|
|
case 0x41000802: /* GC (Dysney's Incredibles, The) */
|
2008-07-14 14:31:19 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave_byte;
|
2008-07-14 15:30:26 +02:00
|
|
|
vgmstream->interleave_block_size = 2;
|
2008-07-15 05:39:20 +02:00
|
|
|
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile))*14/8/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x40,streamFile);
|
|
|
|
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile))*14/8/channel_count;
|
|
|
|
}
|
2008-07-14 14:31:19 +02:00
|
|
|
break;
|
2008-07-15 02:30:49 +02:00
|
|
|
case 0x40004020: /* WII (Guitar Hero III), uses Xbox-ish IMA */
|
|
|
|
case 0x400040A0: /* WII (Guitar Hero III), uses Xbox-ish IMA */
|
2008-07-15 19:08:39 +02:00
|
|
|
case 0x41004800: /* XBOX (FlatOut, Rainbow Six - Lockdown) */
|
2008-07-17 03:22:23 +02:00
|
|
|
case 0x01004804: /* XBOX (Cold Fear) <- maybe IMA??? */
|
2008-07-14 18:07:23 +02:00
|
|
|
vgmstream->coding_type = coding_XBOX;
|
2008-08-10 22:08:03 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2008-07-15 05:39:20 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x0C,streamFile)*64/36/channel_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x40,streamFile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x0C,streamFile)*64/36/channel_count;
|
|
|
|
}
|
2008-07-14 14:31:19 +02:00
|
|
|
break;
|
2008-07-14 18:07:23 +02:00
|
|
|
default:
|
2008-07-14 14:31:19 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-07-14 13:02:39 +02:00
|
|
|
/* fill in the vital statistics */
|
2008-07-14 15:30:26 +02:00
|
|
|
start_offset = (read_32bitLE(0x08,streamFile))+fsb3_headerlen;
|
2008-07-15 19:08:39 +02:00
|
|
|
vgmstream->channels = channel_count;
|
2008-07-14 13:02:39 +02:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x4C,streamFile);
|
2008-07-14 18:20:47 +02:00
|
|
|
vgmstream->meta_type = meta_FSB3;
|
2008-07-14 13:02:39 +02:00
|
|
|
|
2008-07-14 15:30:26 +02:00
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
|
|
|
int i;
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(0x68+i*2,streamFile);
|
|
|
|
}
|
|
|
|
if (vgmstream->channels) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(0x96+i*2,streamFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-14 13:02:39 +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;
|
|
|
|
|
2008-07-14 18:27:29 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2008-07-14 18:34:55 +02:00
|
|
|
vgmstream->ch[i].offset = vgmstream->ch[i].channel_start_offset;
|
2008-07-14 13:02:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-24 19:27:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FSB4 */
|
|
|
|
VGMSTREAM * init_vgmstream_fsb4(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
/* int fsb1_included_files; */
|
|
|
|
int fsb4_format;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
if (read_32bitBE(0x60,streamFile) == 0x40008800) {
|
|
|
|
loop_flag = 1;
|
|
|
|
} else {
|
|
|
|
loop_flag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
channel_count = 2;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
start_offset = 0x80;
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x64,streamFile);
|
|
|
|
fsb4_format = read_32bitBE(0x60,streamFile);
|
|
|
|
switch (fsb4_format) {
|
|
|
|
/* PS2 (Spider Man - Web of Shadows), Speed Racer */
|
|
|
|
case 0x40008800:
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->meta_type = meta_FSB4;
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|