WinRT: got the XAudio2 backend compiling (but not running, yet)
authorDavid Ludwig <dludwig@pobox.com>
Thu, 22 Nov 2012 22:34:50 -0500
changeset 835382447809a27e
parent 8352 deef25f5fce1
child 8354 c086e9e73916
WinRT: got the XAudio2 backend compiling (but not running, yet)
VisualC/SDL/SDL_VS2012_WinRT.vcxproj
include/SDL_config_windowsrt.h
src/audio/xaudio2/SDL_xaudio2.c
src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp
src/audio/xaudio2/SDL_xaudio2_winrthelpers.h
src/core/windows/SDL_windows.h
     1.1 --- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Thu Nov 22 13:11:05 2012 -0500
     1.2 +++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Thu Nov 22 22:34:50 2012 -0500
     1.3 @@ -37,6 +37,22 @@
     1.4      <ClCompile Include="..\..\src\audio\SDL_audiotypecvt.c" />
     1.5      <ClCompile Include="..\..\src\audio\SDL_mixer.c" />
     1.6      <ClCompile Include="..\..\src\audio\SDL_wave.c" />
     1.7 +    <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2.c">
     1.8 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">CompileAsCpp</CompileAs>
     1.9 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">CompileAsCpp</CompileAs>
    1.10 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CompileAsCpp</CompileAs>
    1.11 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
    1.12 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
    1.13 +      <CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
    1.14 +    </ClCompile>
    1.15 +    <ClCompile Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.cpp">
    1.16 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.17 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.18 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.19 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.20 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    1.21 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    1.22 +    </ClCompile>
    1.23      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    1.24      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    1.25      <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
    1.26 @@ -206,6 +222,8 @@
    1.27      <ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
    1.28      <ClInclude Include="..\..\src\audio\SDL_sysaudio.h" />
    1.29      <ClInclude Include="..\..\src\audio\SDL_wave.h" />
    1.30 +    <ClInclude Include="..\..\src\audio\xaudio2\SDL_xaudio2_winrthelpers.h" />
    1.31 +    <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
    1.32      <ClInclude Include="..\..\src\events\blank_cursor.h" />
    1.33      <ClInclude Include="..\..\src\events\default_cursor.h" />
    1.34      <ClInclude Include="..\..\src\events\SDL_clipboardevents_c.h" />
    1.35 @@ -384,7 +402,7 @@
    1.36        <SubSystem>Console</SubSystem>
    1.37        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.38        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.39 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.40 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.41      </Link>
    1.42    </ItemDefinitionGroup>
    1.43    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    1.44 @@ -398,7 +416,7 @@
    1.45        <SubSystem>Console</SubSystem>
    1.46        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.47        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.48 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.49 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.50      </Link>
    1.51    </ItemDefinitionGroup>
    1.52    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
    1.53 @@ -412,7 +430,7 @@
    1.54        <SubSystem>Console</SubSystem>
    1.55        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.56        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.57 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.58 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.59      </Link>
    1.60    </ItemDefinitionGroup>
    1.61    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm'">
    1.62 @@ -426,7 +444,7 @@
    1.63        <SubSystem>Console</SubSystem>
    1.64        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.65        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.66 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.67 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.68      </Link>
    1.69    </ItemDefinitionGroup>
    1.70    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    1.71 @@ -440,7 +458,7 @@
    1.72        <SubSystem>Console</SubSystem>
    1.73        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.74        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.75 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.76 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.77      </Link>
    1.78    </ItemDefinitionGroup>
    1.79    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    1.80 @@ -454,7 +472,7 @@
    1.81        <SubSystem>Console</SubSystem>
    1.82        <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
    1.83        <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    1.84 -      <AdditionalDependencies>d2d1.lib; d3d11.lib; dxgi.lib; ole32.lib; windowscodecs.lib; dwrite.lib; kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.85 +      <AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.86      </Link>
    1.87    </ItemDefinitionGroup>
    1.88    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
     2.1 --- a/include/SDL_config_windowsrt.h	Thu Nov 22 13:11:05 2012 -0500
     2.2 +++ b/include/SDL_config_windowsrt.h	Thu Nov 22 22:34:50 2012 -0500
     2.3 @@ -144,7 +144,7 @@
     2.4  #endif
     2.5  
     2.6  /* Enable various audio drivers */
     2.7 -//#define SDL_AUDIO_DRIVER_XAUDIO2	1	// TODO, WinRT: see if SDL's XAudio2 driver can compile
     2.8 +#define SDL_AUDIO_DRIVER_XAUDIO2	1
     2.9  #define SDL_AUDIO_DRIVER_DISK	1
    2.10  #define SDL_AUDIO_DRIVER_DUMMY	1
    2.11  
     3.1 --- a/src/audio/xaudio2/SDL_xaudio2.c	Thu Nov 22 13:11:05 2012 -0500
     3.2 +++ b/src/audio/xaudio2/SDL_xaudio2.c	Thu Nov 22 22:34:50 2012 -0500
     3.3 @@ -18,22 +18,90 @@
     3.4       misrepresented as being the original software.
     3.5    3. This notice may not be removed or altered from any source distribution.
     3.6  */
     3.7 +
     3.8 +/* WinRT NOTICE:
     3.9 +
    3.10 +   A number of changes were warranted to SDL's XAudio2 backend in order to
    3.11 +   get it compiling for Windows RT.
    3.12 +
    3.13 +   When compiling for WinRT, XAudio2.h requires that it be compiled in a C++
    3.14 +   file, and not a straight C file.  Trying to compile it as C leads to lots
    3.15 +   of errors, at least with MSVC 2012 and Windows SDK 8.0, as of Nov 22, 2012.
    3.16 +   To address this specific issue, a few changes were made to SDL_xaudio2.c:
    3.17 +   
    3.18 +   1. SDL_xaudio2.c is compiled as a C++ file in WinRT builds.  Exported
    3.19 +      symbols, namely XAUDIO2_bootstrap, uses 'extern "C"' to make sure the
    3.20 +      rest of SDL can access it.  Non-WinRT builds continue to compile
    3.21 +      SDL_xaudio2.c as a C file.
    3.22 +   2. A macro redefines variables named 'this' to '_this', to prevent compiler
    3.23 +      errors (C2355 in Visual C++) related to 'this' being a reserverd keyword.
    3.24 +      This hack may need to be altered in the future, particularly if C++'s
    3.25 +      'this' keyword needs to be used (within SDL_xaudio2.c).  At the time
    3.26 +      WinRT support was initially added to SDL's XAudio2 backend, this
    3.27 +      capability was not needed.
    3.28 +   3. The C-style macros to invoke XAudio2's COM-based methods were
    3.29 +      rewritten to be C++-friendly.  These are provided in the file,
    3.30 +      SDL_xaudio2_winrthelpers.h.
    3.31 +   4. IXAudio2::CreateSourceVoice, when used in C++, requires its callbacks to
    3.32 +      be specified via a C++ class.  SDL's XAudio2 backend was written with
    3.33 +      C-style callbacks.  A class to bridge these two interfaces,
    3.34 +      SDL_XAudio2VoiceCallback, was written to make XAudio2 happy.  Its methods
    3.35 +      just call SDL's existing, C-style callbacks.
    3.36 +   5. Multiple checks for the __cplusplus macro were made, in appropriate
    3.37 +      places.  
    3.38 +
    3.39 +
    3.40 +   A few additional changes to SDL's XAudio2 backend were warranted by API
    3.41 +   changes to Windows.  Many, but not all of these are documented by Microsoft
    3.42 +   at:
    3.43 +   http://blogs.msdn.com/b/chuckw/archive/2012/04/02/xaudio2-and-windows-8-consumer-preview.aspx
    3.44 +
    3.45 +   1. Windows' thread synchronization function, CreateSemaphore, was removed
    3.46 +      from Windows RT.  SDL's semaphore API was substituted instead.
    3.47 +   2. The method calls, IXAudio2::GetDeviceCount and IXAudio2::GetDeviceDetails
    3.48 +      were removed from the XAudio2 API.  Microsoft is telling developers to
    3.49 +      use APIs in Windows::Foundation instead.
    3.50 +      For SDL, the missing methods were reimplemented using the APIs Microsoft
    3.51 +      said to use.
    3.52 +   3. CoInitialize and CoUninitialize are not available in Windows RT.
    3.53 +      These calls were removed, as COM will have been initialized earlier,
    3.54 +      at least by the call to the WinRT app's main function
    3.55 +      (aka 'int main(Platform::Array<Platform::String^>^)).  (DLudwig:
    3.56 +      This was my understanding of how WinRT: the 'main' function uses
    3.57 +      a tag of [MTAThread], which should initialize COM.  My understanding
    3.58 +      of COM is somewhat limited, and I may be incorrect here.)
    3.59 +   4. IXAudio2::CreateMasteringVoice changed its integer-based 'DeviceIndex'
    3.60 +      argument to a string-based one, 'szDeviceId'.  In Windows RT, the
    3.61 +      string-based argument will be used.
    3.62 +*/
    3.63 +
    3.64  #include "SDL_config.h"
    3.65  
    3.66  #if SDL_AUDIO_DRIVER_XAUDIO2
    3.67  
    3.68 +#ifdef __cplusplus
    3.69 +extern "C" {
    3.70 +#endif
    3.71  #include "../../core/windows/SDL_windows.h"
    3.72  #include "SDL_audio.h"
    3.73  #include "../SDL_audio_c.h"
    3.74  #include "../SDL_sysaudio.h"
    3.75  #include "SDL_assert.h"
    3.76 +#ifdef __cplusplus
    3.77 +}
    3.78 +#endif
    3.79  
    3.80 +#if defined(__WINRT__)
    3.81 +#  define SDL_XAUDIO2_HAS_SDK 1
    3.82 +#endif
    3.83 +#if defined(__WIN32__)
    3.84  #include <dxsdkver.h> /* XAudio2 exists as of the March 2008 DirectX SDK */
    3.85  #if (!defined(_DXSDK_BUILD_MAJOR) || (_DXSDK_BUILD_MAJOR < 1284))
    3.86  #  pragma message("Your DirectX SDK is too old. Disabling XAudio2 support.")
    3.87  #else
    3.88  #  define SDL_XAUDIO2_HAS_SDK 1
    3.89  #endif
    3.90 +#endif
    3.91  
    3.92  #ifdef SDL_XAUDIO2_HAS_SDK
    3.93  
    3.94 @@ -43,12 +111,17 @@
    3.95  /* Hidden "this" pointer for the audio functions */
    3.96  #define _THIS	SDL_AudioDevice *this
    3.97  
    3.98 +#ifdef __cplusplus
    3.99 +#define this _this
   3.100 +#include "SDL_xaudio2_winrthelpers.h"
   3.101 +#endif
   3.102 +
   3.103  struct SDL_PrivateAudioData
   3.104  {
   3.105      IXAudio2 *ixa2;
   3.106      IXAudio2SourceVoice *source;
   3.107      IXAudio2MasteringVoice *mastering;
   3.108 -    HANDLE semaphore;
   3.109 +    SDL_sem * semaphore;
   3.110      Uint8 *mixbuf;
   3.111      int mixlen;
   3.112      Uint8 *nextbuf;
   3.113 @@ -102,7 +175,7 @@
   3.114  {
   3.115      /* Just signal the SDL audio thread and get out of XAudio2's way. */
   3.116      SDL_AudioDevice *this = (SDL_AudioDevice *) data;
   3.117 -    ReleaseSemaphore(this->hidden->semaphore, 1, NULL);
   3.118 +    SDL_SemPost(this->hidden->semaphore);
   3.119  }
   3.120  
   3.121  static void STDMETHODCALLTYPE
   3.122 @@ -119,6 +192,33 @@
   3.123  static void STDMETHODCALLTYPE VoiceCBOnBufferStart(THIS_ void *data) {}
   3.124  static void STDMETHODCALLTYPE VoiceCBOnLoopEnd(THIS_ void *data) {}
   3.125  
   3.126 +#if defined(__cplusplus)
   3.127 +class SDL_XAudio2VoiceCallback : public IXAudio2VoiceCallback
   3.128 +{
   3.129 +public:
   3.130 +    STDMETHOD_(void, OnBufferEnd)(void *pBufferContext) {
   3.131 +        VoiceCBOnBufferEnd(pBufferContext);
   3.132 +    }
   3.133 +    STDMETHOD_(void, OnBufferStart)(void *pBufferContext) {
   3.134 +        VoiceCBOnBufferEnd(pBufferContext);
   3.135 +    }
   3.136 +    STDMETHOD_(void, OnLoopEnd)(void *pBufferContext) {
   3.137 +        VoiceCBOnLoopEnd(pBufferContext);
   3.138 +    }
   3.139 +    STDMETHOD_(void, OnStreamEnd)() {
   3.140 +        VoiceCBOnStreamEnd();
   3.141 +    }
   3.142 +    STDMETHOD_(void, OnVoiceError)(void *pBufferContext, HRESULT Error) {
   3.143 +        VoiceCBOnVoiceError(pBufferContext, Error);
   3.144 +    }
   3.145 +    STDMETHOD_(void, OnVoiceProcessingPassEnd)() {
   3.146 +        VoiceCBOnVoiceProcessPassEnd();
   3.147 +    }
   3.148 +    STDMETHOD_(void, OnVoiceProcessingPassStart)(UINT32 BytesRequired) {
   3.149 +        VoiceCBOnVoiceProcessPassStart(BytesRequired);
   3.150 +    }
   3.151 +};
   3.152 +#endif
   3.153  
   3.154  static Uint8 *
   3.155  XAUDIO2_GetDeviceBuf(_THIS)
   3.156 @@ -168,7 +268,7 @@
   3.157  XAUDIO2_WaitDevice(_THIS)
   3.158  {
   3.159      if (this->enabled) {
   3.160 -        WaitForSingleObject(this->hidden->semaphore, INFINITE);
   3.161 +        SDL_SemWait(this->hidden->semaphore);
   3.162      }
   3.163  }
   3.164  
   3.165 @@ -181,7 +281,7 @@
   3.166      IXAudio2SourceVoice_Discontinuity(source);
   3.167      IXAudio2SourceVoice_GetState(source, &state);
   3.168      while (state.BuffersQueued > 0) {
   3.169 -        WaitForSingleObject(this->hidden->semaphore, INFINITE);
   3.170 +        SDL_SemWait(this->hidden->semaphore);
   3.171          IXAudio2SourceVoice_GetState(source, &state);
   3.172      }
   3.173  }
   3.174 @@ -230,8 +330,15 @@
   3.175      SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   3.176      IXAudio2 *ixa2 = NULL;
   3.177      IXAudio2SourceVoice *source = NULL;
   3.178 +#if defined(__WINRT__)
   3.179 +    WCHAR devId[256];
   3.180 +#else
   3.181      UINT32 devId = 0;  /* 0 == system default device. */
   3.182 +#endif
   3.183  
   3.184 +#if defined(__cplusplus)
   3.185 +    static SDL_XAudio2VoiceCallback callbacks;
   3.186 +#else
   3.187  	static IXAudio2VoiceCallbackVtbl callbacks_vtable = {
   3.188  	    VoiceCBOnVoiceProcessPassStart,
   3.189          VoiceCBOnVoiceProcessPassEnd,
   3.190 @@ -243,6 +350,11 @@
   3.191  	};
   3.192  
   3.193  	static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
   3.194 +#endif // ! defined(__cplusplus)
   3.195 +
   3.196 +#if defined(__WINRT__)
   3.197 +    SDL_zero(devId);
   3.198 +#endif
   3.199  
   3.200      if (iscapture) {
   3.201          SDL_SetError("XAudio2: capture devices unsupported.");
   3.202 @@ -269,7 +381,11 @@
   3.203                      const int match = (SDL_strcmp(str, devname) == 0);
   3.204                      SDL_free(str);
   3.205                      if (match) {
   3.206 +#if defined(__WINRT__)
   3.207 +                        wcsncpy_s(devId, ARRAYSIZE(devId), details.DeviceID, _TRUNCATE);
   3.208 +#else
   3.209                          devId = i;
   3.210 +#endif
   3.211                          break;
   3.212                      }
   3.213                  }
   3.214 @@ -294,7 +410,7 @@
   3.215      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   3.216  
   3.217      this->hidden->ixa2 = ixa2;
   3.218 -    this->hidden->semaphore = CreateSemaphore(NULL, 1, 2, NULL);
   3.219 +    this->hidden->semaphore = SDL_CreateSemaphore(1);
   3.220      if (this->hidden->semaphore == NULL) {
   3.221          XAUDIO2_CloseDevice(this);
   3.222          SDL_SetError("XAudio2: CreateSemaphore() failed!");
   3.223 @@ -395,7 +511,9 @@
   3.224  static void
   3.225  XAUDIO2_Deinitialize(void)
   3.226  {
   3.227 +#if defined(__WIN32__)
   3.228      WIN_CoUninitialize();
   3.229 +#endif
   3.230  }
   3.231  
   3.232  #endif  /* SDL_XAUDIO2_HAS_SDK */
   3.233 @@ -410,13 +528,17 @@
   3.234  #else
   3.235      /* XAudio2Create() is a macro that uses COM; we don't load the .dll */
   3.236      IXAudio2 *ixa2 = NULL;
   3.237 +#if defined(__WIN32__)
   3.238      if (FAILED(WIN_CoInitialize())) {
   3.239          SDL_SetError("XAudio2: CoInitialize() failed");
   3.240          return 0;
   3.241      }
   3.242 +#endif
   3.243  
   3.244      if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
   3.245 +#if defined(__WIN32__)
   3.246          WIN_CoUninitialize();
   3.247 +#endif
   3.248          SDL_SetError("XAudio2: XAudio2Create() failed");
   3.249          return 0;  /* not available. */
   3.250      }
   3.251 @@ -436,6 +558,9 @@
   3.252  #endif
   3.253  }
   3.254  
   3.255 +#if defined(__cplusplus)
   3.256 +extern "C"
   3.257 +#endif
   3.258  AudioBootStrap XAUDIO2_bootstrap = {
   3.259      "xaudio2", "XAudio2", XAUDIO2_Init, 0
   3.260  };
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp	Thu Nov 22 22:34:50 2012 -0500
     4.3 @@ -0,0 +1,41 @@
     4.4 +
     4.5 +#include <xaudio2.h>
     4.6 +#include "SDL_xaudio2_winrthelpers.h"
     4.7 +
     4.8 +using Windows::Devices::Enumeration::DeviceClass;
     4.9 +using Windows::Devices::Enumeration::DeviceInformation;
    4.10 +using Windows::Devices::Enumeration::DeviceInformationCollection;
    4.11 +
    4.12 +HRESULT IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
    4.13 +{
    4.14 +    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    4.15 +    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    4.16 +    {
    4.17 +    }
    4.18 + 
    4.19 +    DeviceInformationCollection^ devices = operation->GetResults();
    4.20 +    *devcount = devices->Size;
    4.21 +    return S_OK;
    4.22 +}
    4.23 +
    4.24 +HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
    4.25 +{
    4.26 +    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    4.27 +    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    4.28 +    {
    4.29 +    }
    4.30 + 
    4.31 +    DeviceInformationCollection^ devices = operation->GetResults();
    4.32 +    if (index >= devices->Size)
    4.33 +    {
    4.34 +        return XAUDIO2_E_INVALID_CALL;
    4.35 +    }
    4.36 +
    4.37 +    DeviceInformation^ d = devices->GetAt(index);
    4.38 +    if (details)
    4.39 +    {
    4.40 +        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
    4.41 +        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
    4.42 +    }
    4.43 +    return S_OK;
    4.44 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/audio/xaudio2/SDL_xaudio2_winrthelpers.h	Thu Nov 22 22:34:50 2012 -0500
     5.3 @@ -0,0 +1,40 @@
     5.4 +
     5.5 +#pragma once
     5.6 +
     5.7 +//
     5.8 +// Re-implementation of methods removed from XAudio2 (in Windows RT):
     5.9 +//
    5.10 +
    5.11 +typedef struct XAUDIO2_DEVICE_DETAILS
    5.12 +{
    5.13 +    WCHAR DeviceID[256];
    5.14 +    WCHAR DisplayName[256];
    5.15 +    /* Other fields exist in the pre-Windows 8 version of this struct, however
    5.16 +       they weren't used by SDL, so they weren't added.
    5.17 +    */
    5.18 +} XAUDIO2_DEVICE_DETAILS;
    5.19 +
    5.20 +HRESULT IXAudio2_GetDeviceCount(IXAudio2 * unused, UINT32 * devcount);
    5.21 +HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details);
    5.22 +
    5.23 +
    5.24 +//
    5.25 +// C-style macros to call XAudio2's methods in C++:
    5.26 +//
    5.27 +
    5.28 +#define IXAudio2_CreateMasteringVoice(A, B, C, D, E, F, G) (A)->CreateMasteringVoice((B), (C), (D), (E), (F), (G))
    5.29 +#define IXAudio2_CreateSourceVoice(A, B, C, D, E, F, G, H) (A)->CreateSourceVoice((B), (C), (D), (E), (F), (G), (H))
    5.30 +#define IXAudio2_QueryInterface(A, B, C) (A)->QueryInterface((B), (C))
    5.31 +#define IXAudio2_Release(A) (A)->Release()
    5.32 +#define IXAudio2_StartEngine(A) (A)->StartEngine()
    5.33 +#define IXAudio2_StopEngine(A) (A)->StopEngine()
    5.34 +
    5.35 +#define IXAudio2MasteringVoice_DestroyVoice(A) (A)->DestroyVoice()
    5.36 +
    5.37 +#define IXAudio2SourceVoice_DestroyVoice(A) (A)->DestroyVoice()
    5.38 +#define IXAudio2SourceVoice_Discontinuity(A) (A)->Discontinuity()
    5.39 +#define IXAudio2SourceVoice_FlushSourceBuffers(A) (A)->FlushSourceBuffers()
    5.40 +#define IXAudio2SourceVoice_GetState(A, B) (A)->GetState((B))
    5.41 +#define IXAudio2SourceVoice_Start(A, B, C) (A)->Start((B), (C))
    5.42 +#define IXAudio2SourceVoice_Stop(A, B, C) (A)->Stop((B), (C))
    5.43 +#define IXAudio2SourceVoice_SubmitSourceBuffer(A, B, C) (A)->SubmitSourceBuffer((B), (C))
     6.1 --- a/src/core/windows/SDL_windows.h	Thu Nov 22 13:11:05 2012 -0500
     6.2 +++ b/src/core/windows/SDL_windows.h	Thu Nov 22 22:34:50 2012 -0500
     6.3 @@ -24,6 +24,7 @@
     6.4  #ifndef _INCLUDED_WINDOWS_H
     6.5  #define _INCLUDED_WINDOWS_H
     6.6  
     6.7 +#if defined(__WIN32__)
     6.8  #define WIN32_LEAN_AND_MEAN
     6.9  #define STRICT
    6.10  #ifndef UNICODE
    6.11 @@ -31,6 +32,7 @@
    6.12  #endif
    6.13  #undef _WIN32_WINNT
    6.14  #define _WIN32_WINNT  0x501   /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */
    6.15 +#endif
    6.16  
    6.17  #include <windows.h>
    6.18