src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp
changeset 8397 8cd319461894
parent 8361 eefad2ec4f76
child 8519 0a334fc866b0
     1.1 --- a/src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp	Mon Jan 28 22:03:12 2013 -0500
     1.2 +++ b/src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp	Mon Jan 28 23:13:07 2013 -0500
     1.3 @@ -2,12 +2,21 @@
     1.4  #include <xaudio2.h>
     1.5  #include "SDL_xaudio2_winrthelpers.h"
     1.6  
     1.7 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
     1.8  using Windows::Devices::Enumeration::DeviceClass;
     1.9  using Windows::Devices::Enumeration::DeviceInformation;
    1.10  using Windows::Devices::Enumeration::DeviceInformationCollection;
    1.11 +#endif
    1.12  
    1.13  HRESULT IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
    1.14  {
    1.15 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.16 +    // There doesn't seem to be any audio device enumeration on Windows Phone.
    1.17 +    // In lieu of this, just treat things as if there is one and only one
    1.18 +    // audio device.
    1.19 +    *devcount = 1;
    1.20 +    return S_OK;
    1.21 +#else
    1.22      // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
    1.23      auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    1.24      while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    1.25 @@ -17,10 +26,27 @@
    1.26      DeviceInformationCollection^ devices = operation->GetResults();
    1.27      *devcount = devices->Size;
    1.28      return S_OK;
    1.29 +#endif
    1.30  }
    1.31  
    1.32  HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
    1.33  {
    1.34 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    1.35 +    // Windows Phone doesn't seem to have the same device enumeration APIs that
    1.36 +    // Windows 8/RT has, or it doesn't have them at all.  In lieu of this,
    1.37 +    // just treat things as if there is one, and only one, default device.
    1.38 +    if (index != 0)
    1.39 +    {
    1.40 +        return XAUDIO2_E_INVALID_CALL;
    1.41 +    }
    1.42 +
    1.43 +    if (details)
    1.44 +    {
    1.45 +        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
    1.46 +        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
    1.47 +    }
    1.48 +    return S_OK;
    1.49 +#else
    1.50      auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    1.51      while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    1.52      {
    1.53 @@ -39,4 +65,5 @@
    1.54          wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
    1.55      }
    1.56      return S_OK;
    1.57 +#endif
    1.58  }