src/audio/xaudio2/SDL_xaudio2_winrthelpers.cpp
author David Ludwig
Sat, 24 Nov 2012 11:19:06 -0500
changeset 8361 eefad2ec4f76
parent 8353 82447809a27e
child 8397 8cd319461894
permissions -rw-r--r--
WinRT: got XAudio2 sort-of working (it plays stuff poorly, then crashes)
dludwig@8353
     1
dludwig@8353
     2
#include <xaudio2.h>
dludwig@8353
     3
#include "SDL_xaudio2_winrthelpers.h"
dludwig@8353
     4
dludwig@8353
     5
using Windows::Devices::Enumeration::DeviceClass;
dludwig@8353
     6
using Windows::Devices::Enumeration::DeviceInformation;
dludwig@8353
     7
using Windows::Devices::Enumeration::DeviceInformationCollection;
dludwig@8353
     8
dludwig@8353
     9
HRESULT IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
dludwig@8353
    10
{
dludwig@8361
    11
    // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
dludwig@8353
    12
    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
dludwig@8353
    13
    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
dludwig@8353
    14
    {
dludwig@8353
    15
    }
dludwig@8353
    16
 
dludwig@8353
    17
    DeviceInformationCollection^ devices = operation->GetResults();
dludwig@8353
    18
    *devcount = devices->Size;
dludwig@8353
    19
    return S_OK;
dludwig@8353
    20
}
dludwig@8353
    21
dludwig@8353
    22
HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
dludwig@8353
    23
{
dludwig@8353
    24
    auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
dludwig@8353
    25
    while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
dludwig@8353
    26
    {
dludwig@8353
    27
    }
dludwig@8353
    28
 
dludwig@8353
    29
    DeviceInformationCollection^ devices = operation->GetResults();
dludwig@8353
    30
    if (index >= devices->Size)
dludwig@8353
    31
    {
dludwig@8353
    32
        return XAUDIO2_E_INVALID_CALL;
dludwig@8353
    33
    }
dludwig@8353
    34
dludwig@8353
    35
    DeviceInformation^ d = devices->GetAt(index);
dludwig@8353
    36
    if (details)
dludwig@8353
    37
    {
dludwig@8353
    38
        wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
dludwig@8353
    39
        wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
dludwig@8353
    40
    }
dludwig@8353
    41
    return S_OK;
dludwig@8353
    42
}