slouken@8582
|
1 |
|
slouken@8582
|
2 |
#include <xaudio2.h>
|
slouken@8582
|
3 |
#include "SDL_xaudio2_winrthelpers.h"
|
slouken@8582
|
4 |
|
slouken@8582
|
5 |
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
slouken@8582
|
6 |
using Windows::Devices::Enumeration::DeviceClass;
|
slouken@8582
|
7 |
using Windows::Devices::Enumeration::DeviceInformation;
|
slouken@8582
|
8 |
using Windows::Devices::Enumeration::DeviceInformationCollection;
|
slouken@8582
|
9 |
#endif
|
slouken@8582
|
10 |
|
slouken@8582
|
11 |
extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
|
slouken@8582
|
12 |
{
|
slouken@8582
|
13 |
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
slouken@8582
|
14 |
// There doesn't seem to be any audio device enumeration on Windows Phone.
|
slouken@8582
|
15 |
// In lieu of this, just treat things as if there is one and only one
|
slouken@8582
|
16 |
// audio device.
|
slouken@8582
|
17 |
*devcount = 1;
|
slouken@8582
|
18 |
return S_OK;
|
slouken@8582
|
19 |
#else
|
slouken@8582
|
20 |
// TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
|
slouken@8582
|
21 |
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
slouken@8582
|
22 |
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
slouken@8582
|
23 |
{
|
slouken@8582
|
24 |
}
|
slouken@8582
|
25 |
|
slouken@8582
|
26 |
DeviceInformationCollection^ devices = operation->GetResults();
|
slouken@8582
|
27 |
*devcount = devices->Size;
|
slouken@8582
|
28 |
return S_OK;
|
slouken@8582
|
29 |
#endif
|
slouken@8582
|
30 |
}
|
slouken@8582
|
31 |
|
slouken@8582
|
32 |
extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
|
slouken@8582
|
33 |
{
|
slouken@8582
|
34 |
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
slouken@8582
|
35 |
// Windows Phone doesn't seem to have the same device enumeration APIs that
|
slouken@8582
|
36 |
// Windows 8/RT has, or it doesn't have them at all. In lieu of this,
|
slouken@8582
|
37 |
// just treat things as if there is one, and only one, default device.
|
slouken@8582
|
38 |
if (index != 0)
|
slouken@8582
|
39 |
{
|
slouken@8582
|
40 |
return XAUDIO2_E_INVALID_CALL;
|
slouken@8582
|
41 |
}
|
slouken@8582
|
42 |
|
slouken@8582
|
43 |
if (details)
|
slouken@8582
|
44 |
{
|
slouken@8582
|
45 |
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
|
slouken@8582
|
46 |
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
|
slouken@8582
|
47 |
}
|
slouken@8582
|
48 |
return S_OK;
|
slouken@8582
|
49 |
#else
|
slouken@8582
|
50 |
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
slouken@8582
|
51 |
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
slouken@8582
|
52 |
{
|
slouken@8582
|
53 |
}
|
slouken@8582
|
54 |
|
slouken@8582
|
55 |
DeviceInformationCollection^ devices = operation->GetResults();
|
slouken@8582
|
56 |
if (index >= devices->Size)
|
slouken@8582
|
57 |
{
|
slouken@8582
|
58 |
return XAUDIO2_E_INVALID_CALL;
|
slouken@8582
|
59 |
}
|
slouken@8582
|
60 |
|
slouken@8582
|
61 |
DeviceInformation^ d = devices->GetAt(index);
|
slouken@8582
|
62 |
if (details)
|
slouken@8582
|
63 |
{
|
slouken@8582
|
64 |
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
|
slouken@8582
|
65 |
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
|
slouken@8582
|
66 |
}
|
slouken@8582
|
67 |
return S_OK;
|
slouken@8582
|
68 |
#endif
|
slouken@8582
|
69 |
}
|