SDL_xaudio2_winrthelpers.cpp (3321B)
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "../../SDL_internal.h" 22 23#include <xaudio2.h> 24#include "SDL_xaudio2_winrthelpers.h" 25 26#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 27using Windows::Devices::Enumeration::DeviceClass; 28using Windows::Devices::Enumeration::DeviceInformation; 29using Windows::Devices::Enumeration::DeviceInformationCollection; 30#endif 31 32extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount) 33{ 34#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 35 // There doesn't seem to be any audio device enumeration on Windows Phone. 36 // In lieu of this, just treat things as if there is one and only one 37 // audio device. 38 *devcount = 1; 39 return S_OK; 40#else 41 // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background 42 auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender); 43 while (operation->Status != Windows::Foundation::AsyncStatus::Completed) 44 { 45 } 46 47 DeviceInformationCollection^ devices = operation->GetResults(); 48 *devcount = devices->Size; 49 return S_OK; 50#endif 51} 52 53extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details) 54{ 55#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 56 // Windows Phone doesn't seem to have the same device enumeration APIs that 57 // Windows 8/RT has, or it doesn't have them at all. In lieu of this, 58 // just treat things as if there is one, and only one, default device. 59 if (index != 0) 60 { 61 return XAUDIO2_E_INVALID_CALL; 62 } 63 64 if (details) 65 { 66 wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE); 67 wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE); 68 } 69 return S_OK; 70#else 71 auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender); 72 while (operation->Status != Windows::Foundation::AsyncStatus::Completed) 73 { 74 } 75 76 DeviceInformationCollection^ devices = operation->GetResults(); 77 if (index >= devices->Size) 78 { 79 return XAUDIO2_E_INVALID_CALL; 80 } 81 82 DeviceInformation^ d = devices->GetAt(index); 83 if (details) 84 { 85 wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE); 86 wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE); 87 } 88 return S_OK; 89#endif 90}