Rename the SDL backend to SDL2.

This distinction is needed because we'll be doing an SDL3 backend in the
future.
This commit is contained in:
David Reid
2026-01-03 13:50:48 +10:00
parent 23c3277754
commit 3df99ce51d
5 changed files with 111 additions and 105 deletions
+7 -1
View File
@@ -291,6 +291,9 @@ endif()
if(MINIAUDIO_NO_NULL) if(MINIAUDIO_NO_NULL)
list(APPEND COMPILE_DEFINES MA_NO_NULL) list(APPEND COMPILE_DEFINES MA_NO_NULL)
endif() endif()
if(MINIAUDIO_NO_SDL2)
list(APPEND COMPILE_DEFINES MA_NO_SDL2)
endif()
if(MINIAUDIO_ENABLE_ONLY_SPECIFIC_BACKENDS) if(MINIAUDIO_ENABLE_ONLY_SPECIFIC_BACKENDS)
list(APPEND COMPILE_DEFINES MA_ENABLE_ONLY_SPECIFIC_BACKENDS) list(APPEND COMPILE_DEFINES MA_ENABLE_ONLY_SPECIFIC_BACKENDS)
@@ -339,6 +342,9 @@ if(MINIAUDIO_ENABLE_ONLY_SPECIFIC_BACKENDS)
if(MINIAUDIO_ENABLE_NULL) if(MINIAUDIO_ENABLE_NULL)
list(APPEND COMPILE_DEFINES MA_ENABLE_NULL) list(APPEND COMPILE_DEFINES MA_ENABLE_NULL)
endif() endif()
if(MINIAUDIO_ENABLE_SDL2)
list(APPEND COMPILE_DEFINES MA_ENABLE_SDL2)
endif()
endif() endif()
if(MINIAUDIO_NO_DECODING) if(MINIAUDIO_NO_DECODING)
list(APPEND COMPILE_DEFINES MA_NO_DECODING) list(APPEND COMPILE_DEFINES MA_NO_DECODING)
@@ -775,7 +781,7 @@ if(MINIAUDIO_NO_RUNTIME_LINKING)
if(NOT TARGET PkgConfig::SDL2) if(NOT TARGET PkgConfig::SDL2)
message(STATUS "Disabling SDL2 backend for tests because SDL2 development files were not found.") message(STATUS "Disabling SDL2 backend for tests because SDL2 development files were not found.")
target_compile_definitions(miniaudio_test INTERFACE MA_NO_SDL2 MA_NO_SDL) # TODO: Remove MA_NO_SDL once this has been renamed to MA_NO_SDL2 in miniaudio_sdl2.c. target_compile_definitions(miniaudio_test INTERFACE MA_NO_SDL2)
endif() endif()
endif() endif()
+6 -6
View File
@@ -57,8 +57,8 @@ int main(int argc, char** argv)
defining it here just for the sake of demonstration. Whether or not this is required depends on the backend. If you're not sure, defining it here just for the sake of demonstration. Whether or not this is required depends on the backend. If you're not sure,
check the documentation for the backend. check the documentation for the backend.
*/ */
ma_context_config_sdl sdlContextConfig = ma_context_config_sdl_init(); ma_context_config_sdl2 sdl2ContextConfig = ma_context_config_sdl2_init();
sdlContextConfig._unused = 0; sdl2ContextConfig._unused = 0;
/* /*
You must include an entry for each backend you're using, even if the config is NULL. This is how miniaudio knows about You must include an entry for each backend you're using, even if the config is NULL. This is how miniaudio knows about
@@ -69,7 +69,7 @@ int main(int argc, char** argv)
*/ */
ma_device_backend_config backends[] = ma_device_backend_config backends[] =
{ {
{ ma_device_backend_sdl, &sdlContextConfig }, { ma_device_backend_sdl2, &sdl2ContextConfig },
{ ma_device_backend_wasapi, NULL }, { ma_device_backend_wasapi, NULL },
{ ma_device_backend_pulseaudio, NULL } { ma_device_backend_pulseaudio, NULL }
}; };
@@ -89,15 +89,15 @@ int main(int argc, char** argv)
Just like with context configs, we can define some device-level configs as well. It works the same way, except you will pass in Just like with context configs, we can define some device-level configs as well. It works the same way, except you will pass in
a backend-specific device-level config. If the backend doesn't require a device-level config, you can set this to NULL. a backend-specific device-level config. If the backend doesn't require a device-level config, you can set this to NULL.
*/ */
ma_device_config_sdl sdlDeviceConfig = ma_device_config_sdl_init(); ma_device_config_sdl2 sdl2DeviceConfig = ma_device_config_sdl2_init();
sdlDeviceConfig._unused = 0; sdl2DeviceConfig._unused = 0;
/* /*
Unlike with contexts, if your backend does not require a device-level config, you can just leave it out of this list entirely. Unlike with contexts, if your backend does not require a device-level config, you can just leave it out of this list entirely.
*/ */
ma_device_backend_config pBackendDeviceConfigs[] = ma_device_backend_config pBackendDeviceConfigs[] =
{ {
{ ma_device_backend_sdl, &sdlDeviceConfig }, { ma_device_backend_sdl2, &sdl2DeviceConfig },
{ ma_device_backend_wasapi, NULL }, { ma_device_backend_wasapi, NULL },
{ ma_device_backend_pulseaudio, NULL } { ma_device_backend_pulseaudio, NULL }
}; };
+88 -88
View File
@@ -1,11 +1,11 @@
/* /*
This implements a full-featured SDL2 backend. It's intentionally built using the same paradigms as the built-in backends in order to make This implements a full-featured SDL2 backend. It's intentionally built using the same paradigms as the built-in backends in order to make
it suitable as a solid basis for a custom implementation. The SDL2 backend can be disabled with MA_NO_SDL, exactly like the built-in it suitable as a solid basis for a custom implementation. The SDL2 backend can be disabled with MA_NO_SDL2, exactly like the built-in
backends. It supports both runtime and compile-time linking and respects the MA_NO_RUNTIME_LINKING option. It also works on Emscripten backends. It supports both runtime and compile-time linking and respects the MA_NO_RUNTIME_LINKING option. It also works on Emscripten
which requires the `-s USE_SDL=2` option. which requires the `-s USE_SDL=2` option.
*/ */
#ifndef miniaudio_backend_sdl_c #ifndef miniaudio_backend_sdl2_c
#define miniaudio_backend_sdl_c #define miniaudio_backend_sdl2_c
/* Include miniaudio.h if we're not including this file after the implementation. */ /* Include miniaudio.h if we're not including this file after the implementation. */
#if !defined(MINIAUDIO_IMPLEMENTATION) && !defined(MA_IMPLEMENTATION) #if !defined(MINIAUDIO_IMPLEMENTATION) && !defined(MA_IMPLEMENTATION)
@@ -17,32 +17,32 @@ which requires the `-s USE_SDL=2` option.
#include <string.h> /* memset() */ #include <string.h> /* memset() */
#include <assert.h> #include <assert.h>
#ifndef MA_SDL_ASSERT #ifndef MA_SDL2_ASSERT
#define MA_SDL_ASSERT(cond) assert(cond) #define MA_SDL2_ASSERT(cond) assert(cond)
#endif #endif
/* Support SDL on everything. */ /* Support SDL on everything. */
#define MA_SUPPORT_SDL #define MA_SUPPORT_SDL2
/* /*
Only enable SDL if it's hasn't been explicitly disabled (MA_NO_SDL) or enabled (MA_ENABLE_SDL with Only enable SDL if it's hasn't been explicitly disabled (MA_NO_SDL2) or enabled (MA_ENABLE_SDL with
MA_ENABLE_ONLY_SPECIFIC_BACKENDS) and it's supported at compile time (MA_SUPPORT_SDL). MA_ENABLE_ONLY_SPECIFIC_BACKENDS) and it's supported at compile time (MA_SUPPORT_SDL).
*/ */
#if defined(MA_SUPPORT_SDL) && !defined(MA_NO_SDL) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_SDL)) #if defined(MA_SUPPORT_SDL2) && !defined(MA_NO_SDL2) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_SDL2))
#define MA_HAS_SDL #define MA_HAS_SDL2
#endif #endif
/* SDL headers are necessary if using compile-time linking. Necessary for Emscripten. */ /* SDL headers are necessary if using compile-time linking. Necessary for Emscripten. */
#if defined(MA_HAS_SDL) #if defined(MA_HAS_SDL2)
#if defined(MA_NO_RUNTIME_LINKING) || defined(MA_EMSCRIPTEN) #if defined(MA_NO_RUNTIME_LINKING) || defined(MA_EMSCRIPTEN)
#ifdef __has_include #ifdef __has_include
#ifdef MA_EMSCRIPTEN #ifdef MA_EMSCRIPTEN
#if !__has_include(<SDL/SDL_audio.h>) #if !__has_include(<SDL/SDL_audio.h>)
#undef MA_HAS_SDL #undef MA_HAS_SDL2
#endif #endif
#else #else
#if !__has_include(<SDL2/SDL_audio.h>) #if !__has_include(<SDL2/SDL_audio.h>)
#undef MA_HAS_SDL #undef MA_HAS_SDL2
#endif #endif
#endif #endif
#endif #endif
@@ -50,7 +50,7 @@ MA_ENABLE_ONLY_SPECIFIC_BACKENDS) and it's supported at compile time (MA_SUPPORT
#endif #endif
/* Don't compile in the SDL backend if it's been disabled. */ /* Don't compile in the SDL backend if it's been disabled. */
#if defined(MA_HAS_SDL) #if defined(MA_HAS_SDL2)
#define MA_SDL_INIT_AUDIO 0x00000010 #define MA_SDL_INIT_AUDIO 0x00000010
#define MA_AUDIO_U8 0x0008 #define MA_AUDIO_U8 0x0008
#define MA_AUDIO_S16 0x8010 #define MA_AUDIO_S16 0x8010
@@ -115,7 +115,7 @@ typedef struct
MA_PFN_SDL_CloseAudioDevice SDL_CloseAudioDevice; MA_PFN_SDL_CloseAudioDevice SDL_CloseAudioDevice;
MA_PFN_SDL_OpenAudioDevice SDL_OpenAudioDevice; MA_PFN_SDL_OpenAudioDevice SDL_OpenAudioDevice;
MA_PFN_SDL_PauseAudioDevice SDL_PauseAudioDevice; MA_PFN_SDL_PauseAudioDevice SDL_PauseAudioDevice;
} ma_context_state_sdl; } ma_context_state_sdl2;
typedef struct typedef struct
{ {
@@ -128,10 +128,10 @@ typedef struct
{ {
int deviceID; int deviceID;
} playback; } playback;
} ma_device_state_sdl; } ma_device_state_sdl2;
MA_SDL_AudioFormat ma_format_to_sdl(ma_format format) MA_SDL_AudioFormat ma_format_to_sdl2(ma_format format)
{ {
switch (format) switch (format)
{ {
@@ -145,7 +145,7 @@ MA_SDL_AudioFormat ma_format_to_sdl(ma_format format)
} }
} }
ma_format ma_format_from_sdl(MA_SDL_AudioFormat format) ma_format ma_format_from_sdl2(MA_SDL_AudioFormat format)
{ {
switch (format) switch (format)
{ {
@@ -158,30 +158,30 @@ ma_format ma_format_from_sdl(MA_SDL_AudioFormat format)
} }
static ma_context_state_sdl* ma_context_get_backend_state__sdl(ma_context* pContext) static ma_context_state_sdl2* ma_context_get_backend_state__sdl2(ma_context* pContext)
{ {
return (ma_context_state_sdl*)ma_context_get_backend_state(pContext); return (ma_context_state_sdl2*)ma_context_get_backend_state(pContext);
} }
static ma_device_state_sdl* ma_device_get_backend_state__sdl(ma_device* pDevice) static ma_device_state_sdl2* ma_device_get_backend_state__sdl2(ma_device* pDevice)
{ {
return (ma_device_state_sdl*)ma_device_get_backend_state(pDevice); return (ma_device_state_sdl2*)ma_device_get_backend_state(pDevice);
} }
static ma_result ma_device_step__sdl(ma_device* pDevice, ma_blocking_mode blockingMode); static ma_result ma_device_step__sdl2(ma_device* pDevice, ma_blocking_mode blockingMode);
static void ma_backend_info__sdl(ma_device_backend_info* pBackendInfo) static void ma_backend_info__sdl2(ma_device_backend_info* pBackendInfo)
{ {
MA_SDL_ASSERT(pBackendInfo != NULL); MA_SDL2_ASSERT(pBackendInfo != NULL);
pBackendInfo->pName = "SDL2"; pBackendInfo->pName = "SDL2";
} }
static ma_result ma_context_init__sdl(ma_context* pContext, const void* pContextBackendConfig, void** ppContextState) static ma_result ma_context_init__sdl2(ma_context* pContext, const void* pContextBackendConfig, void** ppContextState)
{ {
ma_context_state_sdl* pContextStateSDL; ma_context_state_sdl2* pContextStateSDL;
const ma_context_config_sdl* pContextConfigSDL = (ma_context_config_sdl*)pContextBackendConfig; const ma_context_config_sdl2* pContextConfigSDL = (ma_context_config_sdl2*)pContextBackendConfig;
ma_log* pLog = ma_context_get_log(pContext); ma_log* pLog = ma_context_get_log(pContext);
int resultSDL; int resultSDL;
@@ -190,7 +190,7 @@ static ma_result ma_context_init__sdl(ma_context* pContext, const void* pContext
/* Allocate our SDL-specific context data. */ /* Allocate our SDL-specific context data. */
pContextStateSDL = (ma_context_state_sdl*)ma_calloc(sizeof(*pContextStateSDL), ma_context_get_allocation_callbacks(pContext)); pContextStateSDL = (ma_context_state_sdl2*)ma_calloc(sizeof(*pContextStateSDL), ma_context_get_allocation_callbacks(pContext));
if (pContextStateSDL == NULL) { if (pContextStateSDL == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
@@ -264,11 +264,11 @@ static ma_result ma_context_init__sdl(ma_context* pContext, const void* pContext
return MA_SUCCESS; return MA_SUCCESS;
} }
static void ma_context_uninit__sdl(ma_context* pContext) static void ma_context_uninit__sdl2(ma_context* pContext)
{ {
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(pContext); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(pContext);
MA_SDL_ASSERT(pContextStateSDL != NULL); MA_SDL2_ASSERT(pContextStateSDL != NULL);
pContextStateSDL->SDL_QuitSubSystem(MA_SDL_INIT_AUDIO); pContextStateSDL->SDL_QuitSubSystem(MA_SDL_INIT_AUDIO);
@@ -279,9 +279,9 @@ static void ma_context_uninit__sdl(ma_context* pContext)
ma_free(pContextStateSDL, ma_context_get_allocation_callbacks(pContext)); ma_free(pContextStateSDL, ma_context_get_allocation_callbacks(pContext));
} }
static void ma_add_native_format_from_AudioSpec__sdl(ma_device_info* pDeviceInfo, const MA_SDL_AudioSpec* pAudioSpec) static void ma_add_native_format_from_AudioSpec__sdl2(ma_device_info* pDeviceInfo, const MA_SDL_AudioSpec* pAudioSpec)
{ {
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].format = ma_format_from_sdl(pAudioSpec->format); pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].format = ma_format_from_sdl2(pAudioSpec->format);
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].channels = pAudioSpec->channels; pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].channels = pAudioSpec->channels;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].sampleRate = pAudioSpec->freq; pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].sampleRate = pAudioSpec->freq;
pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].flags = 0; pDeviceInfo->nativeDataFormats[pDeviceInfo->nativeDataFormatCount].flags = 0;
@@ -294,16 +294,16 @@ static void ma_add_native_format_from_AudioSpec__sdl(ma_device_info* pDeviceInfo
pDeviceInfo->nativeDataFormatCount = 1; pDeviceInfo->nativeDataFormatCount = 1;
} }
static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pCallbackUserData) static ma_result ma_context_enumerate_devices__sdl2(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pCallbackUserData)
{ {
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(pContext); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(pContext);
ma_device_enumeration_result cbResult = MA_DEVICE_ENUMERATION_CONTINUE; ma_device_enumeration_result cbResult = MA_DEVICE_ENUMERATION_CONTINUE;
MA_SDL_AudioSpec defaultAudioSpec; MA_SDL_AudioSpec defaultAudioSpec;
ma_device_info deviceInfo; ma_device_info deviceInfo;
int deviceCount; int deviceCount;
int iDevice; int iDevice;
MA_SDL_ASSERT(pContextStateSDL != NULL); MA_SDL2_ASSERT(pContextStateSDL != NULL);
/* Playback */ /* Playback */
if (cbResult == MA_DEVICE_ENUMERATION_CONTINUE) { if (cbResult == MA_DEVICE_ENUMERATION_CONTINUE) {
@@ -339,7 +339,7 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
/* Data Format. */ /* Data Format. */
if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) { if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) {
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 0, &audioSpec) == 0) { if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 0, &audioSpec) == 0) {
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec); ma_add_native_format_from_AudioSpec__sdl2(&deviceInfo, &audioSpec);
} }
} else { } else {
/* No way to retrieve the data format. Just report support for everything. */ /* No way to retrieve the data format. Just report support for everything. */
@@ -360,7 +360,7 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
if (hasDefaultPlaybackDevice) { if (hasDefaultPlaybackDevice) {
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pDefaultPlaybackDeviceName, (size_t)-1); ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pDefaultPlaybackDeviceName, (size_t)-1);
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &defaultAudioSpec); ma_add_native_format_from_AudioSpec__sdl2(&deviceInfo, &defaultAudioSpec);
} else { } else {
/* No way to retrieve the data format. Just report support for everything. */ /* No way to retrieve the data format. Just report support for everything. */
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "Default Playback Device", (size_t)-1); ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "Default Playback Device", (size_t)-1);
@@ -405,7 +405,7 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
/* Data Format. */ /* Data Format. */
if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) { if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) {
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 1, &audioSpec) == 0) { if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 1, &audioSpec) == 0) {
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec); ma_add_native_format_from_AudioSpec__sdl2(&deviceInfo, &audioSpec);
} }
} else { } else {
/* No way to retrieve the data format. Just report support for everything. */ /* No way to retrieve the data format. Just report support for everything. */
@@ -426,7 +426,7 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
if (hasDefaultCaptureDevice) { if (hasDefaultCaptureDevice) {
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pDefaultCaptureDeviceName, (size_t)-1); ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pDefaultCaptureDeviceName, (size_t)-1);
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &defaultAudioSpec); ma_add_native_format_from_AudioSpec__sdl2(&deviceInfo, &defaultAudioSpec);
} else { } else {
/* No way to retrieve the data format. Just report support for everything. */ /* No way to retrieve the data format. Just report support for everything. */
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "Default Capture Device", (size_t)-1); ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), "Default Capture Device", (size_t)-1);
@@ -441,21 +441,21 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
} }
void ma_audio_callback_capture__sdl(void* pUserData, ma_uint8* pBuffer, int bufferSizeInBytes) void ma_audio_callback_capture__sdl2(void* pUserData, ma_uint8* pBuffer, int bufferSizeInBytes)
{ {
ma_device* pDevice = (ma_device*)pUserData; ma_device* pDevice = (ma_device*)pUserData;
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_device_state_async_process(&pDeviceStateSDL->async, pDevice, NULL, pBuffer, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceStateSDL->async.capture.format, pDeviceStateSDL->async.capture.channels)); ma_device_state_async_process(&pDeviceStateSDL->async, pDevice, NULL, pBuffer, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceStateSDL->async.capture.format, pDeviceStateSDL->async.capture.channels));
} }
void ma_audio_callback_playback__sdl(void* pUserData, ma_uint8* pBuffer, int bufferSizeInBytes) void ma_audio_callback_playback__sdl2(void* pUserData, ma_uint8* pBuffer, int bufferSizeInBytes)
{ {
ma_device* pDevice = (ma_device*)pUserData; ma_device* pDevice = (ma_device*)pUserData;
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_device_state_async_process(&pDeviceStateSDL->async, pDevice, pBuffer, NULL, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceStateSDL->async.playback.format, pDeviceStateSDL->async.playback.channels)); ma_device_state_async_process(&pDeviceStateSDL->async, pDevice, pBuffer, NULL, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceStateSDL->async.playback.format, pDeviceStateSDL->async.playback.channels));
} }
static ma_result ma_device_init_internal__sdl(ma_device* pDevice, ma_context_state_sdl* pContextStateSDL, ma_device_state_sdl* pDeviceStateSDL, const ma_device_config_sdl* pDeviceConfigSDL, ma_device_type deviceType, ma_device_descriptor* pDescriptor) static ma_result ma_device_init_internal__sdl2(ma_device* pDevice, ma_context_state_sdl2* pContextStateSDL, ma_device_state_sdl2* pDeviceStateSDL, const ma_device_config_sdl2* pDeviceConfigSDL, ma_device_type deviceType, ma_device_descriptor* pDescriptor)
{ {
MA_SDL_AudioSpec desiredSpec; MA_SDL_AudioSpec desiredSpec;
MA_SDL_AudioSpec obtainedSpec; MA_SDL_AudioSpec obtainedSpec;
@@ -501,10 +501,10 @@ static ma_result ma_device_init_internal__sdl(ma_device* pDevice, ma_context_sta
/* We now have enough information to set up the device. */ /* We now have enough information to set up the device. */
memset(&desiredSpec, 0, sizeof(desiredSpec)); memset(&desiredSpec, 0, sizeof(desiredSpec));
desiredSpec.freq = (int)pDescriptor->sampleRate; desiredSpec.freq = (int)pDescriptor->sampleRate;
desiredSpec.format = ma_format_to_sdl(pDescriptor->format); desiredSpec.format = ma_format_to_sdl2(pDescriptor->format);
desiredSpec.channels = (ma_uint8)pDescriptor->channels; desiredSpec.channels = (ma_uint8)pDescriptor->channels;
desiredSpec.samples = (ma_uint16)pDescriptor->periodSizeInFrames; desiredSpec.samples = (ma_uint16)pDescriptor->periodSizeInFrames;
desiredSpec.callback = (deviceType == ma_device_type_capture) ? ma_audio_callback_capture__sdl : ma_audio_callback_playback__sdl; desiredSpec.callback = (deviceType == ma_device_type_capture) ? ma_audio_callback_capture__sdl2 : ma_audio_callback_playback__sdl2;
desiredSpec.userdata = pDevice; desiredSpec.userdata = pDevice;
/* We'll fall back to f32 if we don't have an appropriate mapping between SDL and miniaudio. */ /* We'll fall back to f32 if we don't have an appropriate mapping between SDL and miniaudio. */
@@ -525,7 +525,7 @@ static ma_result ma_device_init_internal__sdl(ma_device* pDevice, ma_context_sta
} }
/* The descriptor needs to be updated with our actual settings. */ /* The descriptor needs to be updated with our actual settings. */
pDescriptor->format = ma_format_from_sdl(obtainedSpec.format); pDescriptor->format = ma_format_from_sdl2(obtainedSpec.format);
pDescriptor->channels = obtainedSpec.channels; pDescriptor->channels = obtainedSpec.channels;
pDescriptor->sampleRate = (ma_uint32)obtainedSpec.freq; pDescriptor->sampleRate = (ma_uint32)obtainedSpec.freq;
ma_channel_map_init_standard(ma_standard_channel_map_default, pDescriptor->channelMap, ma_countof(pDescriptor->channelMap), pDescriptor->channels); ma_channel_map_init_standard(ma_standard_channel_map_default, pDescriptor->channelMap, ma_countof(pDescriptor->channelMap), pDescriptor->channels);
@@ -541,11 +541,11 @@ static ma_result ma_device_init_internal__sdl(ma_device* pDevice, ma_context_sta
return MA_SUCCESS; return MA_SUCCESS;
} }
static ma_result ma_device_init__sdl(ma_device* pDevice, const void* pDeviceBackendConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture, void** ppDeviceState) static ma_result ma_device_init__sdl2(ma_device* pDevice, const void* pDeviceBackendConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture, void** ppDeviceState)
{ {
ma_device_state_sdl* pDeviceStateSDL; ma_device_state_sdl2* pDeviceStateSDL;
ma_device_config_sdl* pDeviceConfigSDL = (ma_device_config_sdl*)pDeviceBackendConfig; ma_device_config_sdl2* pDeviceConfigSDL = (ma_device_config_sdl2*)pDeviceBackendConfig;
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(ma_device_get_context(pDevice)); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(ma_device_get_context(pDevice));
ma_device_type deviceType = ma_device_get_type(pDevice); ma_device_type deviceType = ma_device_get_type(pDevice);
ma_result result; ma_result result;
@@ -555,13 +555,13 @@ static ma_result ma_device_init__sdl(ma_device* pDevice, const void* pDeviceBack
} }
/* We need to allocate our backend-specific data. */ /* We need to allocate our backend-specific data. */
pDeviceStateSDL = (ma_device_state_sdl*)ma_calloc(sizeof(*pDeviceStateSDL), ma_device_get_allocation_callbacks(pDevice)); pDeviceStateSDL = (ma_device_state_sdl2*)ma_calloc(sizeof(*pDeviceStateSDL), ma_device_get_allocation_callbacks(pDevice));
if (pDeviceStateSDL == NULL) { if (pDeviceStateSDL == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
result = ma_device_init_internal__sdl(pDevice, pContextStateSDL, pDeviceStateSDL, pDeviceConfigSDL, ma_device_type_capture, pDescriptorCapture); result = ma_device_init_internal__sdl2(pDevice, pContextStateSDL, pDeviceStateSDL, pDeviceConfigSDL, ma_device_type_capture, pDescriptorCapture);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
ma_free(pDeviceStateSDL, ma_device_get_allocation_callbacks(pDevice)); ma_free(pDeviceStateSDL, ma_device_get_allocation_callbacks(pDevice));
return result; return result;
@@ -569,7 +569,7 @@ static ma_result ma_device_init__sdl(ma_device* pDevice, const void* pDeviceBack
} }
if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) {
result = ma_device_init_internal__sdl(pDevice, pContextStateSDL, pDeviceStateSDL, pDeviceConfigSDL, ma_device_type_playback, pDescriptorPlayback); result = ma_device_init_internal__sdl2(pDevice, pContextStateSDL, pDeviceStateSDL, pDeviceConfigSDL, ma_device_type_playback, pDescriptorPlayback);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
if (deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_duplex) {
pContextStateSDL->SDL_CloseAudioDevice(pDeviceStateSDL->capture.deviceID); pContextStateSDL->SDL_CloseAudioDevice(pDeviceStateSDL->capture.deviceID);
@@ -598,10 +598,10 @@ static ma_result ma_device_init__sdl(ma_device* pDevice, const void* pDeviceBack
return MA_SUCCESS; return MA_SUCCESS;
} }
static void ma_device_uninit__sdl(ma_device* pDevice) static void ma_device_uninit__sdl2(ma_device* pDevice)
{ {
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(ma_device_get_context(pDevice)); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(ma_device_get_context(pDevice));
ma_device_type deviceType = ma_device_get_type(pDevice); ma_device_type deviceType = ma_device_get_type(pDevice);
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
@@ -617,14 +617,14 @@ static void ma_device_uninit__sdl(ma_device* pDevice)
ma_free(pDeviceStateSDL, ma_device_get_allocation_callbacks(pDevice)); ma_free(pDeviceStateSDL, ma_device_get_allocation_callbacks(pDevice));
} }
static ma_result ma_device_start__sdl(ma_device* pDevice) static ma_result ma_device_start__sdl2(ma_device* pDevice)
{ {
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(ma_device_get_context(pDevice)); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(ma_device_get_context(pDevice));
ma_device_type deviceType = ma_device_get_type(pDevice); ma_device_type deviceType = ma_device_get_type(pDevice);
/* Step the device once to ensure buffers are pre-filled before starting. */ /* Step the device once to ensure buffers are pre-filled before starting. */
ma_device_step__sdl(pDevice, MA_BLOCKING_MODE_NON_BLOCKING); ma_device_step__sdl2(pDevice, MA_BLOCKING_MODE_NON_BLOCKING);
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
pContextStateSDL->SDL_PauseAudioDevice(pDeviceStateSDL->capture.deviceID, 0); pContextStateSDL->SDL_PauseAudioDevice(pDeviceStateSDL->capture.deviceID, 0);
@@ -637,10 +637,10 @@ static ma_result ma_device_start__sdl(ma_device* pDevice)
return MA_SUCCESS; return MA_SUCCESS;
} }
static ma_result ma_device_stop__sdl(ma_device* pDevice) static ma_result ma_device_stop__sdl2(ma_device* pDevice)
{ {
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_context_state_sdl* pContextStateSDL = ma_context_get_backend_state__sdl(ma_device_get_context(pDevice)); ma_context_state_sdl2* pContextStateSDL = ma_context_get_backend_state__sdl2(ma_device_get_context(pDevice));
ma_device_type deviceType = ma_device_get_type(pDevice); ma_device_type deviceType = ma_device_get_type(pDevice);
if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) { if (deviceType == ma_device_type_capture || deviceType == ma_device_type_duplex) {
@@ -654,50 +654,50 @@ static ma_result ma_device_stop__sdl(ma_device* pDevice)
return MA_SUCCESS; return MA_SUCCESS;
} }
static ma_result ma_device_step__sdl(ma_device* pDevice, ma_blocking_mode blockingMode) static ma_result ma_device_step__sdl2(ma_device* pDevice, ma_blocking_mode blockingMode)
{ {
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
return ma_device_state_async_step(&pDeviceStateSDL->async, pDevice, blockingMode, NULL); return ma_device_state_async_step(&pDeviceStateSDL->async, pDevice, blockingMode, NULL);
} }
static void ma_device_wake__sdl(ma_device* pDevice) static void ma_device_wake__sdl2(ma_device* pDevice)
{ {
ma_device_state_sdl* pDeviceStateSDL = ma_device_get_backend_state__sdl(pDevice); ma_device_state_sdl2* pDeviceStateSDL = ma_device_get_backend_state__sdl2(pDevice);
ma_device_state_async_release(&pDeviceStateSDL->async); ma_device_state_async_release(&pDeviceStateSDL->async);
} }
static ma_device_backend_vtable ma_gDeviceBackendVTable_SDL = static ma_device_backend_vtable ma_gDeviceBackendVTable_SDL2 =
{ {
ma_backend_info__sdl, ma_backend_info__sdl2,
ma_context_init__sdl, ma_context_init__sdl2,
ma_context_uninit__sdl, ma_context_uninit__sdl2,
ma_context_enumerate_devices__sdl, ma_context_enumerate_devices__sdl2,
ma_device_init__sdl, ma_device_init__sdl2,
ma_device_uninit__sdl, ma_device_uninit__sdl2,
ma_device_start__sdl, ma_device_start__sdl2,
ma_device_stop__sdl, ma_device_stop__sdl2,
ma_device_step__sdl, ma_device_step__sdl2,
ma_device_wake__sdl ma_device_wake__sdl2
}; };
ma_device_backend_vtable* ma_device_backend_sdl = &ma_gDeviceBackendVTable_SDL; ma_device_backend_vtable* ma_device_backend_sdl2 = &ma_gDeviceBackendVTable_SDL2;
#else #else
ma_device_backend_vtable* ma_device_backend_sdl = NULL; ma_device_backend_vtable* ma_device_backend_sdl2 = NULL;
#endif /* MA_HAS_SDL */ #endif /* MA_HAS_SDL2 */
MA_API ma_context_config_sdl ma_context_config_sdl_init(void) MA_API ma_context_config_sdl2 ma_context_config_sdl2_init(void)
{ {
ma_context_config_sdl config; ma_context_config_sdl2 config;
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
return config; return config;
} }
MA_API ma_device_config_sdl ma_device_config_sdl_init(void) MA_API ma_device_config_sdl2 ma_device_config_sdl2_init(void)
{ {
ma_device_config_sdl config; ma_device_config_sdl2 config;
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
@@ -705,4 +705,4 @@ MA_API ma_device_config_sdl ma_device_config_sdl_init(void)
} }
#endif /* miniaudio_backend_sdl_c */ #endif /* miniaudio_backend_sdl2_c */
+8 -8
View File
@@ -1,32 +1,32 @@
/* /*
The SDL backend does not require any user data, nor configs. Configs are provided here in case The SDL2 backend does not require any user data, nor configs. Configs are provided here in case
they are needed in the future, however you can safely pass in NULL when setting up your context they are needed in the future, however you can safely pass in NULL when setting up your context
and device configs. and device configs.
*/ */
#ifndef miniaudio_backend_sdl_h #ifndef miniaudio_backend_sdl2_h
#define miniaudio_backend_sdl_h #define miniaudio_backend_sdl2_h
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern ma_device_backend_vtable* ma_device_backend_sdl; extern ma_device_backend_vtable* ma_device_backend_sdl2;
typedef struct typedef struct
{ {
int _unused; int _unused;
} ma_context_config_sdl; } ma_context_config_sdl2;
MA_API ma_context_config_sdl ma_context_config_sdl_init(void); MA_API ma_context_config_sdl2 ma_context_config_sdl2_init(void);
typedef struct typedef struct
{ {
int _unused; int _unused;
} ma_device_config_sdl; } ma_device_config_sdl2;
MA_API ma_device_config_sdl ma_device_config_sdl_init(void); MA_API ma_device_config_sdl2 ma_device_config_sdl2_init(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
+2 -2
View File
@@ -198,7 +198,7 @@ ma_bool32 try_parse_backend(const char* arg, ma_device_backend_config* pBackends
goto done; goto done;
} }
if (strcmp(arg, "sdl2") == 0) { if (strcmp(arg, "sdl2") == 0) {
pBackends[backendCount++] = ma_device_backend_config_init(ma_device_backend_sdl, NULL); pBackends[backendCount++] = ma_device_backend_config_init(ma_device_backend_sdl2, NULL);
goto done; goto done;
} }
if (strcmp(arg, "pipewire") == 0) { if (strcmp(arg, "pipewire") == 0) {
@@ -301,7 +301,7 @@ void print_enabled_backends(void)
} }
} }
if (ma_device_backend_sdl != NULL) { if (ma_device_backend_sdl2 != NULL) {
printf(" SDL2\n"); printf(" SDL2\n");
} }