Audio hotplug fixes for winmm and XAudio2 backends.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 20 Mar 2015 11:11:44 -0400
changeset 9410 e25530faeda0
parent 9409 9df20f292907
child 9411 6810478a60e9
Audio hotplug fixes for winmm and XAudio2 backends.
src/audio/SDL_audio.c
src/audio/winmm/SDL_winmm.c
src/audio/xaudio2/SDL_xaudio2.c
--- a/src/audio/SDL_audio.c	Fri Mar 20 10:35:42 2015 -0400
+++ b/src/audio/SDL_audio.c	Fri Mar 20 11:11:44 2015 -0400
@@ -299,7 +299,7 @@
         return -1;
     }
 
-    SDL_assert(handle != NULL);
+    SDL_assert(handle != NULL);  /* we reserve NULL, audio backends can't use it. */
 
     item->handle = handle;
     SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
--- a/src/audio/winmm/SDL_winmm.c	Fri Mar 20 10:35:42 2015 -0400
+++ b/src/audio/winmm/SDL_winmm.c	Fri Mar 20 11:11:44 2015 -0400
@@ -46,7 +46,7 @@
         if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
             char *name = WIN_StringToUTF8(caps.szPname); \
             if (name != NULL) { \
-                SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i)); \
+                SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i+1)); \
                 SDL_free(name); \
             } \
         } \
@@ -228,7 +228,8 @@
     UINT i;
 
     if (handle != NULL) {  /* specific device requested? */
-        const size_t val = (size_t) handle;
+        /* -1 because we increment the original value to avoid NULL. */
+        const size_t val = ((size_t) handle) - 1;
         devId = (UINT) val;
     }
 
--- a/src/audio/xaudio2/SDL_xaudio2.c	Fri Mar 20 10:35:42 2015 -0400
+++ b/src/audio/xaudio2/SDL_xaudio2.c	Fri Mar 20 11:11:44 2015 -0400
@@ -146,7 +146,7 @@
         if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
             char *str = WIN_StringToUTF8(details.DisplayName);
             if (str != NULL) {
-                SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i));
+                SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i+1));
                 SDL_free(str);  /* SDL_AddAudioDevice made a copy of the string. */
             }
         }
@@ -297,7 +297,7 @@
 #if defined(SDL_XAUDIO2_WIN8)
     LPCWSTR devId = NULL;
 #else
-    UINT32 devId = (UINT32) ((size_t) handle);  /* 0 == system default device. */
+    UINT32 devId = 0;  /* 0 == system default device. */
 #endif
 
     static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
@@ -312,6 +312,16 @@
 
     static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
 
+#if defined(SDL_XAUDIO2_WIN8)
+    /* !!! FIXME: hook up hotplugging. */
+#else
+    if (handle != NULL) {  /* specific device requested? */
+        /* -1 because we increment the original value to avoid NULL. */
+        const size_t val = ((size_t) handle) - 1;
+        devId = (UINT32) val;
+    }
+#endif
+
     if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
         return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
     }