VGMStream: Fix one shot files actually decoding to completion instead of getting stuck forever

CQTexperiment
Christopher Snowhill 2021-06-15 01:34:01 -07:00
parent cae132ad79
commit 75a4f1e722
2 changed files with 22 additions and 10 deletions

View File

@ -29,6 +29,7 @@
VGMSTREAM *stream; VGMSTREAM *stream;
BOOL playForever; BOOL playForever;
BOOL canPlayForever;
int sampleRate; int sampleRate;
int channels; int channels;
int bitrate; int bitrate;

View File

@ -223,7 +223,13 @@
vgmstream_mixing_autodownmix(stream, 6); vgmstream_mixing_autodownmix(stream, 6);
playForever = IsRepeatOneSet(); canPlayForever = stream->loop_flag;
if (canPlayForever) {
playForever = IsRepeatOneSet();
}
else {
playForever = NO;
}
vgmstream_cfg_t vcfg = {0}; vgmstream_cfg_t vcfg = {0};
@ -266,18 +272,21 @@
- (int)readAudio:(void *)buf frames:(UInt32)frames - (int)readAudio:(void *)buf frames:(UInt32)frames
{ {
BOOL repeatone = IsRepeatOneSet();
UInt32 framesMax = frames; UInt32 framesMax = frames;
if (repeatone != playForever) { if (canPlayForever) {
playForever = repeatone; BOOL repeatone = IsRepeatOneSet();
vgmstream_set_play_forever(stream, repeatone);
if (repeatone != playForever) {
playForever = repeatone;
vgmstream_set_play_forever(stream, repeatone);
}
} }
if (framesRead + frames > totalFrames && !playForever) if (framesRead + frames > totalFrames && !playForever)
frames = totalFrames - framesRead; frames = totalFrames - framesRead;
if (frames > framesMax) if (frames > framesMax)
frames = 0; frames = 0; // integer overflow?
if (frames) { if (frames) {
sample * sbuf = (sample *) buf; sample * sbuf = (sample *) buf;
@ -292,11 +301,13 @@
- (long)seek:(long)frame - (long)seek:(long)frame
{ {
BOOL repeatone = IsRepeatOneSet(); if (canPlayForever) {
BOOL repeatone = IsRepeatOneSet();
if (repeatone != playForever) { if (repeatone != playForever) {
playForever = repeatone; playForever = repeatone;
vgmstream_set_play_forever(stream, repeatone); vgmstream_set_play_forever(stream, repeatone);
}
} }
if (frame > totalFrames) if (frame > totalFrames)