1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 20:43:35 +00:00

Source: Do rewind on stop like before, and clear buffers

I changed my mind. Let's use rewind to clear buffers on a raw stream like Bjorn suggested, and put rewind at stop like it was before.
This commit is contained in:
Nevyn Bengtsson 2020-01-05 21:08:30 +01:00
parent a8b4dc673d
commit dbe2edd89d
3 changed files with 12 additions and 7 deletions

View file

@ -95,6 +95,9 @@ void lovrAudioUpdate() {
alSourcePlay(id);
}
} else if (isStopped) {
// in case we'll play this source in the future, rewind it now. This also frees up queued raw buffers.
lovrAudioStreamRewind(lovrSourceGetStream(source));
arr_splice(&state.sources, i, 1);
lovrRelease(Source, source);
}

View file

@ -165,11 +165,6 @@ void lovrSourcePlay(Source* source) {
return;
}
// in case we're replaying an already-used stream, make sure to rewind it if applicable
if (!lovrAudioStreamIsRaw(source->stream)) {
lovrAudioStreamRewind(source->stream);
}
// in case we have some queued buffers, make sure to unqueue them before streaming more data into them.
ALint processed;
alGetSourcei(lovrSourceGetId(source), AL_BUFFERS_PROCESSED, &processed);

View file

@ -129,9 +129,16 @@ bool lovrAudioStreamIsRaw(AudioStream* stream)
}
void lovrAudioStreamRewind(AudioStream* stream) {
lovrAssert(!lovrAudioStreamIsRaw(stream), "Can't rewind raw stream");
stb_vorbis* decoder = (stb_vorbis*) stream->decoder;
stb_vorbis_seek_start(decoder);
if (decoder) {
stb_vorbis_seek_start(decoder);
} else {
stream->queueLengthInSamples = 0;
for (int i = 0; i < stream->queuedRawBuffers.length; i++) {
lovrRelease(Blob, stream->queuedRawBuffers.data[i]);
}
arr_clear(&stream->queuedRawBuffers);
}
}
void lovrAudioStreamSeek(AudioStream* stream, size_t sample) {