-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.cpp
88 lines (67 loc) · 2.49 KB
/
volume.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
#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int volume() {
MMRESULT rc;
HMIXER hMixer;
MIXERLINE mxl;
MIXERLINECONTROLS mxlc;
MIXERCONTROL mxc;
for (int deviceID = 0; true; deviceID++) {
rc = mixerOpen(&hMixer, deviceID, 0, 0, MIXER_OBJECTF_MIXER);
if (MMSYSERR_NOERROR != rc) {
break;
}
ZeroMemory(&mxl, sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
if (rc != MMSYSERR_NOERROR) {
continue;
}
DWORD dwConnections = mxl.cConnections;
DWORD dwLineID = -1;
for (DWORD i = 0; i < dwConnections;) {
mxl.dwSource = i;
rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_SOURCE);
if (MMSYSERR_NOERROR == rc) {
if (mxl.dwComponentType == MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE) {
dwLineID = mxl.dwLineID;
break;
}
}
}
if (dwLineID == -1) {
continue;
}
ZeroMemory(&mxc, sizeof(MIXERCONTROL));
mxc.cbStruct = sizeof(mxc);
ZeroMemory(&mxlc, sizeof(MIXERLINECONTROLS));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl = &mxc;
mxlc.cbmxctrl = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == rc) {
MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cbDetails = sizeof(volStruct);
mxcd.cChannels = 1;
rc = mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc) {
long step = (mxc.Bounds.lMaximum - mxc.Bounds.lMinimum) / 100;
int index = (volStruct.lValue - mxc.Bounds.lMinimum) / step;
return index;
}
}
}
return -1;
}