From 2012c93cc994263d3c2dabde0deeecf3cac92e48 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 29 Aug 2020 20:47:43 +1000 Subject: [PATCH] Add support for customizing the VFS for ma_engine. --- research/ma_engine.c | 9 +++++---- research/ma_engine.h | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index d8a5cd1a..00fd3397 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -44,6 +44,7 @@ int main(int argc, char** argv) resourceManagerConfig = ma_resource_manager_config_init(); //resourceManagerConfig.decodedFormat = ma_format_s16; + resourceManagerConfig.decodedSampleRate = 48000; result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager); if (result != MA_SUCCESS) { printf("Failed to initialize resource manager.\n"); @@ -64,7 +65,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, NULL, &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, NULL, &sound); if (result != MA_SUCCESS) { printf("Failed to load sound: %s\n", argv[1]); ma_engine_uninit(&engine); @@ -72,7 +73,7 @@ int main(int argc, char** argv) } #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) { printf("Failed to load sound: %s\n", argv[1]); ma_engine_uninit(&engine); @@ -101,8 +102,8 @@ int main(int argc, char** argv) //ma_sleep(1000); //ma_sound_set_looping(&sound2, MA_TRUE); - ma_sound_set_volume(&sound2, 0.5f); - ma_sound_start(&sound2); + //ma_sound_set_volume(&sound2, 0.5f); + //ma_sound_start(&sound2); //ma_sleep(2000); printf("Stopping...\n"); diff --git a/research/ma_engine.h b/research/ma_engine.h index c665a9c1..95d1d3fe 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -914,10 +914,10 @@ struct ma_sound_group ma_sound_group* pPrevSibling; ma_sound_group* pNextSibling; ma_sound* pFirstSoundInGroup; - ma_engine_effect effect; /* The main effect for panning, etc. This is set on the mixer at initialisation time. */ + ma_engine_effect effect; /* The main effect for panning, etc. This is set on the mixer at initialisation time. */ ma_mixer mixer; - ma_mutex lock; /* Only used by ma_sound_init_*() and ma_sound_uninit(). Not used in the mixing thread. */ - ma_uint64 runningTimeInEngineFrames; /* The amount of time the sound has been running in engine frames, including start delays. */ + ma_mutex lock; /* Only used by ma_sound_init_*() and ma_sound_uninit(). Not used in the mixing thread. */ + ma_uint64 runningTimeInEngineFrames; /* The amount of time the sound has been running in engine frames, including start delays. */ ma_uint64 startDelayInEngineFrames; ma_uint64 stopDelayInEngineFrames; /* In the engine's sample rate. */ ma_uint64 stopDelayInEngineFramesRemaining; /* The number of frames relative to the engine's clock before the sound is stopped. */ @@ -943,6 +943,7 @@ typedef struct ma_device_id* pPlaybackDeviceID; /* The ID of the playback device to use with the default listener. */ ma_allocation_callbacks allocationCallbacks; ma_bool32 noAutoStart; /* When set to true, requires an explicit call to ma_engine_start(). This is false by default, meaning the engine will be started automatically in ma_engine_init(). */ + ma_vfs* pResourceManagerVFS; /* A pointer to a pre-allocated VFS object to use with the resource manager. This is ignored if pResourceManager is not NULL. */ } ma_engine_config; MA_API ma_engine_config ma_engine_config_init_default(); @@ -5686,6 +5687,7 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng resourceManagerConfig.decodedChannels = 0; /* Leave the decoded channel count as 0 so we can get good spatialization. */ resourceManagerConfig.decodedSampleRate = pEngine->sampleRate; ma_allocation_callbacks_init_copy(&resourceManagerConfig.allocationCallbacks, &pEngine->allocationCallbacks); + resourceManagerConfig.pVFS = pConfig->pResourceManagerVFS; result = ma_resource_manager_init(&resourceManagerConfig, pEngine->pResourceManager); if (result != MA_SUCCESS) {