From 53bbca81b94f7f0f0a6f3befadacb3b632b93f6a Mon Sep 17 00:00:00 2001 From: thedmd Date: Sun, 20 Nov 2022 07:23:20 +0100 Subject: [PATCH 1/5] Remove trailing spaces. --- miniaudio.h | 62 ++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 5e11cb96..64fea2cd 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -38,7 +38,7 @@ A config/init pattern is used throughout the entire library. The idea is that yo object and pass that into the initialization routine. The advantage to this system is that the config object can be initialized with logical defaults and new properties added to it without breaking the API. The config object can be allocated on the stack and does not need to be -maintained after initialization of the corresponding object. +maintained after initialization of the corresponding object. 1.1. Low Level API @@ -363,7 +363,7 @@ initialized. The easiest but least flexible way of playing a sound is like so: This plays what miniaudio calls an "inline" sound. It plays the sound once, and then puts the internal sound up for recycling. The last parameter is used to specify which sound group the sound should be associated with which will be explained later. This particular way of playing a sound is -simple, but lacks flexibility and features. A more flexible way of playing a sound is to first +simple, but lacks flexibility and features. A more flexible way of playing a sound is to first initialize a sound: ```c @@ -822,7 +822,7 @@ retrieved like so: ma_uint32 channels; ma_uint32 sampleRate; ma_channel channelMap[MA_MAX_CHANNELS]; - + result = ma_data_source_get_data_format(pDataSource, &format, &channels, &sampleRate, channelMap, MA_MAX_CHANNELS); if (result != MA_SUCCESS) { return result; // Failed to retrieve data format. @@ -878,7 +878,7 @@ To do this, you can use chaining: ``` In the example above we're using decoders. When reading from a chain, you always want to read from -the top level data source in the chain. In the example above, `decoder1` is the top level data +the top level data source in the chain. In the example above, `decoder1` is the top level data source in the chain. When `decoder1` reaches the end, `decoder2` will start seamlessly without any gaps. @@ -971,7 +971,7 @@ base object (`ma_data_source_base`): void my_data_source_uninit(my_data_source* pMyDataSource) { // ... do the uninitialization of your custom data source here ... - + // You must uninitialize the base data source. ma_data_source_uninit(&pMyDataSource->base); } @@ -2561,7 +2561,7 @@ The `ma_decoding_backend_vtable` vtable has the following functions: ``` onInit - onInitFile + onInitFile onInitFileW onInitMemory onUninit @@ -3689,7 +3689,7 @@ extern "C" { #pragma GCC diagnostic ignored "-Wc11-extensions" /* anonymous unions are a C11 extension */ #endif #endif - + #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__) @@ -4089,7 +4089,7 @@ typedef enum #define MA_MIN_CHANNELS 1 -#ifndef MA_MAX_CHANNELS +#ifndef MA_MAX_CHANNELS #define MA_MAX_CHANNELS 254 #endif @@ -18237,7 +18237,7 @@ static void ma_device__on_data(ma_device* pDevice, void* pFramesOut, const void* /* The intermediary buffer has just been filled. */ pDevice->playback.intermediaryBufferLen = pDevice->playback.intermediaryBufferCap; } - } + } } /* If we're in duplex mode we might need to do a refill of the data. */ @@ -29558,7 +29558,7 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi sampleRate = pDescriptorCapture->sampleRate; } - + result = ma_init_pa_mainloop_and_pa_context__pulse(pDevice->pContext, pDevice->pContext->pulse.pApplicationName, pDevice->pContext->pulse.pServerName, MA_FALSE, &pDevice->pulse.pMainLoop, &pDevice->pulse.pPulseContext); if (result != MA_SUCCESS) { @@ -32696,7 +32696,7 @@ static OSStatus ma_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFla ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "Failed to allocate AudioBufferList for capture.\n"); return noErr; } - + pRenderedBufferList = (AudioBufferList*)pDevice->coreaudio.pAudioBufferList; MA_ASSERT(pRenderedBufferList); @@ -33134,7 +33134,7 @@ static ma_result ma_device__untrack__coreaudio(ma_device* pDevice) */ ma_device__on_notification_interruption_began(m_pDevice); } break; - + case AVAudioSessionInterruptionTypeEnded: { ma_log_postf(ma_device_get_log(m_pDevice), MA_LOG_LEVEL_INFO, "[Core Audio] Interruption: AVAudioSessionInterruptionTypeEnded\n"); @@ -33188,7 +33188,7 @@ static ma_result ma_device__untrack__coreaudio(ma_device* pDevice) } ma_log_postf(ma_device_get_log(m_pDevice), MA_LOG_LEVEL_DEBUG, "[Core Audio] Changing Route. inputNumberChannels=%d; outputNumberOfChannels=%d\n", (int)pSession.inputNumberOfChannels, (int)pSession.outputNumberOfChannels); - + /* Let the application know about the route change. */ ma_device__on_notification_rerouted(m_pDevice); } @@ -33561,7 +33561,7 @@ static ma_result ma_device_init_internal__coreaudio(ma_context* pContext, ma_dev @autoreleasepool { AVAudioSession* pAudioSession = [AVAudioSession sharedInstance]; MA_ASSERT(pAudioSession != NULL); - + [pAudioSession setPreferredIOBufferDuration:((float)actualPeriodSizeInFrames / pAudioSession.sampleRate) error:nil]; actualPeriodSizeInFrames = ma_next_power_of_2((ma_uint32)(pAudioSession.IOBufferDuration * pAudioSession.sampleRate)); } @@ -33802,7 +33802,7 @@ static ma_result ma_device_init__coreaudio(ma_device* pDevice, const ma_device_c #if defined(MA_APPLE_DESKTOP) ma_get_AudioObject_uid(pDevice->pContext, pDevice->coreaudio.deviceObjectIDCapture, sizeof(pDevice->capture.id.coreaudio), pDevice->capture.id.coreaudio); - + /* If we are using the default device we'll need to listen for changes to the system's default device so we can seemlessly switch the device in the background. @@ -33866,7 +33866,7 @@ static ma_result ma_device_init__coreaudio(ma_device* pDevice, const ma_device_c #if defined(MA_APPLE_DESKTOP) ma_get_AudioObject_uid(pDevice->pContext, pDevice->coreaudio.deviceObjectIDPlayback, sizeof(pDevice->playback.id.coreaudio), pDevice->playback.id.coreaudio); - + /* If we are using the default device we'll need to listen for changes to the system's default device so we can seemlessly switch the device in the background. @@ -37454,7 +37454,7 @@ static ma_result ma_context_init__aaudio(ma_context* pContext, const ma_context_ return result; } } - + (void)pConfig; return MA_SUCCESS; @@ -39948,7 +39948,7 @@ MA_API ma_result ma_device_job_thread_init(const ma_device_job_thread_config* pC /* Initialize the job queue before the thread to ensure it's in a valid state. */ - jobQueueConfig = ma_job_queue_config_init(pConfig->jobQueueFlags, pConfig->jobQueueCapacity); + jobQueueConfig = ma_job_queue_config_init(pConfig->jobQueueFlags, pConfig->jobQueueCapacity); result = ma_job_queue_init(&jobQueueConfig, pAllocationCallbacks, &pJobThread->jobQueue); if (result != MA_SUCCESS) { @@ -40756,7 +40756,7 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC if (pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) { ma_uint64 intermediaryBufferSizeInBytes; - + pDevice->playback.intermediaryBufferLen = 0; if (pConfig->deviceType == ma_device_type_duplex) { pDevice->playback.intermediaryBufferCap = pDevice->capture.intermediaryBufferCap; /* In duplex mode, make sure the intermediary buffer is always the same size as the capture side. */ @@ -40768,7 +40768,7 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC } intermediaryBufferSizeInBytes = pDevice->playback.intermediaryBufferCap * ma_get_bytes_per_frame(pDevice->playback.format, pDevice->playback.channels); - + pDevice->playback.pIntermediaryBuffer = ma_malloc((size_t)intermediaryBufferSizeInBytes, &pContext->allocationCallbacks); if (pDevice->playback.pIntermediaryBuffer == NULL) { ma_device_uninit(pDevice); @@ -51983,7 +51983,7 @@ MA_API ma_result ma_channel_converter_init_preallocated(const ma_channel_convert /* We now need to fill out our weights table. This is determined by the mixing mode. */ - + /* In all cases we need to make sure all channels that are present in both channel maps have a 1:1 mapping. */ for (iChannelIn = 0; iChannelIn < pConverter->channelsIn; ++iChannelIn) { ma_channel channelPosIn = ma_channel_map_get_channel(pConverter->pChannelMapIn, pConverter->channelsIn, iChannelIn); @@ -67080,7 +67080,7 @@ MA_API ma_result ma_resource_manager_data_buffer_read_pcm_frames(ma_resource_man pDataBuffer->seekToCursorOnNextRead = MA_TRUE; /* Keep the seek scheduled. We just haven't loaded enough data yet to do the seek properly. */ return MA_BUSY; } - + return result; } } @@ -67626,7 +67626,7 @@ MA_API ma_result ma_resource_manager_data_stream_init(ma_resource_manager* pReso config.pFilePath = pFilePath; config.flags = flags; config.pNotifications = pNotifications; - + return ma_resource_manager_data_stream_init_ex(pResourceManager, &config, pDataStream); } @@ -67638,7 +67638,7 @@ MA_API ma_result ma_resource_manager_data_stream_init_w(ma_resource_manager* pRe config.pFilePathW = pFilePath; config.flags = flags; config.pNotifications = pNotifications; - + return ma_resource_manager_data_stream_init_ex(pResourceManager, &config, pDataStream); } @@ -68751,7 +68751,7 @@ static ma_result ma_job_process__resource_manager__load_data_buffer(ma_job* pJob There is a hole between here and the where the data connector is initialized where the data buffer node may have finished initializing. We need to check for this by checking the result of the data buffer node and whether or not we had an unknown data supply type at the time of - trying to initialize the data connector. + trying to initialize the data connector. */ result = ma_resource_manager_data_buffer_node_result(pDataBuffer->pNode); if (result == MA_BUSY || (result == MA_SUCCESS && isConnectorInitialized == MA_FALSE && dataSupplyType == ma_resource_manager_data_supply_type_unknown)) { @@ -70867,7 +70867,7 @@ static ma_result ma_node_read_pcm_frames(ma_node* pNode, ma_uint32 outputBusInde ma_node_output_bus_set_has_read(&pNodeBase->pOutputBuses[outputBusIndex], MA_TRUE); } } - + /* Apply volume, if necessary. */ ma_apply_volume_factor_f32(pFramesOut, totalFramesRead * ma_node_get_output_channels(pNodeBase, outputBusIndex), ma_node_output_bus_get_volume(&pNodeBase->pOutputBuses[outputBusIndex])); @@ -72470,7 +72470,7 @@ static ma_result ma_engine_node_get_heap_layout(const ma_engine_node_config* pCo /* Resmapler. */ resamplerConfig = ma_linear_resampler_config_init(ma_format_f32, channelsIn, 1, 1); /* Input and output sample rates don't affect the calculation of the heap size. */ resamplerConfig.lpfOrder = 0; - + result = ma_linear_resampler_get_heap_size(&resamplerConfig, &tempHeapSize); if (result != MA_SUCCESS) { return result; /* Failed to retrieve the size of the heap for the resampler. */ @@ -72706,7 +72706,7 @@ MA_API ma_sound_config ma_sound_config_init_2(ma_engine* pEngine) } else { config.monoExpansionMode = ma_mono_expansion_mode_default; } - + config.rangeEndInPCMFrames = ~((ma_uint64)0); config.loopPointEndInPCMFrames = ~((ma_uint64)0); @@ -72814,7 +72814,7 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng #if !defined(MA_NO_DEVICE_IO) { pEngine->pDevice = engineConfig.pDevice; - + /* If we don't have a device, we need one. */ if (pEngine->pDevice == NULL && engineConfig.noDevice == MA_FALSE) { ma_device_config deviceConfig; @@ -73735,7 +73735,7 @@ MA_API ma_result ma_sound_init_from_file(ma_engine* pEngine, const char* pFilePa if (pFilePath == NULL) { return MA_INVALID_ARGS; } - + config = ma_sound_config_init_2(pEngine); config.pFilePath = pFilePath; config.flags = flags; @@ -73752,7 +73752,7 @@ MA_API ma_result ma_sound_init_from_file_w(ma_engine* pEngine, const wchar_t* pF if (pFilePath == NULL) { return MA_INVALID_ARGS; } - + config = ma_sound_config_init_2(pEngine); config.pFilePathW = pFilePath; config.flags = flags; From 9beb89c1e392b94afd6ed3b4f70b71c2048f40bb Mon Sep 17 00:00:00 2001 From: thedmd Date: Sun, 20 Nov 2022 07:25:43 +0100 Subject: [PATCH 2/5] Detect MA_ORBIS and MA_PROSPERO before MA_BSD. Checking for __ORBIS__ and __PROSPERO__ first avoid identifying PS4/PS5 as BSD systems. --- miniaudio.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 64fea2cd..2c1415ab 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -3805,7 +3805,11 @@ typedef ma_uint16 wchar_t; #ifdef __unix__ #define MA_UNIX - #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + #ifdef __ORBIS__ + #define MA_ORBIS + #elif defined(__PROSPERO__) + #define MA_PROSPERO + #elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #define MA_BSD #endif #endif From bf64bc79db8abe5a882ad995b754c778efbf0157 Mon Sep 17 00:00:00 2001 From: thedmd Date: Sun, 20 Nov 2022 07:27:48 +0100 Subject: [PATCH 3/5] Add MA_NO_DLOPEN to disable `ma_dlopen` implementation. --- miniaudio.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 2c1415ab..ca58c257 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -17422,13 +17422,22 @@ DEVICE I/O #ifdef MA_POSIX #include #include +#endif + +#ifndef MA_NO_DLOPEN + #if defined(MA_POSIX) && (defined(MA_ORBIS) || defined(MA_PROSPERO)) + #define MA_NO_DLOPEN + #endif +#endif + +#ifndef MA_NO_DLOPEN #include #endif /* Disable run-time linking on certain backends. */ #ifndef MA_NO_RUNTIME_LINKING - #if defined(MA_EMSCRIPTEN) + #if defined(MA_NO_DLOPEN) || defined(MA_EMSCRIPTEN) #define MA_NO_RUNTIME_LINKING #endif #endif @@ -17968,6 +17977,7 @@ Dynamic Linking *******************************************************************************/ MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename) { +#ifndef MA_NO_DLOPEN ma_handle handle; ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading library: %s\n", filename); @@ -17999,10 +18009,16 @@ MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename) (void)pContext; /* It's possible for pContext to be unused. */ return handle; +#else + (void)pContext; + (void)filename; + return NULL; +#endif } MA_API void ma_dlclose(ma_context* pContext, ma_handle handle) { +#ifndef MA_NO_DLOPEN #ifdef _WIN32 FreeLibrary((HMODULE)handle); #else @@ -18010,10 +18026,15 @@ MA_API void ma_dlclose(ma_context* pContext, ma_handle handle) #endif (void)pContext; +#else + (void)pContext; + (void)handle; +#endif } MA_API ma_proc ma_dlsym(ma_context* pContext, ma_handle handle, const char* symbol) { +#ifndef MA_NO_DLOPEN ma_proc proc; ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading symbol: %s\n", symbol); @@ -18037,6 +18058,12 @@ MA_API ma_proc ma_dlsym(ma_context* pContext, ma_handle handle, const char* symb (void)pContext; /* It's possible for pContext to be unused. */ return proc; +#else + (void)pContext; + (void)handle; + (void)symbol; + return NULL; +#endif } From 8eec6da4911af05ee270ace702121b85e6a63e29 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 20 Nov 2022 17:54:02 +1000 Subject: [PATCH 4/5] Unify the MA_NO_DLOPEN and MA_NO_RUNTIME_LINKING options. --- miniaudio.h | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index ca58c257..1711f4fa 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -17404,6 +17404,14 @@ DEVICE I/O ************************************************************************************************************************************************************* ************************************************************************************************************************************************************/ + +/* Disable run-time linking on certain backends and platforms. */ +#ifndef MA_NO_RUNTIME_LINKING + #if defined(MA_EMSCRIPTEN) || defined(MA_ORBIS) || defined(MA_PROSPERO) + #define MA_NO_RUNTIME_LINKING + #endif +#endif + #ifndef MA_NO_DEVICE_IO #ifdef MA_WIN32 #include @@ -17422,25 +17430,13 @@ DEVICE I/O #ifdef MA_POSIX #include #include -#endif -#ifndef MA_NO_DLOPEN - #if defined(MA_POSIX) && (defined(MA_ORBIS) || defined(MA_PROSPERO)) - #define MA_NO_DLOPEN + /* No need for dlfcn.h if we're not using runtime linking. */ + #ifndef MA_NO_RUNTIME_LINKING + #include #endif #endif -#ifndef MA_NO_DLOPEN - #include -#endif - - -/* Disable run-time linking on certain backends. */ -#ifndef MA_NO_RUNTIME_LINKING - #if defined(MA_NO_DLOPEN) || defined(MA_EMSCRIPTEN) - #define MA_NO_RUNTIME_LINKING - #endif -#endif MA_API void ma_device_info_add_native_data_format(ma_device_info* pDeviceInfo, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 flags) @@ -17977,7 +17973,7 @@ Dynamic Linking *******************************************************************************/ MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename) { -#ifndef MA_NO_DLOPEN +#ifndef MA_NO_RUNTIME_LINKING ma_handle handle; ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading library: %s\n", filename); @@ -18010,6 +18006,7 @@ MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename) (void)pContext; /* It's possible for pContext to be unused. */ return handle; #else + /* Runtime linking is disabled. */ (void)pContext; (void)filename; return NULL; @@ -18018,7 +18015,7 @@ MA_API ma_handle ma_dlopen(ma_context* pContext, const char* filename) MA_API void ma_dlclose(ma_context* pContext, ma_handle handle) { -#ifndef MA_NO_DLOPEN +#ifndef MA_NO_RUNTIME_LINKING #ifdef _WIN32 FreeLibrary((HMODULE)handle); #else @@ -18027,6 +18024,7 @@ MA_API void ma_dlclose(ma_context* pContext, ma_handle handle) (void)pContext; #else + /* Runtime linking is disabled. */ (void)pContext; (void)handle; #endif @@ -18034,7 +18032,7 @@ MA_API void ma_dlclose(ma_context* pContext, ma_handle handle) MA_API ma_proc ma_dlsym(ma_context* pContext, ma_handle handle, const char* symbol) { -#ifndef MA_NO_DLOPEN +#ifndef MA_NO_RUNTIME_LINKING ma_proc proc; ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_DEBUG, "Loading symbol: %s\n", symbol); @@ -18059,6 +18057,7 @@ MA_API ma_proc ma_dlsym(ma_context* pContext, ma_handle handle, const char* symb (void)pContext; /* It's possible for pContext to be unused. */ return proc; #else + /* Runtime linking is disabled. */ (void)pContext; (void)handle; (void)symbol; From a1024dde4963da853f83d4c82951e751b34483b4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 20 Nov 2022 20:15:14 +1000 Subject: [PATCH 5/5] Don't treat some platforms as Unix. --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 1711f4fa..807e9d71 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -6217,7 +6217,7 @@ This section contains the APIs for device playback and capture. Here is where yo #define MA_SUPPORT_JACK /* JACK is technically supported on Windows, but I don't know how many people use it in practice... */ #endif #endif -#if defined(MA_UNIX) +#if defined(MA_UNIX) && !defined(MA_ORBIS) && !defined(MA_PROSPERO) #if defined(MA_LINUX) #if !defined(MA_ANDROID) /* ALSA is not supported on Android. */ #define MA_SUPPORT_ALSA