vgmstream/src/meta/ps2_sfs.c

54 lines
1.5 KiB
C
Raw Normal View History

#include "meta.h"
2021-07-29 18:38:07 +02:00
#include "../coding/coding.h"
2021-07-29 18:38:07 +02:00
/* SFS - from Sting games [Baroque (PS2)] */
VGMSTREAM* init_vgmstream_sfs(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
2021-07-29 18:38:07 +02:00
int loop_flag, channels, sample_rate;
size_t channel_size, loop_start;
2021-07-29 18:38:07 +02:00
/* checks */
/* .sfs: bigfile extension (no apparent names) */
if (!check_extensions(sf, "sfs"))
goto fail;
2021-07-29 18:38:07 +02:00
if (!is_id32be(0x00,sf, "STER"))
goto fail;
channel_size = read_u32le(0x04, sf);
loop_start = read_u32le(0x08, sf); /* absolute (ex. offset 0x50 for full loops) */
/* 0x0c: data size BE */
sample_rate = read_s32be(0x10,sf);
2021-07-29 18:38:07 +02:00
loop_flag = loop_start != 0xFFFFFFFF;
channels = 2;
start_offset = 0x30;
2021-07-29 18:38:07 +02:00
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_SFS;
2021-07-29 18:38:07 +02:00
vgmstream->sample_rate = sample_rate;
2021-07-29 18:38:07 +02:00
vgmstream->num_samples = ps_bytes_to_samples(channel_size, 1);
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start - start_offset, channels);
vgmstream->loop_end_sample = vgmstream->num_samples;
2021-07-29 18:38:07 +02:00
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
2021-07-29 18:38:07 +02:00
read_string(vgmstream->stream_name,0x10+1, 0x20,sf);
2021-07-29 18:38:07 +02:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
2021-07-29 18:38:07 +02:00
close_vgmstream(vgmstream);
return NULL;
}