Audio hotplug fixes for winmm and XAudio2 backends.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 20 Mar 2015 11:11:44 -0400
changeset 9410e25530faeda0
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
     1.1 --- a/src/audio/SDL_audio.c	Fri Mar 20 10:35:42 2015 -0400
     1.2 +++ b/src/audio/SDL_audio.c	Fri Mar 20 11:11:44 2015 -0400
     1.3 @@ -299,7 +299,7 @@
     1.4          return -1;
     1.5      }
     1.6  
     1.7 -    SDL_assert(handle != NULL);
     1.8 +    SDL_assert(handle != NULL);  /* we reserve NULL, audio backends can't use it. */
     1.9  
    1.10      item->handle = handle;
    1.11      SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
     2.1 --- a/src/audio/winmm/SDL_winmm.c	Fri Mar 20 10:35:42 2015 -0400
     2.2 +++ b/src/audio/winmm/SDL_winmm.c	Fri Mar 20 11:11:44 2015 -0400
     2.3 @@ -46,7 +46,7 @@
     2.4          if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
     2.5              char *name = WIN_StringToUTF8(caps.szPname); \
     2.6              if (name != NULL) { \
     2.7 -                SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i)); \
     2.8 +                SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i+1)); \
     2.9                  SDL_free(name); \
    2.10              } \
    2.11          } \
    2.12 @@ -228,7 +228,8 @@
    2.13      UINT i;
    2.14  
    2.15      if (handle != NULL) {  /* specific device requested? */
    2.16 -        const size_t val = (size_t) handle;
    2.17 +        /* -1 because we increment the original value to avoid NULL. */
    2.18 +        const size_t val = ((size_t) handle) - 1;
    2.19          devId = (UINT) val;
    2.20      }
    2.21  
     3.1 --- a/src/audio/xaudio2/SDL_xaudio2.c	Fri Mar 20 10:35:42 2015 -0400
     3.2 +++ b/src/audio/xaudio2/SDL_xaudio2.c	Fri Mar 20 11:11:44 2015 -0400
     3.3 @@ -146,7 +146,7 @@
     3.4          if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
     3.5              char *str = WIN_StringToUTF8(details.DisplayName);
     3.6              if (str != NULL) {
     3.7 -                SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i));
     3.8 +                SDL_AddAudioDevice(SDL_FALSE, str, (void *) ((size_t) i+1));
     3.9                  SDL_free(str);  /* SDL_AddAudioDevice made a copy of the string. */
    3.10              }
    3.11          }
    3.12 @@ -297,7 +297,7 @@
    3.13  #if defined(SDL_XAUDIO2_WIN8)
    3.14      LPCWSTR devId = NULL;
    3.15  #else
    3.16 -    UINT32 devId = (UINT32) ((size_t) handle);  /* 0 == system default device. */
    3.17 +    UINT32 devId = 0;  /* 0 == system default device. */
    3.18  #endif
    3.19  
    3.20      static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
    3.21 @@ -312,6 +312,16 @@
    3.22  
    3.23      static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
    3.24  
    3.25 +#if defined(SDL_XAUDIO2_WIN8)
    3.26 +    /* !!! FIXME: hook up hotplugging. */
    3.27 +#else
    3.28 +    if (handle != NULL) {  /* specific device requested? */
    3.29 +        /* -1 because we increment the original value to avoid NULL. */
    3.30 +        const size_t val = ((size_t) handle) - 1;
    3.31 +        devId = (UINT32) val;
    3.32 +    }
    3.33 +#endif
    3.34 +
    3.35      if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
    3.36          return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
    3.37      }