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