From 3b840235f9b938360850fcf5237aa60c64267f05 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 28 Aug 2020 20:31:45 +1000 Subject: [PATCH] Resource Manager: Fix a looping bug. This is happening because the data buffer is incorrectly being reported as busy (still loading) which is used to indicate to the engine that no data is available and therefore nothing can be played. --- research/ma_engine.c | 7 ++++--- research/ma_engine.h | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index e25f241c..a18275e3 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -73,17 +73,18 @@ int main(int argc, char** argv) /*ma_sound_set_volume(&sound, 0.25f);*/ //ma_sound_set_pitch(&sound, 2.0f); ma_sound_set_pan(&sound, 0.0f); - ma_sound_set_looping(&sound, MA_TRUE); + //ma_sound_set_looping(&sound, MA_TRUE); //ma_sound_seek_to_pcm_frame(&sound, 6000000); //ma_sound_set_start_delay(&sound, 1110); - ma_sound_set_volume(&sound, 0.5f); + ma_sound_set_volume(&sound, 0.0f); //ma_sound_set_fade_point_in_milliseconds(&sound, 0, 0, 1, 0, 2000); //ma_sound_set_fade_point_auto_reset(&sound, 0, MA_FALSE); /* Enable fading around loop transitions. */ //ma_sound_set_fade_point_auto_reset(&sound, 1, MA_FALSE); ma_sound_set_stop_delay(&sound, 1000); ma_sound_start(&sound); - ma_sleep(1000); + //ma_sleep(1000); + ma_sound_set_looping(&sound2, MA_TRUE); ma_sound_set_volume(&sound2, 0.5f); ma_sound_start(&sound2); diff --git a/research/ma_engine.h b/research/ma_engine.h index fa436b27..63b5d6f4 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -2129,6 +2129,12 @@ static ma_bool32 ma_resource_manager_data_buffer_is_busy(ma_resource_manager_dat */ if (pDataBuffer->pNode->data.type == ma_resource_manager_data_buffer_encoding_decoded) { ma_uint64 availableFrames; + + /* If the sound has been fully loaded then we'll never be busy. */ + if (pDataBuffer->pNode->data.decoded.decodedFrameCount == pDataBuffer->pNode->data.decoded.frameCount) { + return MA_FALSE; /* The sound is fully loaded. The buffer will never be busy. */ + } + if (ma_resource_manager_data_buffer_get_available_frames(pDataBuffer, &availableFrames) == MA_SUCCESS) { return availableFrames < requiredFrameCount; }