vgmstream/src/meta/vsf.c

59 lines
1.9 KiB
C
Raw Normal View History

2019-12-14 19:50:56 +01:00
#include "meta.h"
2019-12-15 01:37:56 +01:00
#include "../coding/coding.h"
2019-12-14 19:50:56 +01:00
2019-12-15 01:37:56 +01:00
/* VSF - from Square Enix PS2 games between 2004-2006 [Musashi: Samurai Legend (PS2), Front Mission 5 (PS2)] */
VGMSTREAM * init_vgmstream_vsf(STREAMFILE *streamFile) {
2019-12-14 19:50:56 +01:00
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
2019-12-15 01:37:56 +01:00
int loop_flag, channel_count, flags, pitch;
size_t channel_size, loop_start;
2019-12-14 19:50:56 +01:00
/* checks */
2019-12-15 01:37:56 +01:00
/* .vsf: header id and actual extension [Code Age Commanders (PS2)] */
2019-12-14 19:50:56 +01:00
if (!check_extensions(streamFile, "vsf"))
goto fail;
2019-12-15 01:37:56 +01:00
if (read_32bitBE(0x00,streamFile) != 0x56534600) /* "VSF\0" */
2019-12-14 19:50:56 +01:00
goto fail;
2019-12-15 01:37:56 +01:00
/* 0x04: data size */
/* 0x08: file number? */
/* 0x0c: version? (always 0x00010000) */
channel_size = read_32bitLE(0x10,streamFile) * 0x10;
/* 0x14: frame size */
loop_start = read_32bitLE(0x18,streamFile) * 0x10; /* also in channel size */
flags = read_32bitLE(0x1c,streamFile);
2019-12-14 19:50:56 +01:00
pitch = read_32bitLE(0x20,streamFile);
2019-12-15 01:37:56 +01:00
/* 0x24: volume? */
/* 0x28: ? (may be 0) */
/* rest is 0xFF */
channel_count = (flags & (1<<0)) ? 2 : 1;
loop_flag = (flags & (1<<1));
start_offset = (flags & (1<<8)) ? 0x80 : 0x800;
/* flag (1<<4) is common but no apparent differences, no other flags known */
2019-12-14 19:50:56 +01:00
2019-12-15 01:37:56 +01:00
/* build the VGMSTREAM */
2019-12-14 19:50:56 +01:00
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = round10((48000 * pitch) / 4096);
2019-12-15 01:37:56 +01:00
vgmstream->num_samples = ps_bytes_to_samples(channel_size, 1);
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, 1);
vgmstream->loop_end_sample = vgmstream->num_samples;
2019-12-14 19:50:56 +01:00
2019-12-15 01:37:56 +01:00
vgmstream->coding_type = coding_PSX;
2019-12-14 19:50:56 +01:00
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x400;
2019-12-15 01:37:56 +01:00
vgmstream->meta_type = meta_VSF;
2019-12-14 19:50:56 +01:00
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}