2008-05-13 13:47:51 +02:00
|
|
|
#include "meta.h"
|
2018-08-16 20:06:57 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-05-13 13:47:51 +02:00
|
|
|
|
|
|
|
|
2018-08-16 20:06:57 +02:00
|
|
|
/* EXST - from Sony games [Shadow of the Colossus (PS2), Gacha Mecha Stadium Saru Battle (PS2)] */
|
2021-01-03 16:00:08 +01:00
|
|
|
VGMSTREAM* init_vgmstream_ps2_exst(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
STREAMFILE* sf_body = NULL;
|
2018-08-16 20:06:57 +02:00
|
|
|
off_t start_offset;
|
2021-01-03 16:00:08 +01:00
|
|
|
int loop_flag, channels, sample_rate;
|
2018-08-16 20:06:57 +02:00
|
|
|
size_t block_size, num_blocks, loop_start_block;
|
2008-05-13 13:47:51 +02:00
|
|
|
|
|
|
|
|
2018-08-16 20:06:57 +02:00
|
|
|
/* checks */
|
2021-01-03 16:00:08 +01:00
|
|
|
/* .sts+int: standard [Shadow of the Colossus (PS2)] (some fake .sts have manually joined header+body)
|
2018-08-16 20:06:57 +02:00
|
|
|
* .x: header+body [Ape Escape 3 (PS2)] */
|
2021-01-03 16:00:08 +01:00
|
|
|
if (!check_extensions(sf, "sts,x"))
|
2018-08-16 20:06:57 +02:00
|
|
|
goto fail;
|
2021-01-03 16:00:08 +01:00
|
|
|
if (!is_id32be(0x00,sf, "EXST"))
|
2008-05-13 13:47:51 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-01-03 16:00:08 +01:00
|
|
|
sf_body = open_streamfile_by_ext(sf,"int");
|
|
|
|
if (sf_body) {
|
|
|
|
/* separate header+body (header is 0x78) */
|
2018-08-16 20:06:57 +02:00
|
|
|
start_offset = 0x00;
|
|
|
|
}
|
2021-01-03 16:00:08 +01:00
|
|
|
else {
|
|
|
|
/* joint header+body */
|
|
|
|
start_offset = 0x78;
|
|
|
|
/* Gacharoku 2 has header+data but padded header (ELF has pointers + size to SOUND.PCK, and
|
|
|
|
* treats them as single files, no extension but there are Sg2ExStAdpcm* calls in the ELF) */
|
|
|
|
if ((get_streamfile_size(sf) % 0x10) == 0)
|
|
|
|
start_offset = 0x80;
|
2018-08-16 20:06:57 +02:00
|
|
|
|
2021-01-03 16:00:08 +01:00
|
|
|
if (get_streamfile_size(sf) < start_offset)
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-08-16 20:06:57 +02:00
|
|
|
|
2021-01-03 16:00:08 +01:00
|
|
|
channels = read_u16le(0x06,sf);
|
|
|
|
sample_rate = read_u32le(0x08,sf);
|
|
|
|
loop_flag = read_u32le(0x0C,sf) == 1;
|
|
|
|
loop_start_block = read_u32le(0x10,sf);
|
|
|
|
num_blocks = read_u32le(0x14,sf);
|
|
|
|
/* 0x18: 0x24 config per channel? (volume+panning+etc?) */
|
|
|
|
/* rest is padding up to 0x78 */
|
2008-05-13 13:47:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2021-01-03 16:00:08 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-05-13 13:47:51 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-08-16 20:06:57 +02:00
|
|
|
vgmstream->meta_type = meta_PS2_EXST;
|
2021-01-03 16:00:08 +01:00
|
|
|
vgmstream->sample_rate = sample_rate;
|
2008-05-13 13:47:51 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2018-08-16 20:06:57 +02:00
|
|
|
vgmstream->interleave_block_size = 0x400;
|
2008-05-13 13:47:51 +02:00
|
|
|
|
2018-08-16 20:06:57 +02:00
|
|
|
block_size = vgmstream->interleave_block_size * vgmstream->channels;
|
2021-01-03 16:00:08 +01:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(num_blocks * block_size, channels);
|
|
|
|
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start_block * block_size, channels);
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2008-05-13 13:47:51 +02:00
|
|
|
|
2021-01-03 16:00:08 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf_body ? sf_body : sf, start_offset))
|
2018-08-16 20:06:57 +02:00
|
|
|
goto fail;
|
2021-01-03 16:00:08 +01:00
|
|
|
close_streamfile(sf_body);
|
2008-05-13 13:47:51 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2021-01-03 16:00:08 +01:00
|
|
|
close_streamfile(sf_body);
|
2018-08-16 20:06:57 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-05-13 13:47:51 +02:00
|
|
|
return NULL;
|
|
|
|
}
|