2008-11-28 17:25:52 +01:00
|
|
|
#include "meta.h"
|
2008-12-18 08:33:13 +01:00
|
|
|
#include "../layout/layout.h"
|
2017-01-14 01:39:21 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
/* GSP+GSB - from Tecmo's Super Swing Golf 1 & 2 (WII), Quantum Theory (PS3/X360) */
|
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;
|
2017-01-14 01:39:21 +01:00
|
|
|
int loop_flag, channel_count;
|
|
|
|
off_t start_offset, chunk_offset, first_offset;
|
|
|
|
size_t datasize;
|
|
|
|
int codec_id;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2009-01-28 10:35:55 +01:00
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
/* check extensions */
|
|
|
|
if (!check_extensions(streamFile,"gsb"))
|
|
|
|
goto fail;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
streamFileGSP = open_stream_ext(streamFile, "gsp");
|
2009-01-28 10:35:55 +01:00
|
|
|
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;
|
2017-01-14 01:39:21 +01:00
|
|
|
/* 0x04: version?, 0x08: 1?, 0x0c: 0?, */
|
|
|
|
first_offset = read_32bitBE(0x10,streamFileGSP); /* usually 0x14*/
|
|
|
|
|
|
|
|
if (!find_chunk_be(streamFileGSP, 0x44415441,first_offset,1, &chunk_offset,NULL)) goto fail; /*"DATA"*/
|
|
|
|
channel_count = read_16bitBE(chunk_offset+0x0e,streamFileGSP);
|
|
|
|
if (!find_chunk_be(streamFileGSP, 0x42534943,first_offset,1, &chunk_offset,NULL)) goto fail; /*"BSIC"*/
|
|
|
|
loop_flag = read_8bit(chunk_offset+0x0c,streamFileGSP);
|
2009-01-28 10:35:55 +01:00
|
|
|
|
2008-11-28 17:25:52 +01:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
if (!find_chunk_be(streamFileGSP, 0x48454144,first_offset,1, &chunk_offset,NULL)) goto fail; /*"HEAD"*/
|
|
|
|
/* 0x00: header_size, 0x04: num_chunks */
|
|
|
|
|
|
|
|
if (!find_chunk_be(streamFileGSP, 0x44415441,first_offset,1, &chunk_offset,NULL)) goto fail; /*"DATA"*/
|
|
|
|
/* 0x00: filesize, 0x0c: always 10?, 0x10: always 0?, 0x18: always 0? */
|
2017-01-14 03:05:07 +01:00
|
|
|
datasize = read_32bitBE(chunk_offset+0x00,streamFileGSP);
|
2017-01-14 01:39:21 +01:00
|
|
|
codec_id = read_32bitBE(chunk_offset+0x04,streamFileGSP);
|
|
|
|
vgmstream->sample_rate = read_32bitBE(chunk_offset+0x08,streamFileGSP);
|
|
|
|
vgmstream->channels = channel_count; /* 0x0e */
|
|
|
|
vgmstream->num_samples = read_32bitBE(chunk_offset+0x14,streamFileGSP);
|
|
|
|
/* 0x1c: unk (varies with codec_id) */
|
|
|
|
|
|
|
|
if (!find_chunk_be(streamFileGSP, 0x42534943,first_offset,1, &chunk_offset,NULL)) goto fail; /*"BSIC"*/
|
|
|
|
/* 0x00+: probably volume/pan/etc */
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(chunk_offset+0x10,streamFileGSP);
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(chunk_offset+0x14,streamFileGSP);
|
|
|
|
|
|
|
|
//if (!find_chunk_be(streamFileGSP, 0x4E414D45,first_offset,1, &chunk_offset,NULL)) goto fail; /*"NAME"*/
|
|
|
|
/* 0x00: name_size, 0x04+: name*/
|
|
|
|
|
|
|
|
start_offset = 0x0;
|
|
|
|
|
|
|
|
switch (codec_id) {
|
|
|
|
case 4: { /* DSP */
|
2017-01-14 03:05:07 +01:00
|
|
|
size_t block_header_size;
|
|
|
|
size_t num_blocks;
|
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_gsb_blocked;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
if (!find_chunk_be(streamFileGSP, 0x47434558,first_offset,1, &chunk_offset,NULL)) goto fail; /*"GCEX"*/
|
|
|
|
|
2017-01-14 03:05:07 +01:00
|
|
|
//vgmstream->current_block_size = read_32bitBE(chunk_offset+0x00,streamFileGSP);
|
|
|
|
block_header_size = read_32bitBE(chunk_offset+0x04,streamFileGSP);
|
|
|
|
num_blocks = read_32bitBE(chunk_offset+0x08,streamFileGSP);
|
|
|
|
vgmstream->num_samples = (datasize - block_header_size * num_blocks) / 8 / vgmstream->channels * 14;
|
|
|
|
/* 0x0c+: unk */
|
2017-01-14 01:39:21 +01:00
|
|
|
|
|
|
|
dsp_read_coefs_be(vgmstream, streamFileGSP, chunk_offset+0x18, 0x30);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case 8: { /* ATRAC3 */
|
|
|
|
ffmpeg_codec_data *ffmpeg_data = NULL;
|
|
|
|
uint8_t buf[100];
|
|
|
|
int32_t bytes, block_size, encoder_delay, joint_stereo, max_samples;
|
|
|
|
|
|
|
|
block_size = 0x98 * vgmstream->channels;
|
|
|
|
joint_stereo = 0;
|
|
|
|
max_samples = (datasize / block_size) * 1024;
|
|
|
|
encoder_delay = max_samples - vgmstream->num_samples; /* todo guessed */
|
|
|
|
|
|
|
|
vgmstream->num_samples += encoder_delay;
|
|
|
|
/* make a fake riff so FFmpeg can parse the ATRAC3 */
|
|
|
|
bytes = ffmpeg_make_riff_atrac3(buf,100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_size, joint_stereo, encoder_delay);
|
|
|
|
if (bytes <= 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,datasize);
|
|
|
|
if ( !ffmpeg_data ) goto fail;
|
|
|
|
vgmstream->codec_data = ffmpeg_data;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
vgmstream->loop_start_sample = (vgmstream->loop_start_sample / ffmpeg_data->blockAlign) * ffmpeg_data->frameSize;
|
|
|
|
vgmstream->loop_end_sample = (vgmstream->loop_end_sample / ffmpeg_data->blockAlign) * ffmpeg_data->frameSize;
|
|
|
|
|
|
|
|
break;
|
2008-11-28 17:25:52 +01:00
|
|
|
}
|
2017-01-14 01:39:21 +01:00
|
|
|
|
|
|
|
case 9: { /* XMA2 */
|
|
|
|
ffmpeg_codec_data *ffmpeg_data = NULL;
|
|
|
|
uint8_t buf[200];
|
|
|
|
int32_t bytes;
|
|
|
|
|
|
|
|
if (!find_chunk_be(streamFileGSP, 0x584D4558,first_offset,1, &chunk_offset,NULL)) goto fail; /*"XMEX"*/
|
|
|
|
/* 0x00: fmt0x166 header (BE), 0x34: seek table */
|
|
|
|
|
|
|
|
bytes = ffmpeg_make_riff_xma2_from_fmt_be(buf,200, chunk_offset,0x34, datasize, streamFileGSP);
|
|
|
|
if (bytes <= 0) goto fail;
|
|
|
|
|
|
|
|
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,datasize);
|
|
|
|
if ( !ffmpeg_data ) goto fail;
|
|
|
|
vgmstream->codec_data = ffmpeg_data;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
break;
|
2008-11-28 17:25:52 +01:00
|
|
|
}
|
2017-01-14 01:39:21 +01:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
goto fail;
|
2008-11-28 17:25:52 +01:00
|
|
|
}
|
2017-01-14 01:39:21 +01:00
|
|
|
vgmstream->meta_type = meta_GSP_GSB;
|
2008-11-28 17:25:52 +01:00
|
|
|
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2017-01-14 01:39:21 +01:00
|
|
|
/* open the file for reading */
|
|
|
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
|
|
|
goto fail;
|
2008-12-16 16:48:21 +01:00
|
|
|
|
2017-01-14 03:05:07 +01:00
|
|
|
close_streamfile(streamFileGSP);
|
2008-11-28 17:25:52 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (streamFileGSP) close_streamfile(streamFileGSP);
|
2017-01-14 01:39:21 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-11-28 17:25:52 +01:00
|
|
|
return NULL;
|
|
|
|
}
|