2008-11-28 17:25:52 +01:00
|
|
|
#include "meta.h"
|
2008-12-18 08:33:13 +01:00
|
|
|
#include "../layout/layout.h"
|
2008-11-28 17:25:52 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
/* GSP+GSB - 2008-11-28 - manakoAT
|
2008-12-18 20:04:35 +01:00
|
|
|
Super Swing Golf 1 & 2 (WII) */
|
2008-11-28 17:25:52 +01:00
|
|
|
VGMSTREAM * init_vgmstream_gsp_gsb(STREAMFILE *streamFile) {
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2008-11-28 17:25:52 +01:00
|
|
|
STREAMFILE * streamFileGSP = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2009-01-28 10:35:55 +01:00
|
|
|
char filenameGSP[260];
|
|
|
|
int channel_count;
|
|
|
|
int loop_flag;
|
|
|
|
int header_len;
|
|
|
|
int i;
|
2008-12-16 16:48:21 +01:00
|
|
|
off_t coef1_start;
|
2009-01-28 10:35:55 +01:00
|
|
|
off_t coef2_start;
|
|
|
|
off_t start_offset;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
|
2008-11-28 17:25:52 +01:00
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("gsb",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
strcpy(filenameGSP,filename);
|
|
|
|
strcpy(filenameGSP+strlen(filenameGSP)-3,"gsp");
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
streamFileGSP = streamFile->open(streamFile,filenameGSP,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!streamFileGSP) goto fail;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFileGSP) != 0x47534E44) /* "GSND" */
|
2009-01-28 10:35:55 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
channel_count = (uint16_t)read_16bitBE(0x3A,streamFileGSP);
|
2010-02-27 23:10:52 +01:00
|
|
|
loop_flag = (read_32bitBE(0x64,streamFileGSP) != 0xFFFFFFFF);
|
2009-01-28 10:35:55 +01:00
|
|
|
header_len = read_32bitBE(0x1C,streamFileGSP);
|
|
|
|
|
|
|
|
coef1_start = header_len-0x4C;
|
|
|
|
coef2_start = header_len-0x1C;
|
|
|
|
|
2008-11-28 17:25:52 +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(0x34,streamFileGSP);
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
if(loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x64,streamFileGSP);
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x68,streamFileGSP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channel_count == 1) {
|
|
|
|
vgmstream->layout_type = layout_gsb_blocked;
|
|
|
|
} else if (channel_count > 1) {
|
|
|
|
vgmstream->layout_type = layout_gsb_blocked;
|
|
|
|
vgmstream->interleave_block_size = read_32bitBE(header_len-0x64,streamFileGSP);
|
|
|
|
}
|
2008-11-28 17:25:52 +01:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_GSP_GSB;
|
2009-01-28 10:35:55 +01:00
|
|
|
|
2009-02-06 20:16:37 +01:00
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,vgmstream->interleave_block_size);
|
|
|
|
|
|
|
|
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 17:25:52 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
if (vgmstream->coding_type == coding_NGC_DSP) {
|
2008-11-28 17:25:52 +01:00
|
|
|
int i;
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(coef1_start+i*2,streamFileGSP);
|
|
|
|
}
|
|
|
|
if (vgmstream->channels == 2) {
|
|
|
|
for (i=0;i<16;i++) {
|
|
|
|
vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(coef2_start+i*2,streamFileGSP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
/* Calc num_samples */
|
|
|
|
start_offset = 0x0;
|
|
|
|
gsb_block_update(start_offset,vgmstream);
|
|
|
|
vgmstream->num_samples=0;
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
do {
|
|
|
|
|
|
|
|
vgmstream->num_samples += vgmstream->current_block_size*14/8;
|
|
|
|
gsb_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
} while (vgmstream->next_block_offset<get_streamfile_size(streamFile));
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
gsb_block_update(start_offset,vgmstream);
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
close_streamfile(streamFileGSP); streamFileGSP=NULL;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2008-11-28 17:25:52 +01:00
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (streamFileGSP) close_streamfile(streamFileGSP);
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|