Skip to content

Commit 747faa3

Browse files
committed
Fix some errors with the Emscripten build.
1 parent ca3ba8c commit 747faa3

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

extras/backends/sdl/backend_sdl.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ MA_ENABLE_ONLY_SPECIFIC_BACKENDS) and it's supported at compile time (MA_SUPPORT
9595

9696
typedef int (* MA_PFN_SDL_InitSubSystem )(ma_uint32 flags);
9797
typedef void (* MA_PFN_SDL_QuitSubSystem )(ma_uint32 flags);
98-
typedef int (* MA_PFN_SDL_GetDefaultAudioInfo)(char** name, MA_SDL_AudioSpec* spec, int iscapture);
9998
typedef int (* MA_PFN_SDL_GetNumAudioDevices )(int iscapture);
100-
typedef const char* (* MA_PFN_SDL_GetAudioDeviceName )(int index, int iscapture);
99+
typedef int (* MA_PFN_SDL_GetDefaultAudioInfo)(char** name, MA_SDL_AudioSpec* spec, int iscapture);
101100
typedef int (* MA_PFN_SDL_GetAudioDeviceSpec )(int index, int iscapture, MA_SDL_AudioSpec* spec);
101+
typedef const char* (* MA_PFN_SDL_GetAudioDeviceName )(int index, int iscapture);
102102
typedef void (* MA_PFN_SDL_CloseAudioDevice )(MA_SDL_AudioDeviceID dev);
103103
typedef MA_SDL_AudioDeviceID (* MA_PFN_SDL_OpenAudioDevice )(const char* device, int iscapture, const MA_SDL_AudioSpec* desired, MA_SDL_AudioSpec* obtained, int allowed_changes);
104104
typedef void (* MA_PFN_SDL_PauseAudioDevice )(MA_SDL_AudioDeviceID dev, int pause_on);
@@ -108,10 +108,10 @@ typedef struct
108108
ma_handle hSDL; /* A handle to the SDL2 shared object. We dynamically load function pointers at runtime so we can avoid linking. */
109109
MA_PFN_SDL_InitSubSystem SDL_InitSubSystem;
110110
MA_PFN_SDL_QuitSubSystem SDL_QuitSubSystem;
111-
MA_PFN_SDL_GetDefaultAudioInfo SDL_GetDefaultAudioInfo;
112111
MA_PFN_SDL_GetNumAudioDevices SDL_GetNumAudioDevices;
113-
MA_PFN_SDL_GetAudioDeviceName SDL_GetAudioDeviceName;
112+
MA_PFN_SDL_GetDefaultAudioInfo SDL_GetDefaultAudioInfo;
114113
MA_PFN_SDL_GetAudioDeviceSpec SDL_GetAudioDeviceSpec;
114+
MA_PFN_SDL_GetAudioDeviceName SDL_GetAudioDeviceName;
115115
MA_PFN_SDL_CloseAudioDevice SDL_CloseAudioDevice;
116116
MA_PFN_SDL_OpenAudioDevice SDL_OpenAudioDevice;
117117
MA_PFN_SDL_PauseAudioDevice SDL_PauseAudioDevice;
@@ -225,10 +225,10 @@ static ma_result ma_context_init__sdl(ma_context* pContext, const void* pContext
225225
/* Now that we have the handle to the shared object we can go ahead and load some function pointers. */
226226
pContextStateSDL->SDL_InitSubSystem = (MA_PFN_SDL_InitSubSystem )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_InitSubSystem");
227227
pContextStateSDL->SDL_QuitSubSystem = (MA_PFN_SDL_QuitSubSystem )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_QuitSubSystem");
228-
pContextStateSDL->SDL_GetDefaultAudioInfo = (MA_PFN_SDL_GetDefaultAudioInfo)ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetDefaultAudioInfo");
229228
pContextStateSDL->SDL_GetNumAudioDevices = (MA_PFN_SDL_GetNumAudioDevices )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetNumAudioDevices");
230-
pContextStateSDL->SDL_GetAudioDeviceName = (MA_PFN_SDL_GetAudioDeviceName )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetAudioDeviceName");
229+
pContextStateSDL->SDL_GetDefaultAudioInfo = (MA_PFN_SDL_GetDefaultAudioInfo)ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetDefaultAudioInfo");
231230
pContextStateSDL->SDL_GetAudioDeviceSpec = (MA_PFN_SDL_GetAudioDeviceSpec )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetAudioDeviceSpec");
231+
pContextStateSDL->SDL_GetAudioDeviceName = (MA_PFN_SDL_GetAudioDeviceName )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_GetAudioDeviceName");
232232
pContextStateSDL->SDL_CloseAudioDevice = (MA_PFN_SDL_CloseAudioDevice )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_CloseAudioDevice");
233233
pContextStateSDL->SDL_OpenAudioDevice = (MA_PFN_SDL_OpenAudioDevice )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_OpenAudioDevice");
234234
pContextStateSDL->SDL_PauseAudioDevice = (MA_PFN_SDL_PauseAudioDevice )ma_dlsym(pLog, pContextStateSDL->hSDL, "SDL_PauseAudioDevice");
@@ -237,10 +237,15 @@ static ma_result ma_context_init__sdl(ma_context* pContext, const void* pContext
237237
{
238238
pContextStateSDL->SDL_InitSubSystem = SDL_InitSubSystem;
239239
pContextStateSDL->SDL_QuitSubSystem = SDL_QuitSubSystem;
240-
pContextStateSDL->SDL_GetDefaultAudioInfo = SDL_GetDefaultAudioInfo;
241240
pContextStateSDL->SDL_GetNumAudioDevices = SDL_GetNumAudioDevices;
242-
pContextStateSDL->SDL_GetAudioDeviceName = SDL_GetAudioDeviceName;
241+
#ifndef __EMSCRIPTEN__
242+
pContextStateSDL->SDL_GetDefaultAudioInfo = SDL_GetDefaultAudioInfo;
243243
pContextStateSDL->SDL_GetAudioDeviceSpec = SDL_GetAudioDeviceSpec;
244+
#else
245+
pContextStateSDL->SDL_GetDefaultAudioInfo = NULL;
246+
pContextStateSDL->SDL_GetAudioDeviceSpec = NULL;
247+
#endif
248+
pContextStateSDL->SDL_GetAudioDeviceName = SDL_GetAudioDeviceName;
244249
pContextStateSDL->SDL_CloseAudioDevice = SDL_CloseAudioDevice;
245250
pContextStateSDL->SDL_OpenAudioDevice = SDL_OpenAudioDevice;
246251
pContextStateSDL->SDL_PauseAudioDevice = SDL_PauseAudioDevice;
@@ -318,8 +323,13 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
318323
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pContextStateSDL->SDL_GetAudioDeviceName(iDevice, 0), (size_t)-1);
319324

320325
/* Data Format. */
321-
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 0, &audioSpec) == 0) {
322-
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec);
326+
if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) {
327+
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 0, &audioSpec) == 0) {
328+
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec);
329+
}
330+
} else {
331+
/* No way to retrieve the data format. Just report support for everything. */
332+
deviceInfo.nativeDataFormatCount = 1;
323333
}
324334

325335
cbResult = callback(ma_device_type_playback, &deviceInfo, pCallbackUserData);
@@ -350,8 +360,13 @@ static ma_result ma_context_enumerate_devices__sdl(ma_context* pContext, ma_enum
350360
ma_strncpy_s(deviceInfo.name, sizeof(deviceInfo.name), pContextStateSDL->SDL_GetAudioDeviceName(iDevice, 1), (size_t)-1);
351361

352362
/* Data Format. */
353-
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 1, &audioSpec) == 0) {
354-
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec);
363+
if (pContextStateSDL->SDL_GetAudioDeviceSpec != NULL) {
364+
if (pContextStateSDL->SDL_GetAudioDeviceSpec(iDevice, 1, &audioSpec) == 0) {
365+
ma_add_native_format_from_AudioSpec__sdl(&deviceInfo, &audioSpec);
366+
}
367+
} else {
368+
/* No way to retrieve the data format. Just report support for everything. */
369+
deviceInfo.nativeDataFormatCount = 1;
355370
}
356371

357372
cbResult = callback(ma_device_type_capture, &deviceInfo, pCallbackUserData);

tests/deviceio/deviceio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,15 @@ int main(int argc, char** argv)
650650
break;
651651
}
652652

653-
ma_sleep(10);
653+
/*
654+
Can't sleep with Emscripten. Just skip the sleeping part in this case. I don't run this test for Emscripten
655+
so it doesn't matter. Just fixing this for the sake of automated build tools.
656+
*/
657+
#ifndef __EMSCRIPTEN__
658+
{
659+
ma_sleep(10);
660+
}
661+
#endif
654662
}
655663
}
656664

0 commit comments

Comments
 (0)