2008-11-28 15:27:51 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/*
|
|
|
|
ISH+ISD
|
2008-11-28 15:27:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
VGMSTREAM * init_vgmstream_ish_isd(STREAMFILE *streamFile) {
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2008-11-28 15:27:51 +01:00
|
|
|
STREAMFILE * streamFileISH = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2014-03-15 06:36:23 +01:00
|
|
|
char filenameISH[PATH_LIMIT];
|
2009-01-28 10:35:55 +01:00
|
|
|
int i;
|
|
|
|
int channel_count;
|
|
|
|
int loop_flag;
|
2008-11-28 15:27:51 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("isd",filename_extension(filename))) goto fail;
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
strcpy(filenameISH,filename);
|
|
|
|
strcpy(filenameISH+strlen(filenameISH)-3,"ish");
|
2008-11-28 15:27:51 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
streamFileISH = streamFile->open(streamFile,filenameISH,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!streamFileISH) goto fail;
|
2008-11-28 15:27:51 +01:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFileISH) != 0x495F5346) /* "I_SF" */
|
|
|
|
goto fail;
|
2009-01-28 10:35:55 +01:00
|
|
|
|
|
|
|
channel_count = read_32bitBE(0x14,streamFileISH);
|
|
|
|
loop_flag = (read_32bitBE(0x1C,streamFileISH) !=0);
|
2008-11-28 15:27:51 +01:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
2009-01-28 10:35:55 +01:00
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x08,streamFileISH);
|
|
|
|
vgmstream->num_samples=read_32bitBE(0x0C,streamFileISH);
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
if(loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x20,streamFileISH)*14/8/channel_count;
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x24,streamFileISH)*14/8/channel_count;
|
|
|
|
}
|
2008-11-28 15:27:51 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
if (channel_count == 1) {
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
} else if (channel_count == 2) {
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = read_32bitBE(0x18,streamFileISH);
|
|
|
|
}
|
2008-11-28 15:27:51 +01:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_ISH_ISD;
|
2009-01-28 10:35:55 +01:00
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
2008-11-28 15:27:51 +01:00
|
|
|
{
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,vgmstream->interleave_block_size);
|
2009-01-28 10:35:55 +01:00
|
|
|
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=i*vgmstream->interleave_block_size;
|
2008-11-28 15:27:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
|
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
2008-11-28 15:27:51 +01:00
|
|
|
int i;
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(0x40+i*2,streamFileISH);
|
|
|
|
}
|
|
|
|
if (vgmstream->channels == 2) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(0x80+i*2,streamFileISH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
close_streamfile(streamFileISH); streamFileISH=NULL;
|
|
|
|
|
2008-11-28 15:27:51 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (streamFileISH) close_streamfile(streamFileISH);
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|