RSTM: Fix stream sizes and looping

This commit is contained in:
EdnessP 2023-10-29 20:33:27 +02:00
parent 416ac26510
commit 2af39680d8

View File

@ -4,8 +4,9 @@
/* RSTM - from Rockstar games [Midnight Club 3, Bully - Canis Canim Edit (PS2)] */ /* RSTM - from Rockstar games [Midnight Club 3, Bully - Canis Canim Edit (PS2)] */
VGMSTREAM* init_vgmstream_rstm_rockstar(STREAMFILE* sf) { VGMSTREAM* init_vgmstream_rstm_rockstar(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
uint32_t start_offset; off_t stream_offset, loop_start, loop_end;
int channels, loop_flag; size_t stream_size;
int sample_rate, channels, loop_flag;
/* checks */ /* checks */
@ -17,9 +18,17 @@ VGMSTREAM* init_vgmstream_rstm_rockstar(STREAMFILE* sf) {
if (!check_extensions(sf, "rsm,rstm")) if (!check_extensions(sf, "rsm,rstm"))
return NULL; return NULL;
loop_flag = (read_s32le(0x24,sf) > 0); sample_rate = read_s32le(0x08, sf);
channels = read_s32le(0x0C, sf); channels = read_s32le(0x0C, sf);
start_offset = 0x800; /* 0x10-0x18 - empty padding(?) */
stream_size = read_s32le(0x18, sf);
loop_start = read_s32le(0x1C, sf);
loop_end = read_s32le(0x20, sf);
/* other loop start/ends after here? (uncommon) */
stream_offset = 0x800;
//loop_flag = (read_s32le(0x24,sf) > 0);
loop_flag = loop_end != stream_size;
/* build the VGMSTREAM */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag); vgmstream = allocate_vgmstream(channels, loop_flag);
@ -27,17 +36,17 @@ VGMSTREAM* init_vgmstream_rstm_rockstar(STREAMFILE* sf) {
vgmstream->meta_type = meta_RSTM_ROCKSTAR; vgmstream->meta_type = meta_RSTM_ROCKSTAR;
vgmstream->sample_rate = read_s32le(0x08,sf); vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = ps_bytes_to_samples(read_u32le(0x20,sf),channels); vgmstream->num_samples = ps_bytes_to_samples(stream_size, channels);
vgmstream->loop_start_sample = ps_bytes_to_samples(read_u32le(0x24,sf),channels); vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels);
vgmstream->loop_end_sample = vgmstream->num_samples; vgmstream->loop_end_sample = ps_bytes_to_samples(loop_end, channels);
vgmstream->coding_type = coding_PSX; vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave; vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10; vgmstream->interleave_block_size = 0x10;
/* open the file for reading */ /* open the file for reading */
if ( !vgmstream_open_stream(vgmstream, sf, start_offset) ) if ( !vgmstream_open_stream(vgmstream, sf, stream_offset) )
goto fail; goto fail;
return vgmstream; return vgmstream;