vgmstream/src/meta/ster.c

57 lines
1.7 KiB
C
Raw Normal View History

#include "meta.h"
2021-07-29 18:38:07 +02:00
#include "../coding/coding.h"
/* STER - from Silicon Studios/Vicarious Visions's ALCHEMY middleware [Baroque (PS2), Star Soldier (PS2)] */
VGMSTREAM* init_vgmstream_ster(STREAMFILE* sf) {
2021-07-29 18:38:07 +02:00
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 */
2023-01-20 17:30:17 +01:00
if (!is_id32be(0x00,sf, "STER"))
goto fail;
/* .ster: header id (no apparent names/extensions)
* .sfs: generic bigfile extension (to be removed?)*/
if (!check_extensions(sf, "ster,sfs"))
goto fail;
2021-07-29 18:38:07 +02:00
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);
/* 0x14~20: null */
2021-07-29 18:38:07 +02:00
loop_flag = loop_start != 0xFFFFFFFF;
channels = 2; /* mono files are simply .VAG */
start_offset = 0x30;
2021-07-29 18:38:07 +02:00
2023-01-20 17:30:17 +01:00
/* build the VGMSTREAM */
2021-07-29 18:38:07 +02:00
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_STER;
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;
}