mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Only set the isPlaying flag when the audio has finished playing.
This commit is contained in:
@@ -71,12 +71,14 @@ int main(int argc, char** argv)
|
|||||||
return -1;
|
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);
|
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) {
|
if (result != MA_SUCCESS) {
|
||||||
printf("Failed to load sound: %s\n", argv[1]);
|
printf("Failed to load sound: %s\n", argv[1]);
|
||||||
ma_engine_uninit(&engine);
|
ma_engine_uninit(&engine);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/
|
/*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_set_looping(&sound, MA_TRUE);
|
||||||
//ma_sound_seek_to_pcm_frame(&sound, 6000000);
|
//ma_sound_seek_to_pcm_frame(&sound, 6000000);
|
||||||
//ma_sound_set_start_delay(&sound, 1110);
|
//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_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, 0, MA_FALSE); /* Enable fading around loop transitions. */
|
||||||
//ma_sound_set_fade_point_auto_reset(&sound, 1, MA_FALSE);
|
//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_sound_start(&sound);
|
||||||
|
|
||||||
//ma_sleep(1000);
|
//ma_sleep(1000);
|
||||||
|
|||||||
+25
-4
@@ -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_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_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_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);
|
MA_API ma_result ma_sound_group_get_time_in_frames(const ma_sound_group* pGroup, ma_uint64* pTimeInFrames);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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;
|
pDataBuffer->pNode->data.decoded.decodedFrameCount += framesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there's more to decode, post a job to keep decoding. */
|
/*
|
||||||
if (result != MA_AT_END) {
|
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;
|
jobCopy.pageDataBuffer.decodedFrameCount += framesRead;
|
||||||
jobCopy.order = ma_resource_manager_data_buffer_next_execution_order(pDataBuffer); /* We need a fresh execution order. */
|
|
||||||
|
|
||||||
|
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);
|
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_result result = MA_SUCCESS;
|
||||||
ma_uint64 framesProcessed;
|
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 we're seeking, do so now before reading. */
|
||||||
if (pSound->seekTarget != MA_SEEK_TARGET_NONE) {
|
if (pSound->seekTarget != MA_SEEK_TARGET_NONE) {
|
||||||
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 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) {
|
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(). */
|
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) {
|
if (result != MA_SUCCESS) {
|
||||||
return result; /* Failed to seek back to the start. */
|
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. */
|
/* 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;
|
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)
|
MA_API ma_result ma_sound_group_get_time_in_frames(const ma_sound_group* pGroup, ma_uint64* pTimeInFrames)
|
||||||
{
|
{
|
||||||
if (pTimeInFrames == NULL) {
|
if (pTimeInFrames == NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user