vgmstream/src/meta/ps2_strlr.c

58 lines
1.7 KiB
C
Raw Normal View History

#include "meta.h"
#include "../layout/layout.h"
2018-06-30 16:01:29 +02:00
#include "../coding/coding.h"
2018-06-30 16:01:29 +02:00
/* STR - The Bouncer (PS2) */
VGMSTREAM * init_vgmstream_ps2_strlr(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
2018-06-30 16:01:29 +02:00
int channel_count, loop_flag;
off_t start_offset;
2018-06-30 16:01:29 +02:00
/* checks */
/* .vs: real extension (from .nam container) , .str: partial header id */
if (!check_extensions(streamFile, "vs,str"))
goto fail;
2018-06-30 16:01:29 +02:00
/* check header */
if (!(read_32bitBE(0x000,streamFile) == 0x5354524C && /* "STRL" */
read_32bitBE(0x800,streamFile) == 0x53545252) && /* "STRR" */
read_32bitBE(0x00,streamFile) != 0x5354524D) /* "STRM" */
goto fail;
2018-06-30 16:01:29 +02:00
loop_flag = 0;
2018-06-30 16:01:29 +02:00
channel_count = (read_32bitBE(0x00,streamFile) == 0x5354524D) ? 1 : 2; /* "STRM"=mono (voices) */
start_offset = 0x00;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
2018-06-30 16:01:29 +02:00
vgmstream->sample_rate = 44100;
vgmstream->coding_type = coding_PSX;
2018-03-29 19:00:04 +02:00
vgmstream->layout_type = layout_blocked_ps2_strlr;
vgmstream->meta_type = meta_PS2_STRLR;
2018-06-30 16:01:29 +02:00
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
/* calc num_samples */
{
2018-06-30 16:01:29 +02:00
vgmstream->next_block_offset = start_offset;
do {
block_update_ps2_strlr(vgmstream->next_block_offset,vgmstream);
vgmstream->num_samples += ps_bytes_to_samples(vgmstream->current_block_size, 1);
}
2018-06-30 16:01:29 +02:00
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
}
2018-03-29 19:00:04 +02:00
block_update_ps2_strlr(start_offset, vgmstream);
return vgmstream;
fail:
2018-06-30 16:01:29 +02:00
close_vgmstream(vgmstream);
return NULL;
}