diff --git a/research/ma_engine.c b/research/ma_engine.c index edcc61b5..d8a5cd1a 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -71,12 +71,14 @@ int main(int argc, char** argv) return -1; } +#if 1 result = ma_sound_init_from_file(&engine, argv[1], MA_DATA_SOURCE_FLAG_DECODE | MA_DATA_SOURCE_FLAG_ASYNC /*| MA_DATA_SOURCE_FLAG_STREAM*/, &loadNotification, NULL, &sound2); if (result != MA_SUCCESS) { printf("Failed to load sound: %s\n", argv[1]); ma_engine_uninit(&engine); return -1; } +#endif /*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/ @@ -90,11 +92,11 @@ int main(int argc, char** argv) //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.0f); + ma_sound_set_volume(&sound, 0.5f); //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_set_stop_delay(&sound, 1000); ma_sound_start(&sound); //ma_sleep(1000); diff --git a/research/ma_engine.h b/research/ma_engine.h index cd643d4d..c665a9c1 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -1021,6 +1021,7 @@ MA_API ma_result ma_sound_group_set_fade_point_in_milliseconds(ma_sound_group* p MA_API ma_result ma_sound_group_set_fade_point_auto_reset(ma_sound_group* pGroup, ma_uint32 fadePointIndex, ma_bool32 autoReset); MA_API ma_result ma_sound_group_set_start_delay(ma_sound_group* pGroup, ma_uint64 delayInMilliseconds); MA_API ma_result ma_sound_group_set_stop_delay(ma_sound_group* pGroup, ma_uint64 delayInMilliseconds); +MA_API ma_bool32 ma_sound_group_is_playing(const ma_sound_group* pGroup); MA_API ma_result ma_sound_group_get_time_in_frames(const ma_sound_group* pGroup, ma_uint64* pTimeInFrames); #ifdef __cplusplus @@ -3960,11 +3961,14 @@ static ma_result ma_resource_manager_process_job__page_data_buffer(ma_resource_m pDataBuffer->pNode->data.decoded.decodedFrameCount += framesRead; } - /* If there's more to decode, post a job to keep decoding. */ - if (result != MA_AT_END) { - jobCopy.pageDataBuffer.decodedFrameCount += framesRead; - jobCopy.order = ma_resource_manager_data_buffer_next_execution_order(pDataBuffer); /* We need a fresh execution order. */ + /* + If there's more to decode, post a job to keep decoding. Note that we always increment the decoded frame count in the copy of the job because it'll be + referenced below and we'll need to know the new frame count. + */ + jobCopy.pageDataBuffer.decodedFrameCount += framesRead; + if (result != MA_AT_END) { + jobCopy.order = ma_resource_manager_data_buffer_next_execution_order(pDataBuffer); /* We need a fresh execution order. */ result = ma_resource_manager_post_job(pResourceManager, &jobCopy); } } @@ -5328,6 +5332,12 @@ static void ma_engine_mix_sound(ma_engine* pEngine, ma_sound_group* pGroup, ma_s ma_result result = MA_SUCCESS; ma_uint64 framesProcessed; + /* If we're marked at the end we need to stop the sound and do nothing. */ + if (pSound->atEnd) { + ma_sound_stop_internal(pSound); + return; + } + /* If we're seeking, do so now before reading. */ if (pSound->seekTarget != MA_SEEK_TARGET_NONE) { pSound->seekTarget = MA_SEEK_TARGET_NONE; @@ -5359,7 +5369,6 @@ static void ma_engine_mix_sound(ma_engine* pEngine, ma_sound_group* pGroup, ma_s /* If we reached the end of the sound we'll want to mark it as at the end and stop it. This should never be returned for looping sounds. */ if (result == MA_AT_END) { - ma_sound_stop_internal(pSound); c89atomic_exchange_32(&pSound->atEnd, MA_TRUE); /* This will be set to false in ma_sound_start(). */ } @@ -6152,6 +6161,9 @@ MA_API ma_result ma_sound_start(ma_sound* pSound) if (result != MA_SUCCESS) { return result; /* Failed to seek back to the start. */ } + + /* Make sure we clear the end indicator. */ + pSound->atEnd = MA_FALSE; } /* Once everything is set up we can tell the mixer thread about it. */ @@ -6759,6 +6771,15 @@ MA_API ma_result ma_sound_group_set_stop_delay(ma_sound_group* pGroup, ma_uint64 return MA_SUCCESS; } +MA_API ma_bool32 ma_sound_group_is_playing(const ma_sound_group* pGroup) +{ + if (pGroup == NULL) { + return MA_FALSE; + } + + return pGroup->isPlaying; +} + MA_API ma_result ma_sound_group_get_time_in_frames(const ma_sound_group* pGroup, ma_uint64* pTimeInFrames) { if (pTimeInFrames == NULL) {