2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "../../SDL_internal.h"
24 #include "SDL_xaudio2_winrthelpers.h"
26 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
27 using Windows::Devices::Enumeration::DeviceClass;
28 using Windows::Devices::Enumeration::DeviceInformation;
29 using Windows::Devices::Enumeration::DeviceInformationCollection;
32 extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
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
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)
47 DeviceInformationCollection^ devices = operation->GetResults();
48 *devcount = devices->Size;
53 extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
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.
61 return XAUDIO2_E_INVALID_CALL;
66 wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
67 wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
71 auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
72 while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
76 DeviceInformationCollection^ devices = operation->GetResults();
77 if (index >= devices->Size)
79 return XAUDIO2_E_INVALID_CALL;
82 DeviceInformation^ d = devices->GetAt(index);
85 wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
86 wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);