From b4a71cd5aa8f03f53d3229000ca6a0a7fa359738 Mon Sep 17 00:00:00 2001 From: NicknineTheEagle Date: Fri, 21 Sep 2018 14:31:56 +0300 Subject: [PATCH] RIFF: implemented looping info from CUE chunk --- src/meta/riff.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/meta/riff.c b/src/meta/riff.c index 2aca1992..d2f7c175 100644 --- a/src/meta/riff.c +++ b/src/meta/riff.c @@ -244,6 +244,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) { long loop_start_ms = -1, loop_end_ms = -1; int32_t loop_start_wsmp = -1, loop_end_wsmp = -1; int32_t loop_start_smpl = -1, loop_end_smpl = -1; + int32_t loop_start_cue = -1; int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0; @@ -420,6 +421,18 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) { mwv_ctrl_offset = current_chunk; break; + case 0x63756520: /* "cue " (used in Source Engine for storing loop points) */ + if (fmt.coding_type == coding_PCM16LE || fmt.coding_type == coding_MSADPCM) { + uint32_t num_cues = read_32bitLE(current_chunk + 0x08, streamFile); + + if (num_cues == 1 || num_cues == 2) { + // The second cue sets loop end point but it's not actually used by the engine. + loop_flag = 1; + loop_start_cue = read_32bitLE(current_chunk + 0x20, streamFile); + } + } + break; + case 0x4A554E4B: /* "JUNK" */ JunkFound = 1; break; @@ -643,6 +656,10 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) { vgmstream->loop_start_sample = read_32bitLE(mwv_ctrl_offset+12, streamFile); vgmstream->loop_end_sample = vgmstream->num_samples; } + else if (loop_start_cue != -1) { + vgmstream->loop_start_sample = loop_start_cue; + vgmstream->loop_end_sample = vgmstream->num_samples; + } } if (mwv) { vgmstream->meta_type = meta_RIFF_WAVE_MWV;