src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp
changeset 8582 c3e9a2b93517
parent 8519 0a334fc866b0
child 8616 ec011c16e2fd
     1.1 --- a/src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp	Tue Mar 04 19:49:11 2014 -0500
     1.2 +++ b/src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp	Sun Mar 09 11:06:11 2014 -0700
     1.3 @@ -1,69 +1,69 @@
     1.4 -
     1.5 -#include <xaudio2.h>
     1.6 -#include "SDL_xaudio2_winrthelpers.h"
     1.7 -
     1.8 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
     1.9 -using Windows::Devices::Enumeration::DeviceClass;
    1.10 -using Windows::Devices::Enumeration::DeviceInformation;
    1.11 -using Windows::Devices::Enumeration::DeviceInformationCollection;
    1.12 -#endif
    1.13 -
    1.14 -extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
    1.15 -{
    1.16 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.17 -    // There doesn't seem to be any audio device enumeration on Windows Phone.
    1.18 -    // In lieu of this, just treat things as if there is one and only one
    1.19 -    // audio device.
    1.20 -    *devcount = 1;
    1.21 -    return S_OK;
    1.22 -#else
    1.23 -    // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
    1.24 -    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    1.25 -    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    1.26 -    {
    1.27 -    }
    1.28 - 
    1.29 -    DeviceInformationCollection^ devices = operation->GetResults();
    1.30 -    *devcount = devices->Size;
    1.31 -    return S_OK;
    1.32 -#endif
    1.33 -}
    1.34 -
    1.35 -extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
    1.36 -{
    1.37 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.38 -    // Windows Phone doesn't seem to have the same device enumeration APIs that
    1.39 -    // Windows 8/RT has, or it doesn't have them at all.  In lieu of this,
    1.40 -    // just treat things as if there is one, and only one, default device.
    1.41 -    if (index != 0)
    1.42 -    {
    1.43 -        return XAUDIO2_E_INVALID_CALL;
    1.44 -    }
    1.45 -
    1.46 -    if (details)
    1.47 -    {
    1.48 -        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
    1.49 -        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
    1.50 -    }
    1.51 -    return S_OK;
    1.52 -#else
    1.53 -    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    1.54 -    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    1.55 -    {
    1.56 -    }
    1.57 - 
    1.58 -    DeviceInformationCollection^ devices = operation->GetResults();
    1.59 -    if (index >= devices->Size)
    1.60 -    {
    1.61 -        return XAUDIO2_E_INVALID_CALL;
    1.62 -    }
    1.63 -
    1.64 -    DeviceInformation^ d = devices->GetAt(index);
    1.65 -    if (details)
    1.66 -    {
    1.67 -        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
    1.68 -        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
    1.69 -    }
    1.70 -    return S_OK;
    1.71 -#endif
    1.72 -}
    1.73 +
    1.74 +#include <xaudio2.h>
    1.75 +#include "SDL_xaudio2_winrthelpers.h"
    1.76 +
    1.77 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    1.78 +using Windows::Devices::Enumeration::DeviceClass;
    1.79 +using Windows::Devices::Enumeration::DeviceInformation;
    1.80 +using Windows::Devices::Enumeration::DeviceInformationCollection;
    1.81 +#endif
    1.82 +
    1.83 +extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
    1.84 +{
    1.85 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.86 +    // There doesn't seem to be any audio device enumeration on Windows Phone.
    1.87 +    // In lieu of this, just treat things as if there is one and only one
    1.88 +    // audio device.
    1.89 +    *devcount = 1;
    1.90 +    return S_OK;
    1.91 +#else
    1.92 +    // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
    1.93 +    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    1.94 +    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    1.95 +    {
    1.96 +    }
    1.97 + 
    1.98 +    DeviceInformationCollection^ devices = operation->GetResults();
    1.99 +    *devcount = devices->Size;
   1.100 +    return S_OK;
   1.101 +#endif
   1.102 +}
   1.103 +
   1.104 +extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
   1.105 +{
   1.106 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   1.107 +    // Windows Phone doesn't seem to have the same device enumeration APIs that
   1.108 +    // Windows 8/RT has, or it doesn't have them at all.  In lieu of this,
   1.109 +    // just treat things as if there is one, and only one, default device.
   1.110 +    if (index != 0)
   1.111 +    {
   1.112 +        return XAUDIO2_E_INVALID_CALL;
   1.113 +    }
   1.114 +
   1.115 +    if (details)
   1.116 +    {
   1.117 +        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
   1.118 +        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
   1.119 +    }
   1.120 +    return S_OK;
   1.121 +#else
   1.122 +    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
   1.123 +    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
   1.124 +    {
   1.125 +    }
   1.126 + 
   1.127 +    DeviceInformationCollection^ devices = operation->GetResults();
   1.128 +    if (index >= devices->Size)
   1.129 +    {
   1.130 +        return XAUDIO2_E_INVALID_CALL;
   1.131 +    }
   1.132 +
   1.133 +    DeviceInformation^ d = devices->GetAt(index);
   1.134 +    if (details)
   1.135 +    {
   1.136 +        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
   1.137 +        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
   1.138 +    }
   1.139 +    return S_OK;
   1.140 +#endif
   1.141 +}