forked from LibreVR/Revive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
REV_CAPI_Audio.cpp
89 lines (75 loc) · 2.57 KB
/
REV_CAPI_Audio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "OVR_CAPI_Audio.h"
#include <Windows.h>
#include <Mmddk.h>
#include <Mmdeviceapi.h>
#include "REV_Assert.h"
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutWaveId(UINT* deviceOutId)
{
waveOutMessage((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)deviceOutId, NULL);
return ovrSuccess;
}
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInWaveId(UINT* deviceInId)
{
waveInMessage((HWAVEIN)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)deviceInId, NULL);
return ovrSuccess;
}
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutGuidStr(WCHAR deviceOutStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE])
{
IMMDeviceEnumerator* pEnumerator;
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
HRESULT hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_ALL, IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
if (FAILED(hr))
return ovrError_RuntimeException;
IMMDevice* pDevice;
pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
LPWSTR pGuid;
hr = pDevice->GetId(&pGuid);
if (FAILED(hr))
return ovrError_RuntimeException;
wcsncpy(deviceOutStrBuffer, pGuid, OVR_AUDIO_MAX_DEVICE_STR_SIZE);
// Cleanup
pDevice->Release();
pEnumerator->Release();
return ovrSuccess;
}
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutGuid(GUID* deviceOutGuid)
{
WCHAR deviceOut[OVR_AUDIO_MAX_DEVICE_STR_SIZE];
ovr_GetAudioDeviceOutGuidStr(deviceOut);
UuidFromString((RPC_WSTR)deviceOut, deviceOutGuid);
return ovrSuccess;
}
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInGuidStr(WCHAR deviceInStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE])
{
IMMDeviceEnumerator* pEnumerator;
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
HRESULT hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_ALL, IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
if (FAILED(hr))
return ovrError_RuntimeException;
IMMDevice* pDevice;
pEnumerator->GetDefaultAudioEndpoint(eCapture, eConsole, &pDevice);
LPWSTR pGuid;
hr = pDevice->GetId(&pGuid);
if (FAILED(hr))
return ovrError_RuntimeException;
wcsncpy(deviceInStrBuffer, pGuid, OVR_AUDIO_MAX_DEVICE_STR_SIZE);
// Cleanup
pDevice->Release();
pEnumerator->Release();
return ovrSuccess;
}
OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInGuid(GUID* deviceInGuid)
{
WCHAR deviceIn[OVR_AUDIO_MAX_DEVICE_STR_SIZE];
ovr_GetAudioDeviceInGuidStr(deviceIn);
UuidFromString((RPC_WSTR)deviceIn, deviceInGuid);
return ovrSuccess;
}