tweak stream looping behavior

main
cosmonaut 2021-11-18 12:35:31 -08:00
parent e17d7e0da8
commit e12914177f
2 changed files with 14 additions and 14 deletions

Binary file not shown.

View File

@ -356,14 +356,21 @@ static void FAudioGMS_INTERNAL_OnBufferEndCallback(
instance->soundData.streamingSound.streamBufferSize / instance->soundData.streamingSound.streamBufferSize /
(instance->format.nChannels * sizeof(float)); (instance->format.nChannels * sizeof(float));
instance->soundData.streamingSound.mostRecentSampleOffset = SDL_min( instance->soundData.streamingSound.mostRecentSampleOffset %= instance->playLength;
instance->soundData.streamingSound.mostRecentSampleOffset,
instance->playLength);
if (instance->soundData.streamingSound.isFinalBuffer) if (instance->soundData.streamingSound.isFinalBuffer)
{
if (instance->loop)
{
stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin);
instance->soundData.streamingSound.mostRecentSampleOffset = instance->playBegin;
FAudioGMS_INTERNAL_SoundInstance_AddBuffers(instance);
}
else
{ {
FAudioGMS_INTERNAL_SoundInstance_Stop(instance); FAudioGMS_INTERNAL_SoundInstance_Stop(instance);
} }
}
else else
{ {
FAudioGMS_INTERNAL_SoundInstance_AddBuffers(instance); FAudioGMS_INTERNAL_SoundInstance_AddBuffers(instance);
@ -1030,16 +1037,9 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffers(FAudioGMS_SoundInstance
instance->soundData.streamingSound.isFinalBuffer = 0; instance->soundData.streamingSound.isFinalBuffer = 0;
if (sampleCount < defaultRequestedSampleCount) if (sampleCount < defaultRequestedSampleCount)
{
if (instance->loop)
{
stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin);
}
else
{ {
instance->soundData.streamingSound.isFinalBuffer = 1; instance->soundData.streamingSound.isFinalBuffer = 1;
} }
}
instance->soundData.streamingSound.nextStreamBufferIndex = instance->soundData.streamingSound.nextStreamBufferIndex =
(instance->soundData.streamingSound.nextStreamBufferIndex + 1) % STREAMING_BUFFER_COUNT; (instance->soundData.streamingSound.nextStreamBufferIndex + 1) % STREAMING_BUFFER_COUNT;