-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.hpp
67 lines (53 loc) · 1.69 KB
/
sound.hpp
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
/*
* sound.hpp
* -------------------------
* Enter Description
* -------------------------
* Stavros Avramidis 1/25/2019
*/
#ifndef GALAXLIGHTINGCONTROL_SOUND_HPP
#define GALAXLIGHTINGCONTROL_SOUND_HPP
#include <windows.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#define TIMER_PERIOD 125
#define EXIT_ON_ERROR(hr) \
if (FAILED(hr)) { goto Exit; }
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) \
{ (punk)->Release(); (punk) = NULL; }
HRESULT hr;
IMMDeviceEnumerator* pEnumerator = nullptr;
IMMDevice* pDevice = nullptr;
IAudioMeterInformation* pMeterInfo = nullptr;
void SoundInitialize() {
CoInitialize(nullptr);
// Get enumerator for audio endpoint devices.
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
nullptr, CLSCTX_INPROC_SERVER,
__uuidof(IMMDeviceEnumerator),
(void**) &pEnumerator);
EXIT_ON_ERROR(hr)
// Get peak meter for default audio-rendering device.
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
EXIT_ON_ERROR(hr)
hr = pDevice->Activate(__uuidof(IAudioMeterInformation),
CLSCTX_ALL, nullptr, (void**) &pMeterInfo);
EXIT_ON_ERROR(hr);
Exit:
if (FAILED(hr)) {
MessageBox(nullptr, TEXT("This program requires Windows Vista."),
TEXT("Error termination"), MB_OK);
}
SAFE_RELEASE(pEnumerator)
SAFE_RELEASE(pDevice)
SAFE_RELEASE(pMeterInfo)
CoUninitialize();
}
float GetPeakVolume() {
float peakVolume;
auto p_peakVolume = &peakVolume;
hr = pMeterInfo->GetPeakValue(p_peakVolume);
return peakVolume;
}
#endif //GALAXLIGHTINGCONTROL_SOUND_HPP