mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 21:43:34 +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:
parent
a8b4dc673d
commit
dbe2edd89d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue