vgmstream/src/meta/pos.c

51 lines
1.5 KiB
C
Raw Normal View History

#include "meta.h"
2018-07-21 20:12:09 +02:00
/* .pos - loop points for .wav [Ys I Complete (PC); reused for manual looping] */
VGMSTREAM * init_vgmstream_pos(STREAMFILE *streamFile) {
2018-07-21 20:12:09 +02:00
VGMSTREAM * vgmstream = NULL;
STREAMFILE * streamData = NULL;
int32_t loop_start, loop_end;
2018-07-21 20:12:09 +02:00
/* checks */
if (!check_extensions(streamFile, "pos"))
2018-07-21 20:12:09 +02:00
goto fail;
if (get_streamfile_size(streamFile) != 0x08)
goto fail;
2018-07-21 20:12:09 +02:00
streamData = open_streamfile_by_ext(streamFile, "wav");
if (streamData) {
vgmstream = init_vgmstream_riff(streamData);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_RIFF_WAVE_POS;
}
else {
/* hack for Ogg with external loops */
streamData = open_streamfile_by_ext(streamFile, "ogg");
if (streamData) {
vgmstream = init_vgmstream_ogg_vorbis(streamData);
if (!vgmstream) goto fail;
}
else {
goto fail;
}
}
2018-07-21 20:12:09 +02:00
close_streamfile(streamData);
streamData = NULL;
2018-07-21 20:12:09 +02:00
/* install loops (wrong values are validated later) */
loop_start = read_32bitLE(0x00, streamFile);
loop_end = read_32bitLE(0x04, streamFile);
if (loop_end <= 0 || (loop_end > vgmstream->num_samples)) {
loop_end = vgmstream->num_samples;
}
2018-07-21 20:12:09 +02:00
vgmstream_force_loop(vgmstream, 1, loop_start, loop_end);
return vgmstream;
fail:
2018-07-21 20:12:09 +02:00
close_streamfile(streamData);
close_vgmstream(vgmstream);
return NULL;
}