Commit 63cdc5ef authored by David Reid's avatar David Reid

Improvements to the OpenAL backend.

parent ac00f058
...@@ -244,12 +244,13 @@ extern "C" { ...@@ -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 ...@@ -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) ...@@ -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,35 +8029,55 @@ mal_result mal_enumerate_devices__openal(mal_context* pContext, mal_device_type ...@@ -8031,35 +8029,55 @@ mal_result mal_enumerate_devices__openal(mal_context* pContext, mal_device_type
mal_uint32 infoSize = *pCount; mal_uint32 infoSize = *pCount;
*pCount = 0; *pCount = 0;
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 (pContext->openal.isEnumerationSupported) {
if (pDeviceNames == NULL) { const mal_ALCchar* pDeviceNames = ((MAL_LPALCGETSTRING)pContext->openal.alcGetString)(NULL, (type == mal_device_type_playback) ? MAL_ALC_DEVICE_SPECIFIER : MAL_ALC_CAPTURE_DEVICE_SPECIFIER);
return MAL_NO_DEVICE; if (pDeviceNames == NULL) {
} return MAL_NO_DEVICE;
}
// Each device is stored in pDeviceNames, separated by a null-terminator. The string itself is double-null-terminated. // Each device is stored in pDeviceNames, separated by a null-terminator. The string itself is double-null-terminated.
const mal_ALCchar* pNextDeviceName = pDeviceNames; const mal_ALCchar* pNextDeviceName = pDeviceNames;
while (pNextDeviceName[0] != '\0') { while (pNextDeviceName[0] != '\0') {
if (pInfo != NULL) {
if (infoSize > 0) {
mal_strncpy_s(pInfo->id.openal, sizeof(pInfo->id.openal), (const char*)pNextDeviceName, (size_t)-1);
mal_strncpy_s(pInfo->name, sizeof(pInfo->name), (const char*)pNextDeviceName, (size_t)-1);
pInfo += 1;
infoSize -= 1;
*pCount += 1;
}
} else {
*pCount += 1;
}
// Move to the next device name.
while (*pNextDeviceName != '\0') {
pNextDeviceName += 1;
}
// Skip past the null terminator.
pNextDeviceName += 1;
};
} else {
// Enumeration is not supported. Use default devices.
if (pInfo != NULL) { if (pInfo != NULL) {
if (infoSize > 0) { if (infoSize > 0) {
mal_strncpy_s(pInfo->id.openal, sizeof(pInfo->id.openal), (const char*)pNextDeviceName, (size_t)-1); if (type == mal_device_type_playback) {
mal_strncpy_s(pInfo->name, sizeof(pInfo->name), (const char*)pNextDeviceName, (size_t)-1); 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; pInfo += 1;
infoSize -= 1;
*pCount += 1; *pCount += 1;
} }
} else { } else {
*pCount += 1; *pCount += 1;
} }
}
// Move to the next device name.
while (*pNextDeviceName != '\0') {
pNextDeviceName += 1;
}
// Skip past the null terminator.
pNextDeviceName += 1;
};
return MAL_SUCCESS; return MAL_SUCCESS;
} }
...@@ -8137,7 +8155,7 @@ mal_result mal_device_init__openal(mal_context* pContext, mal_device_type type, ...@@ -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;
......
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