Commit dc0ca707 authored by David Reid's avatar David Reid

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.
parent 9e6042f6
...@@ -50,6 +50,8 @@ int main(int argc, char** argv) ...@@ -50,6 +50,8 @@ int main(int argc, char** argv)
resourceManagerConfig.decodedFormat = ma_format_f32; resourceManagerConfig.decodedFormat = ma_format_f32;
//resourceManagerConfig.decodedChannels = 2; //resourceManagerConfig.decodedChannels = 2;
resourceManagerConfig.decodedSampleRate = 48000; resourceManagerConfig.decodedSampleRate = 48000;
//resourceManagerConfig.flags |= MA_RESOURCE_MANAGER_FLAG_NO_THREADING;
resourceManagerConfig.jobThreadCount = 1;
result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager); result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
printf("Failed to initialize resource manager.\n"); printf("Failed to initialize resource manager.\n");
...@@ -76,7 +78,7 @@ int main(int argc, char** argv) ...@@ -76,7 +78,7 @@ int main(int argc, char** argv)
loadNotification.cb.onSignal = on_sound_loaded; loadNotification.cb.onSignal = on_sound_loaded;
loadNotification.pSound = &sound; 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) { 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);
...@@ -96,7 +98,7 @@ int main(int argc, char** argv) ...@@ -96,7 +98,7 @@ int main(int argc, char** argv)
/*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/ /*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_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_start_time(ma_engine_get_master_sound_group(&engine), 2000);
//ma_sound_group_set_fade_in_milliseconds(&group, 0, 1, 5000); //ma_sound_group_set_fade_in_milliseconds(&group, 0, 1, 5000);
//ma_sound_group_stop(&group); //ma_sound_group_stop(&group);
...@@ -124,7 +126,7 @@ int main(int argc, char** argv) ...@@ -124,7 +126,7 @@ int main(int argc, char** argv)
//ma_sound_start(&sound2); //ma_sound_start(&sound2);
//ma_sleep(2000); //ma_sleep(2000);
printf("Stopping...\n"); //printf("Stopping...\n");
//ma_sound_stop(&sound); //ma_sound_stop(&sound);
//ma_sound_group_stop(ma_engine_get_master_sound_group(&engine)); //ma_sound_group_stop(ma_engine_get_master_sound_group(&engine));
#endif #endif
...@@ -135,6 +137,13 @@ int main(int argc, char** argv) ...@@ -135,6 +137,13 @@ int main(int argc, char** argv)
ma_engine_play_sound(&engine, argv[3], NULL);*/ ma_engine_play_sound(&engine, argv[3], NULL);*/
#endif #endif
#if 0
for (;;) {
ma_resource_manager_process_next_job(&resourceManager);
ma_sleep(5);
}
#endif
#if 0 #if 0
float pitch = 1; float pitch = 1;
float pitchStep = 0.01f; float pitchStep = 0.01f;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment