2008-06-09 02:20:08 +02:00
|
|
|
#include "meta.h"
|
2008-06-10 03:20:54 +02:00
|
|
|
#include "../layout/layout.h"
|
2008-06-09 02:20:08 +02:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* GENH is an artificial "generic" header for headerless streams */
|
|
|
|
|
2008-06-10 03:20:54 +02:00
|
|
|
VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
2008-06-09 02:20:08 +02:00
|
|
|
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
|
|
|
|
int32_t channel_count;
|
|
|
|
int32_t interleave;
|
|
|
|
int32_t sample_rate;
|
|
|
|
int32_t loop_start;
|
|
|
|
int32_t loop_end;
|
2008-06-13 01:33:07 +02:00
|
|
|
int32_t start_offset;
|
|
|
|
int32_t header_size;
|
2008-06-09 02:20:08 +02:00
|
|
|
char filename[260];
|
2008-06-10 03:20:54 +02:00
|
|
|
int coding;
|
2008-06-09 02:20:08 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("genh",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header magic */
|
|
|
|
if (read_32bitBE(0x0,streamFile) != 0x47454e48) goto fail;
|
|
|
|
|
2008-06-13 01:50:45 +02:00
|
|
|
/* check channel count (needed for ADP/DTK check) */
|
|
|
|
channel_count = read_32bitLE(0x4,streamFile);
|
|
|
|
if (channel_count < 1) goto fail;
|
|
|
|
|
2008-06-10 03:20:54 +02:00
|
|
|
/* check format */
|
|
|
|
/* 0 = PSX ADPCM */
|
2008-06-13 01:33:07 +02:00
|
|
|
/* 1 = XBOX IMA ADPCM */
|
|
|
|
/* 2 = NGC ADP/DTK ADPCM */
|
2008-06-10 03:20:54 +02:00
|
|
|
/* ... others to come */
|
|
|
|
switch (read_32bitLE(0x18,streamFile)) {
|
|
|
|
case 0:
|
|
|
|
coding = coding_PSX;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
coding = coding_XBOX;
|
|
|
|
break;
|
2008-06-13 01:33:07 +02:00
|
|
|
case 2:
|
|
|
|
coding = coding_NGC_DTK;
|
|
|
|
if (channel_count != 2) goto fail;
|
|
|
|
break;
|
2008-06-10 03:20:54 +02:00
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-06-09 02:20:08 +02:00
|
|
|
|
2008-06-13 01:50:45 +02:00
|
|
|
start_offset = read_32bitLE(0x1c,streamFile);
|
|
|
|
header_size = read_32bitLE(0x20,streamFile);
|
2008-06-13 01:33:07 +02:00
|
|
|
|
|
|
|
/* HACK to support old genh */
|
|
|
|
if (header_size == 0) {
|
|
|
|
start_offset = 0x800;
|
|
|
|
header_size = 0x800;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for audio data start past header end */
|
|
|
|
if (header_size > start_offset) goto fail;
|
|
|
|
|
2008-06-09 02:20:08 +02:00
|
|
|
interleave = read_32bitLE(0x8,streamFile);
|
|
|
|
sample_rate = read_32bitLE(0xc,streamFile);
|
|
|
|
loop_start = read_32bitLE(0x10,streamFile);
|
|
|
|
loop_end = read_32bitLE(0x14,streamFile);
|
|
|
|
|
2008-06-10 03:20:54 +02:00
|
|
|
if (coding == coding_XBOX && channel_count != 2) goto fail;
|
|
|
|
|
2008-06-09 02:20:08 +02:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,(loop_start!=-1));
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital information */
|
|
|
|
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
vgmstream->num_samples = loop_end;
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
vgmstream->loop_end_sample = loop_end;
|
|
|
|
vgmstream->loop_flag = (loop_start != -1);
|
|
|
|
|
2008-06-10 03:20:54 +02:00
|
|
|
vgmstream->coding_type = coding;
|
|
|
|
switch (coding) {
|
|
|
|
case coding_PSX:
|
|
|
|
vgmstream->interleave_block_size = interleave;
|
|
|
|
if (channel_count > 1)
|
|
|
|
{
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
} else {
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_XBOX:
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 36;
|
|
|
|
|
2008-06-13 01:33:07 +02:00
|
|
|
break;
|
|
|
|
case coding_NGC_DTK:
|
|
|
|
vgmstream->layout_type = layout_dtk_interleave;
|
2008-06-10 03:20:54 +02:00
|
|
|
break;
|
2008-06-09 12:26:17 +02:00
|
|
|
}
|
2008-06-09 02:20:08 +02:00
|
|
|
|
2008-06-10 03:20:54 +02:00
|
|
|
vgmstream->meta_type = meta_GENH;
|
2008-06-09 02:20:08 +02:00
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
int i;
|
2008-06-13 01:33:07 +02:00
|
|
|
STREAMFILE * chstreamfile = NULL;
|
|
|
|
|
2008-06-09 02:20:08 +02:00
|
|
|
for (i=0;i<channel_count;i++) {
|
2008-06-13 01:33:07 +02:00
|
|
|
off_t chstart_offset = start_offset;
|
|
|
|
|
|
|
|
switch (coding) {
|
|
|
|
case coding_PSX:
|
|
|
|
if (vgmstream->layout_type == layout_interleave) {
|
|
|
|
chstreamfile =
|
|
|
|
streamFile->open(streamFile,filename,interleave);
|
|
|
|
chstart_offset =
|
|
|
|
start_offset+vgmstream->interleave_block_size*i;
|
|
|
|
} else {
|
|
|
|
chstreamfile =
|
|
|
|
streamFile->open(streamFile,filename,
|
|
|
|
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_XBOX:
|
|
|
|
/* xbox's "interleave" is a lie, all channels start at same
|
|
|
|
* offset */
|
|
|
|
chstreamfile =
|
|
|
|
streamFile->open(streamFile,filename,
|
|
|
|
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
break;
|
|
|
|
case coding_NGC_DTK:
|
|
|
|
if (!chstreamfile)
|
|
|
|
chstreamfile =
|
|
|
|
streamFile->open(streamFile,filename,32*0x400);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chstreamfile) goto fail;
|
2008-06-09 02:20:08 +02:00
|
|
|
|
2008-06-13 01:33:07 +02:00
|
|
|
vgmstream->ch[i].streamfile = chstreamfile;
|
2008-06-09 02:20:08 +02:00
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
2008-06-14 01:01:12 +02:00
|
|
|
vgmstream->ch[i].offset=chstart_offset;
|
2008-06-09 02:20:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|