Add support for running the resource manager without a job thread.

This is useful for platforms that do not have support for threading or
programs that do not want to use an extra thread for resource
management and would rather process jobs manually.

When configuring the resource manager to not use threading, the
MA_RESOURCE_MANAGER_FLAG_NO_THREADING flag must be set in the config.
This implicitly enables the MA_RESOURCE_MANAGER_FLAG_NON_BLOCKING flag
because it requires programs to manually call
ma_resource_manager_process_next_job(), and since it's assumed that
won't ever be called from another thread, you'd never want that to be
blocking.

This sets up a framework for getting the resource manager working with
Emscripten.
This commit is contained in:
David Reid
2021-01-17 13:41:09 +10:00
parent 9e6042f698
commit dc0ca7072b
2 changed files with 227 additions and 56 deletions
+12 -3
View File
@@ -50,6 +50,8 @@ int main(int argc, char** argv)
resourceManagerConfig.decodedFormat = ma_format_f32;
//resourceManagerConfig.decodedChannels = 2;
resourceManagerConfig.decodedSampleRate = 48000;
//resourceManagerConfig.flags |= MA_RESOURCE_MANAGER_FLAG_NO_THREADING;
resourceManagerConfig.jobThreadCount = 1;
result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager);
if (result != MA_SUCCESS) {
printf("Failed to initialize resource manager.\n");
@@ -76,7 +78,7 @@ int main(int argc, char** argv)
loadNotification.cb.onSignal = on_sound_loaded;
loadNotification.pSound = &sound;
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, &group, &sound);
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, &group, &sound);
if (result != MA_SUCCESS) {
printf("Failed to load sound: %s\n", argv[1]);
ma_engine_uninit(&engine);
@@ -96,7 +98,7 @@ int main(int argc, char** argv)
/*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/
//ma_sound_group_set_pan(ma_engine_get_master_sound_group(&engine), -1);
ma_sound_group_set_pitch(&group, 1.1f);
ma_sound_group_set_pitch(&group, 1.25f);
//ma_sound_group_set_start_time(ma_engine_get_master_sound_group(&engine), 2000);
//ma_sound_group_set_fade_in_milliseconds(&group, 0, 1, 5000);
//ma_sound_group_stop(&group);
@@ -124,7 +126,7 @@ int main(int argc, char** argv)
//ma_sound_start(&sound2);
//ma_sleep(2000);
printf("Stopping...\n");
//printf("Stopping...\n");
//ma_sound_stop(&sound);
//ma_sound_group_stop(ma_engine_get_master_sound_group(&engine));
#endif
@@ -135,6 +137,13 @@ int main(int argc, char** argv)
ma_engine_play_sound(&engine, argv[3], NULL);*/
#endif
#if 0
for (;;) {
ma_resource_manager_process_next_job(&resourceManager);
ma_sleep(5);
}
#endif
#if 0
float pitch = 1;
float pitchStep = 0.01f;