vgmstream/src/meta/vs_square.c

67 lines
2.1 KiB
C
Raw Normal View History

2018-10-20 15:30:46 +02:00
#include "meta.h"
#include "../layout/layout.h"
#include "../coding/coding.h"
2018-11-01 16:41:23 +01:00
/* VS - VagStream from Square games [Final Fantasy X (PS2) voices, Unlimited Saga (PS2) voices, All Star Pro-Wrestling 2/3 (PS2) music] */
2018-12-22 20:09:01 +01:00
VGMSTREAM * init_vgmstream_vs_square(STREAMFILE *streamFile) {
2018-10-20 15:30:46 +02:00
VGMSTREAM * vgmstream = NULL;
int channel_count, loop_flag, pitch, flags;
2018-10-20 15:30:46 +02:00
off_t start_offset;
/* checks */
/* .vs: header id (probably ok like The Bouncer's .vs, very similar) */
if (!check_extensions(streamFile, "vs"))
goto fail;
2018-11-01 16:41:23 +01:00
if (read_32bitBE(0x00,streamFile) != 0x56530000) /* "VS\0\0" */
2018-10-20 15:30:46 +02:00
goto fail;
flags = read_32bitLE(0x04,streamFile);
2018-11-01 16:41:23 +01:00
/* 0x08: block number */
/* 0x0c: blocks left in the subfile */
pitch = read_32bitLE(0x10,streamFile); /* usually 0x1000 = 48000 */
2019-05-05 23:27:02 +02:00
/* 0x14: volume, usually 0x64 = 100 but may be bigger/smaller (up to 128?) */
2018-11-01 16:41:23 +01:00
/* 0x18: null */
/* 0x1c: null */
2018-10-20 15:30:46 +02:00
2019-05-05 23:27:02 +02:00
/* some Front Mission 4 voices have flag 0x100, no idea */
if (flags != 0x00 && flags != 0x01) {
2019-05-05 23:27:02 +02:00
VGM_LOG("VS: unknown flags %x\n", flags);
}
2018-10-20 15:30:46 +02:00
loop_flag = 0;
channel_count = (flags & 1) ? 2 : 1;
2018-10-20 15:30:46 +02:00
start_offset = 0x00;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
2018-12-22 20:09:01 +01:00
vgmstream->meta_type = meta_VS_SQUARE;
2018-11-03 18:06:39 +01:00
vgmstream->sample_rate = round10((48000 * pitch) / 4096); /* needed for rare files */
2018-10-20 15:30:46 +02:00
vgmstream->coding_type = coding_PSX;
2018-12-22 20:09:01 +01:00
vgmstream->layout_type = layout_blocked_vs_square;
2018-10-20 15:30:46 +02:00
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
/* calc num_samples */
{
vgmstream->next_block_offset = start_offset;
do {
block_update(vgmstream->next_block_offset,vgmstream);
vgmstream->num_samples += ps_bytes_to_samples(vgmstream->current_block_size, 1);
}
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
block_update(start_offset, vgmstream);
}
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}