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

Audio: Rewind on play, not stop

Before, streams were rewound when they stopped, so that next time they're played they're played from the start.

Instead, rewind on play instead, so that it's done when it's needed. This gets us a good point to make sure we're not rewinding raw streams too.
This commit is contained in:
Nevyn Bengtsson 2020-01-03 23:00:58 +01:00
parent c6806f50e1
commit 33bee6ce44
2 changed files with 8 additions and 2 deletions

View file

@ -95,7 +95,6 @@ void lovrAudioUpdate() {
alSourcePlay(id);
}
} else if (isStopped) {
lovrAudioStreamRewind(lovrSourceGetStream(source));
arr_splice(&state.sources, i, 1);
lovrRelease(Source, source);
}

View file

@ -165,6 +165,11 @@ 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);
}
lovrSourceStream(source, source->buffers, SOURCE_BUFFERS);
alSourcePlay(source->id);
}
@ -285,7 +290,9 @@ void lovrSourceStop(Source* source) {
alSourcei(source->id, AL_BUFFER, AL_NONE);
// Rewind the decoder
lovrAudioStreamRewind(source->stream);
if (!lovrAudioStreamIsRaw(source->stream)) {
lovrAudioStreamRewind(source->stream);
}
break;
}
}