mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-12-20 02:15:53 +01:00
55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
#include "meta.h"
|
|
#include "../util.h"
|
|
|
|
/* VSF (from many Square Enix games released on the PS2 between 2004-2006) */
|
|
VGMSTREAM * init_vgmstream_ps2_vsf(STREAMFILE *streamFile) {
|
|
VGMSTREAM * vgmstream = NULL;
|
|
off_t start_offset;
|
|
int loop_flag, channel_count, pitch;
|
|
|
|
/* checks */
|
|
/* .vsf - header id and actual extension (Code Age Commanders [PS2]) */
|
|
if (!check_extensions(streamFile, "vsf"))
|
|
goto fail;
|
|
|
|
/* check header */
|
|
if (read_32bitBE(0x00,streamFile) != 0x56534600) /* "VSF" */
|
|
goto fail;
|
|
|
|
loop_flag = (read_32bitLE(0x1c,streamFile)==0x13);
|
|
if(read_8bit(0x1C,streamFile)==0x0)
|
|
channel_count = 1;
|
|
else
|
|
channel_count = 2;
|
|
pitch = read_32bitLE(0x20,streamFile);
|
|
|
|
/* build the VGMSTREAM */
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
if (!vgmstream) goto fail;
|
|
|
|
/* fill in the vital statistics */
|
|
start_offset = 0x800;
|
|
vgmstream->channels = channel_count;
|
|
vgmstream->sample_rate = round10((48000 * pitch) / 4096);
|
|
vgmstream->coding_type = coding_PSX;
|
|
vgmstream->num_samples = read_32bitLE(0x10,streamFile)*28;
|
|
if (loop_flag) {
|
|
vgmstream->loop_start_sample = read_32bitLE(0x18,streamFile)*28;
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
}
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
vgmstream->interleave_block_size = 0x400;
|
|
vgmstream->meta_type = meta_PS2_VSF;
|
|
|
|
/* open the file for reading */
|
|
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
|
goto fail;
|
|
return vgmstream;
|
|
|
|
/* clean up anything we may have opened */
|
|
fail:
|
|
close_vgmstream(vgmstream);
|
|
return NULL;
|
|
}
|