Fix .CSMP loops [Metroid Prime Trilogy (Wii)]

This commit is contained in:
bnnm 2023-05-14 20:12:25 +02:00
parent 3f1a5e94a8
commit f3a9c3bdd3

View File

@ -2,7 +2,7 @@
#include "../coding/coding.h"
/* CSMP - Retro Studios sample [Metroid Prime 3 (Wii), Donkey Kong Country Returns (Wii)] */
/* CSMP - Retro Studios sample [Metroid Prime 3 (Wii)-sfx, Donkey Kong Country Returns (Wii)-sfx] */
VGMSTREAM* init_vgmstream_csmp(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset, first_offset = 0x08, chunk_offset;
@ -10,21 +10,20 @@ VGMSTREAM* init_vgmstream_csmp(STREAMFILE* sf) {
/* checks */
if (!check_extensions(sf, "csmp"))
goto fail;
if (!is_id32be(0x00, sf, "CSMP"))
goto fail;
if (read_u32be(0x04, sf) != 1)
if (!check_extensions(sf, "csmp"))
goto fail;
if (read_u32be(0x04, sf) != 1) /* version? */
goto fail;
if (!find_chunk(sf, 0x44415441,first_offset,0, &chunk_offset,NULL, 1, 0)) /*"DATA"*/
/* INFO > PAD > DATA */
if (!find_chunk(sf, get_id32be("DATA"),first_offset,0, &chunk_offset,NULL, 1, 0))
goto fail;
/* contains standard DSP header, but somehow some validations (start/loop ps)
* don't seem to work, so no point to handle as standard DSP */
channels = 1;
loop_flag = read_s16be(chunk_offset+0x0c,sf);
/* contains a not quite standard DSP header */
channels = 1; /* also at INFO + 0x00? (in practice uses dual stereo in separate files) */
loop_flag = read_s16be(chunk_offset+0x0c,sf); /* also at INFO + 0x01 */
start_offset = chunk_offset + 0x60;
@ -35,10 +34,8 @@ VGMSTREAM* init_vgmstream_csmp(STREAMFILE* sf) {
vgmstream->meta_type = meta_CSMP;
vgmstream->sample_rate = read_s32be(chunk_offset+0x08,sf);
vgmstream->num_samples = read_s32be(chunk_offset+0x00,sf);
vgmstream->loop_start_sample = dsp_nibbles_to_samples(read_u32be(chunk_offset+0x10,sf));
vgmstream->loop_end_sample = dsp_nibbles_to_samples(read_u32be(chunk_offset+0x14,sf)) + 1;
if (vgmstream->loop_end_sample > vgmstream->num_samples) /* ? */
vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->loop_start_sample = read_s32be(chunk_offset+0x10,sf); /* unlike regular DSP's nibbles */
vgmstream->loop_end_sample = read_s32be(chunk_offset+0x14,sf) + 1;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_none;