mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Improvements to the OpenAL backend.
This commit is contained in:
@@ -244,12 +244,13 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAL_SUPPORT_SDL // All platforms support SDL.
|
||||||
|
|
||||||
// Explicitly disable OpenAL and Null backends for Emscripten because they both use a background thread which is not properly supported right now.
|
// Explicitly disable OpenAL and Null backends for Emscripten because they both use a background thread which is not properly supported right now.
|
||||||
#if !defined(MAL_EMSCRIPTEN)
|
#if !defined(MAL_EMSCRIPTEN)
|
||||||
#define MAL_SUPPORT_OPENAL
|
#define MAL_SUPPORT_OPENAL
|
||||||
#define MAL_SUPPORT_NULL // All platforms support the null backend.
|
#define MAL_SUPPORT_NULL // All platforms support the null backend.
|
||||||
#endif
|
#endif
|
||||||
#define MAL_SUPPORT_SDL // All platforms support SDL.
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(MAL_NO_WASAPI) && defined(MAL_SUPPORT_WASAPI)
|
#if !defined(MAL_NO_WASAPI) && defined(MAL_SUPPORT_WASAPI)
|
||||||
@@ -862,8 +863,9 @@ struct mal_context
|
|||||||
mal_proc alGetBuffer3i;
|
mal_proc alGetBuffer3i;
|
||||||
mal_proc alGetBufferiv;
|
mal_proc alGetBufferiv;
|
||||||
|
|
||||||
mal_uint32 isFloat32Supported : 1;
|
mal_bool32 isEnumerationSupported : 1;
|
||||||
mal_uint32 isMCFormatsSupported : 1;
|
mal_bool32 isFloat32Supported : 1;
|
||||||
|
mal_bool32 isMCFormatsSupported : 1;
|
||||||
} openal;
|
} openal;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MAL_SUPPORT_SDL
|
#ifdef MAL_SUPPORT_SDL
|
||||||
@@ -8002,12 +8004,8 @@ mal_result mal_context_init__openal(mal_context* pContext)
|
|||||||
pContext->openal.alGetBufferiv = (mal_proc)alGetBufferiv;
|
pContext->openal.alGetBufferiv = (mal_proc)alGetBufferiv;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We depend on the ALC_ENUMERATION_EXT extension.
|
// We depend on the ALC_ENUMERATION_EXT extension for enumeration. If this is not supported we fall back to default devices.
|
||||||
if (!((MAL_LPALCISEXTENSIONPRESENT)pContext->openal.alcIsExtensionPresent)(NULL, "ALC_ENUMERATION_EXT")) {
|
pContext->openal.isEnumerationSupported = ((MAL_LPALCISEXTENSIONPRESENT)pContext->openal.alcIsExtensionPresent)(NULL, "ALC_ENUMERATION_EXT");
|
||||||
mal_dlclose(pContext->openal.hOpenAL);
|
|
||||||
return MAL_FAILED_TO_INIT_BACKEND;
|
|
||||||
}
|
|
||||||
|
|
||||||
pContext->openal.isFloat32Supported = ((MAL_LPALISEXTENSIONPRESENT)pContext->openal.alIsExtensionPresent)("AL_EXT_float32");
|
pContext->openal.isFloat32Supported = ((MAL_LPALISEXTENSIONPRESENT)pContext->openal.alIsExtensionPresent)("AL_EXT_float32");
|
||||||
pContext->openal.isMCFormatsSupported = ((MAL_LPALISEXTENSIONPRESENT)pContext->openal.alIsExtensionPresent)("AL_EXT_MCFORMATS");
|
pContext->openal.isMCFormatsSupported = ((MAL_LPALISEXTENSIONPRESENT)pContext->openal.alIsExtensionPresent)("AL_EXT_MCFORMATS");
|
||||||
|
|
||||||
@@ -8031,6 +8029,7 @@ mal_result mal_enumerate_devices__openal(mal_context* pContext, mal_device_type
|
|||||||
mal_uint32 infoSize = *pCount;
|
mal_uint32 infoSize = *pCount;
|
||||||
*pCount = 0;
|
*pCount = 0;
|
||||||
|
|
||||||
|
if (pContext->openal.isEnumerationSupported) {
|
||||||
const mal_ALCchar* pDeviceNames = ((MAL_LPALCGETSTRING)pContext->openal.alcGetString)(NULL, (type == mal_device_type_playback) ? MAL_ALC_DEVICE_SPECIFIER : MAL_ALC_CAPTURE_DEVICE_SPECIFIER);
|
const mal_ALCchar* pDeviceNames = ((MAL_LPALCGETSTRING)pContext->openal.alcGetString)(NULL, (type == mal_device_type_playback) ? MAL_ALC_DEVICE_SPECIFIER : MAL_ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||||
if (pDeviceNames == NULL) {
|
if (pDeviceNames == NULL) {
|
||||||
return MAL_NO_DEVICE;
|
return MAL_NO_DEVICE;
|
||||||
@@ -8060,6 +8059,25 @@ mal_result mal_enumerate_devices__openal(mal_context* pContext, mal_device_type
|
|||||||
// Skip past the null terminator.
|
// Skip past the null terminator.
|
||||||
pNextDeviceName += 1;
|
pNextDeviceName += 1;
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
// Enumeration is not supported. Use default devices.
|
||||||
|
if (pInfo != NULL) {
|
||||||
|
if (infoSize > 0) {
|
||||||
|
if (type == mal_device_type_playback) {
|
||||||
|
pInfo->id.sdl = 0;
|
||||||
|
mal_strncpy_s(pInfo->name, sizeof(pInfo->name), "Default Playback Device", (size_t)-1);
|
||||||
|
} else {
|
||||||
|
pInfo->id.sdl = 0;
|
||||||
|
mal_strncpy_s(pInfo->name, sizeof(pInfo->name), "Default Capture Device", (size_t)-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo += 1;
|
||||||
|
*pCount += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*pCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return MAL_SUCCESS;
|
return MAL_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -8137,7 +8155,7 @@ mal_result mal_device_init__openal(mal_context* pContext, mal_device_type type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (formatAL == 0) {
|
if (formatAL == 0) {
|
||||||
return MAL_FORMAT_NOT_SUPPORTED;
|
return mal_context_post_error(pContext, NULL, "[OpenAL] Format not supported.", MAL_FORMAT_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferSizeInSamplesAL *= channelsAL;
|
bufferSizeInSamplesAL *= channelsAL;
|
||||||
|
|||||||
Reference in New Issue
Block a user