mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-06 14:44:25 +01:00
Clean .pos code [Ys I Complete (PC)]
This commit is contained in:
parent
6823642302
commit
dc4cee2daf
@ -1,66 +1,40 @@
|
|||||||
#include <ctype.h>
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../util.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define DIRSEP '\\'
|
|
||||||
#else
|
|
||||||
#define DIRSEP '/'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* .pos is a tiny file with loop points, and the same base name as a .wav */
|
|
||||||
|
|
||||||
|
/* .pos - loop points for .wav [Ys I Complete (PC); reused for manual looping] */
|
||||||
VGMSTREAM * init_vgmstream_pos(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_pos(STREAMFILE *streamFile) {
|
||||||
|
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
STREAMFILE * streamFileWAV = NULL;
|
STREAMFILE * streamData = NULL;
|
||||||
char filename[PATH_LIMIT];
|
int32_t loop_start, loop_end;
|
||||||
char filenameWAV[PATH_LIMIT];
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* checks */
|
||||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
if (!check_extensions(streamFile,"pos"))
|
||||||
if (strcasecmp("pos",filename_extension(filename))) goto fail;
|
goto fail;
|
||||||
|
if (get_streamfile_size(streamFile) != 0x08)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
/* check for .WAV file */
|
streamData = open_streamfile_by_ext(streamFile, "wav");
|
||||||
strcpy(filenameWAV,filename);
|
if (!streamData) goto fail;
|
||||||
strcpy(filenameWAV+strlen(filenameWAV)-3,"wav");
|
|
||||||
|
|
||||||
streamFileWAV = streamFile->open(streamFile,filenameWAV,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
if (!streamFileWAV) {
|
|
||||||
/* try again, ucase */
|
|
||||||
for (i=strlen(filenameWAV);i>=0&&filenameWAV[i]!=DIRSEP;i--)
|
|
||||||
filenameWAV[i]=toupper(filenameWAV[i]);
|
|
||||||
|
|
||||||
streamFileWAV = streamFile->open(streamFile,filenameWAV,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
if (!streamFileWAV) goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* let the real initer do the parsing */
|
/* let the real initer do the parsing */
|
||||||
vgmstream = init_vgmstream_riff(streamFileWAV);
|
vgmstream = init_vgmstream_riff(streamData);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
close_streamfile(streamFileWAV);
|
close_streamfile(streamData);
|
||||||
streamFileWAV = NULL;
|
streamData = NULL;
|
||||||
|
|
||||||
/* install loops */
|
/* install loops (wrong values are validated later) */
|
||||||
if (!vgmstream->loop_flag) {
|
loop_start = read_32bitLE(0x00,streamFile);
|
||||||
vgmstream->loop_flag = 1;
|
loop_end = read_32bitLE(0x04,streamFile);
|
||||||
vgmstream->loop_ch = calloc(vgmstream->channels,
|
vgmstream_force_loop(vgmstream, 1, loop_start, loop_end);
|
||||||
sizeof(VGMSTREAMCHANNEL));
|
|
||||||
if (!vgmstream->loop_ch) goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
vgmstream->loop_start_sample = read_32bitLE(0,streamFile);
|
|
||||||
vgmstream->loop_end_sample = read_32bitLE(4,streamFile);
|
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_POS;
|
vgmstream->meta_type = meta_RIFF_WAVE_POS;
|
||||||
|
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
/* clean up anything we may have opened */
|
|
||||||
fail:
|
fail:
|
||||||
if (streamFileWAV) close_streamfile(streamFileWAV);
|
close_streamfile(streamData);
|
||||||
if (vgmstream) close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user