-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmixer.cpp
136 lines (116 loc) · 3.24 KB
/
mixer.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "mixer.h"
HMIXER mixerInit(SoundDirections d, int Component, int dev, int &cChannels, int &dwControlID)
{
HMIXER hMixer;
HRESULT hr;
hr = mixerOpen(&hMixer, 0, 0, 0, (d==Player) ? MIXER_OBJECTF_WAVEOUT : MIXER_OBJECTF_WAVEIN);
if ( FAILED( hr ) ) return 0;
MIXERLINE mxl;
memset(&mxl, 0, sizeof(MIXERLINE));
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = Component;
hr = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
if (FAILED(hr) || mxl.cControls==0)
{
mixerClose(hMixer);
return 0;
}
MIXERCONTROL mc;
MIXERLINECONTROLS mxlc;
memset(&mxlc, 0, sizeof(MIXERLINECONTROLS));
memset(&mc, 0, sizeof(MIXERCONTROL));
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = mxl.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.pamxctrl = &mc;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
hr = mixerGetLineControls((HMIXEROBJ)hMixer, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
if(FAILED(hr))
{
mixerClose(hMixer);
return 0;
}
if(mxl.cChannels==0)
{
mixerClose(hMixer);
return 0;
}
cChannels = mxl.cChannels;
dwControlID = mc.dwControlID;
return hMixer;
}
double GetVolumeX(SoundDirections d, int Component, int dev)
{
int cChannels, dwControlID;
HMIXER hMixer = mixerInit(d, Component, dev, cChannels, dwControlID);
if(!hMixer)
{
/* if(d==Recorder)
{
hMixer = mixerInit(Player, Component, dev, cChannels, dwControlID);
if(!hMixer)
return -1;
}
else
*/ return -1;
}
// getting value
MIXERCONTROLDETAILS mxcd;
memset(&mxcd, 0, sizeof(MIXERCONTROLDETAILS));
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.cChannels = cChannels;
mxcd.dwControlID = dwControlID;
MIXERCONTROLDETAILS_UNSIGNED mxdu[2];
memset(mxdu, 0, sizeof(MIXERCONTROLDETAILS_UNSIGNED)*2);
mxdu[0].dwValue = -1;
mxdu[1].dwValue = -1;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED)*mxcd.cChannels;
mxcd.paDetails = mxdu;
if( mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
{
mixerClose(hMixer);
return -1;
}
mixerClose(hMixer);
double val = -1;
if(mxcd.cChannels==1)
val = (double)mxdu[0].dwValue/65535.0;
if(mxcd.cChannels==2)
val = (double)(mxdu[0].dwValue+mxdu[1].dwValue)/2.0/65535.0;
return val;
}
int SetVolumeX(SoundDirections d, int Component, double volume, int dev)
{
int cChannels, dwControlID;
HMIXER hMixer = mixerInit(d, Component, dev, cChannels, dwControlID);
if(!hMixer)
{
/* if(d==Recorder)
{
hMixer = mixerInit(Player, Component, dev, cChannels, dwControlID);
if(!hMixer)
return -1;
}
else
*/ return -1;
}
// getting value
MIXERCONTROLDETAILS mxcd;
memset(&mxcd, 0, sizeof(MIXERCONTROLDETAILS));
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.cChannels = cChannels;
mxcd.dwControlID = dwControlID;
MIXERCONTROLDETAILS_UNSIGNED mxdu[2];
mxdu[0].dwValue = (int)(volume*65535.0);//(mc.Bounds.dwMaximum - mc.Bounds.dwMinimum));
mxdu[1].dwValue = mxdu[0].dwValue;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED) * mxcd.cChannels;
mxcd.paDetails = mxdu;
if(mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
{
mixerClose(hMixer);
return -1;
}
mixerClose(hMixer);
return 0;
}