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)
     1 
     2 #include <xaudio2.h>
     3 #include "SDL_xaudio2_winrthelpers.h"
     4 
     5 using Windows::Devices::Enumeration::DeviceClass;
     6 using Windows::Devices::Enumeration::DeviceInformation;
     7 using Windows::Devices::Enumeration::DeviceInformationCollection;
     8 
     9 HRESULT IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
    10 {
    11     // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
    12     auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    13     while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    14     {
    15     }
    16  
    17     DeviceInformationCollection^ devices = operation->GetResults();
    18     *devcount = devices->Size;
    19     return S_OK;
    20 }
    21 
    22 HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
    23 {
    24     auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
    25     while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
    26     {
    27     }
    28  
    29     DeviceInformationCollection^ devices = operation->GetResults();
    30     if (index >= devices->Size)
    31     {
    32         return XAUDIO2_E_INVALID_CALL;
    33     }
    34 
    35     DeviceInformation^ d = devices->GetAt(index);
    36     if (details)
    37     {
    38         wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
    39         wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
    40     }
    41     return S_OK;
    42 }