2008-12-10 13:30:23 +01:00
|
|
|
#include "meta.h"
|
2008-12-10 21:54:10 +01:00
|
|
|
#include "../layout/layout.h"
|
2008-12-10 13:30:23 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* EMFF - Eidos Music File Format (PS2),
|
|
|
|
found in Tomb Raider Legend/Anniversary, Legacy of Kain - Defiance, possibly more... */
|
2008-12-15 05:37:43 +01:00
|
|
|
VGMSTREAM * init_vgmstream_emff_ps2(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
|
|
|
int frequency;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("emff",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* do some checks on the file, cause we have no magic words to check the header...
|
|
|
|
it seems if 0x800 and 0x804 = 0 then the file has only audio, if 0x800 = 1
|
|
|
|
it has a text section, if both are 1 it's video with a text section included... */
|
|
|
|
if (read_32bitBE(0x800,streamFile) == 0x01000000 || /* "0x01000000" */
|
|
|
|
read_32bitBE(0x804,streamFile) == 0x01000000) /* "0x01000000" */
|
|
|
|
goto fail;
|
2008-12-10 13:30:23 +01:00
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
frequency = read_32bitLE(0x0,streamFile);
|
2008-12-15 05:37:43 +01:00
|
|
|
channel_count = read_32bitLE(0xC,streamFile);
|
|
|
|
|
|
|
|
if (frequency > 48000 ||
|
|
|
|
channel_count > 8) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop_flag = (read_32bitLE(0x4,streamFile) != 0xFFFFFFFF);
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
start_offset = 0x800;
|
|
|
|
vgmstream->sample_rate = frequency;
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = (read_32bitLE(0x28,streamFile)-start_offset)*28/16/channel_count;
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x8,streamFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->layout_type = layout_emff_ps2_blocked;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
vgmstream->meta_type = meta_EMFF_PS2;
|
|
|
|
|
|
|
|
/* open the file for reading */
|
|
|
|
{
|
|
|
|
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-12-16 16:48:21 +01:00
|
|
|
|
2008-12-15 05:37:43 +01:00
|
|
|
/* Calc num_samples */
|
|
|
|
emff_ps2_block_update(start_offset,vgmstream);
|
|
|
|
vgmstream->num_samples=0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
vgmstream->num_samples += vgmstream->current_block_size*28/16;
|
|
|
|
emff_ps2_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
} while (vgmstream->next_block_offset<get_streamfile_size(streamFile));
|
|
|
|
|
|
|
|
emff_ps2_block_update(start_offset,vgmstream);
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* clean up anything we may have opened */
|
2008-12-15 05:37:43 +01:00
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* EMFF - Eidos Music File Format (NGC/WII),
|
|
|
|
found in Tomb Raider Legend/Anniversary, Legacy of Kain - Defiance, possibly more... */
|
2008-12-15 05:37:43 +01:00
|
|
|
VGMSTREAM * init_vgmstream_emff_ngc(STREAMFILE *streamFile) {
|
2008-12-10 13:30:23 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
|
|
|
off_t start_offset;
|
|
|
|
int loop_flag = 0;
|
|
|
|
int channel_count;
|
2008-12-15 05:37:43 +01:00
|
|
|
int frequency;
|
2008-12-10 13:30:23 +01:00
|
|
|
int i;
|
2008-12-15 05:37:43 +01:00
|
|
|
int j;
|
2008-12-16 16:48:21 +01:00
|
|
|
off_t coef_table1[8] = {0xC8,0xF6,0x124,0x152,0x180,0x1AE,0x1DC,0x20A};
|
|
|
|
off_t coef_table2[8] = {0x2D0,0x2FE,0x32C,0x35A,0x388,0x3B6,0x3E4,0x412};
|
2008-12-10 13:30:23 +01:00
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* check extension, case insensitive */
|
2008-12-10 13:30:23 +01:00
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("emff",filename_extension(filename))) goto fail;
|
|
|
|
|
2008-12-15 05:37:43 +01:00
|
|
|
/* do some checks on the file, cause we have no magic words to check the header...
|
|
|
|
it seems if 0x800 and 0x804 = 0 then the file has only audio, if 0x800 = 1
|
|
|
|
it has a text section, if both are 1 it's video with a text section included... */
|
|
|
|
if (read_32bitBE(0x800,streamFile) == 0x00000001 || /* "0x00000001" */
|
|
|
|
read_32bitBE(0x804,streamFile) == 0x00000001) /* "0x00000001" */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
frequency = read_32bitBE(0x0,streamFile);
|
|
|
|
channel_count = read_32bitBE(0xC,streamFile);
|
|
|
|
|
|
|
|
if (frequency > 48000 ||
|
|
|
|
channel_count > 8) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
loop_flag = (read_32bitBE(0x4,streamFile) != 0xFFFFFFFF);
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2008-12-10 13:30:23 +01:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
2008-12-15 05:37:43 +01:00
|
|
|
start_offset = 0x800;
|
|
|
|
vgmstream->sample_rate = frequency;
|
2008-12-10 13:30:23 +01:00
|
|
|
vgmstream->channels = channel_count;
|
2008-12-15 05:37:43 +01:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* Retrieving coefs and loops, depending on the file layout... */
|
|
|
|
if (read_32bitBE(0xC8,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xCC,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xD0,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xD4,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xD8,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xDC,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xE0,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0xE4,streamFile) == 0x0) {
|
|
|
|
|
|
|
|
for (j=0;j<vgmstream->channels;j++) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[j].adpcm_coef[i] = read_16bitBE(coef_table2[j]+i*2,streamFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = (read_32bitBE(0x28,streamFile))*14/8/channel_count;
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x8,streamFile);
|
|
|
|
}
|
|
|
|
} else if (read_32bitBE(0x2D0,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2D4,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2D8,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2DC,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2E0,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2E4,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2E8,streamFile) == 0x0 &&
|
|
|
|
read_32bitBE(0x2EC,streamFile) == 0x0) {
|
|
|
|
|
|
|
|
for (j=0;j<vgmstream->channels;j++) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[j].adpcm_coef[i] = read_16bitBE(coef_table1[j]+i*2,streamFile);
|
|
|
|
}
|
|
|
|
}
|
2008-12-15 05:37:43 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = (read_32bitBE(0x28,streamFile)-start_offset)*14/8/channel_count;
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x8,streamFile);
|
2008-12-16 16:48:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-12-10 13:30:23 +01:00
|
|
|
|
2008-12-15 05:37:43 +01:00
|
|
|
vgmstream->layout_type = layout_emff_ngc_blocked;
|
|
|
|
vgmstream->interleave_block_size = 0x10;
|
|
|
|
vgmstream->meta_type = meta_EMFF_NGC;
|
2008-12-10 13:30:23 +01:00
|
|
|
|
2008-12-15 05:37:43 +01:00
|
|
|
/* open the file for reading */
|
|
|
|
{
|
|
|
|
STREAMFILE * file;
|
|
|
|
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!file) goto fail;
|
2008-12-10 13:30:23 +01:00
|
|
|
for (i=0;i<channel_count;i++) {
|
2008-12-15 05:37:43 +01:00
|
|
|
vgmstream->ch[i].streamfile = file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-10 13:30:23 +01:00
|
|
|
/* Calc num_samples */
|
2008-12-15 05:37:43 +01:00
|
|
|
emff_ngc_block_update(start_offset,vgmstream);
|
2008-12-10 13:30:23 +01:00
|
|
|
vgmstream->num_samples=0;
|
|
|
|
|
|
|
|
do {
|
2008-12-15 05:37:43 +01:00
|
|
|
|
|
|
|
vgmstream->num_samples += vgmstream->current_block_size*14/8;
|
|
|
|
emff_ngc_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-12-10 13:30:23 +01:00
|
|
|
} while (vgmstream->next_block_offset<get_streamfile_size(streamFile));
|
|
|
|
|
2008-12-15 05:37:43 +01:00
|
|
|
emff_ngc_block_update(start_offset,vgmstream);
|
|
|
|
|
2008-12-10 13:30:23 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* clean up anything we may have opened */
|
2008-12-10 13:30:23 +01:00
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|