-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowsAudio.cs
190 lines (162 loc) · 6.28 KB
/
WindowsAudio.cs
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Timers;
using SpotifyLib;
using System.Collections;
using System.Diagnostics;
//Windows things
namespace WindowsAudio
{
[ComImport]
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
internal class MMDeviceEnumerator
{
}
internal enum EDataFlow
{
eRender,
eCapture,
eAll,
EDataFlow_enum_count
}
internal enum ERole
{
eConsole,
eMultimedia,
eCommunications,
ERole_enum_count
}
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDeviceEnumerator
{
int NotImpl1();
[PreserveSig]
int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice ppDevice);
// the rest is not implemented
}
[Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDevice
{
[PreserveSig]
int Activate(ref Guid iid, int dwClsCtx, IntPtr pActivationParams, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface);
// the rest is not implemented
}
[Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioSessionManager2
{
int NotImpl1();
int NotImpl2();
[PreserveSig]
int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum);
// the rest is not implemented
}
[Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioSessionEnumerator
{
[PreserveSig]
int GetCount(out int SessionCount);
[PreserveSig]
int GetSession(int SessionCount, out IAudioSessionControl Session);
}
[Guid("F4B1A599-7266-4319-A8CA-E70ACB11E8CD"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioSessionControl
{
int NotImpl1();
[PreserveSig]
int GetDisplayName([MarshalAs(UnmanagedType.LPWStr)] out string pRetVal);
// the rest is not implemented
}
[Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ISimpleAudioVolume
{
[PreserveSig]
int SetMasterVolume(float fLevel, ref Guid EventContext);
[PreserveSig]
int GetMasterVolume(out float pfLevel);
[PreserveSig]
int SetMute(bool bMute, ref Guid EventContext);
[PreserveSig]
int GetMute(out bool pbMute);
}
public enum AudioSessionState
{
AudioSessionStateInactive = 0,
AudioSessionStateActive = 1,
AudioSessionStateExpired = 2
}
public enum AudioSessionDisconnectReason
{
DisconnectReasonDeviceRemoval = 0,
DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1),
DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1),
DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1),
DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1),
DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1)
}
[Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAudioSessionEvents
{
[PreserveSig]
int OnDisplayNameChanged([MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext);
[PreserveSig]
int OnIconPathChanged([MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext);
[PreserveSig]
int OnSimpleVolumeChanged(float NewVolume, bool newMute, Guid EventContext);
[PreserveSig]
int OnChannelVolumeChanged(UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext);
[PreserveSig]
int OnGroupingParamChanged(Guid NewGroupingParam, Guid EventContext);
[PreserveSig]
int OnStateChanged(AudioSessionState NewState);
[PreserveSig]
int OnSessionDisconnected(AudioSessionDisconnectReason DisconnectReason);
}
[Guid("BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAudioSessionControl2
{
[PreserveSig]
int GetState(out AudioSessionState state);
[PreserveSig]
int GetDisplayName([Out(), MarshalAs(UnmanagedType.LPWStr)] out string name);
[PreserveSig]
int SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string value, Guid EventContext);
[PreserveSig]
int GetIconPath([Out(), MarshalAs(UnmanagedType.LPWStr)] out string Path);
[PreserveSig]
int SetIconPath([MarshalAs(UnmanagedType.LPWStr)] string Value, Guid EventContext);
[PreserveSig]
int GetGroupingParam(out Guid GroupingParam);
[PreserveSig]
int SetGroupingParam(Guid Override, Guid Eventcontext);
[PreserveSig]
int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
[PreserveSig]
int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
[PreserveSig]
int GetSessionIdentifier([Out(), MarshalAs(UnmanagedType.LPWStr)] out string retVal);
[PreserveSig]
int GetSessionInstanceIdentifier([Out(), MarshalAs(UnmanagedType.LPWStr)] out string retVal);
[PreserveSig]
int GetProcessId(out UInt32 retvVal);
[PreserveSig]
int IsSystemSoundsSession();
[PreserveSig]
int SetDuckingPreference(bool optOut);
}
[Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioMeterInformation
{
[PreserveSig]
int GetPeakValue(out float pfPeak);
[PreserveSig]
int GetMeteringChannelCount(out int pnChannelCount);
[PreserveSig]
int GetChannelsPeakValues(int u32ChannelCount, [In] IntPtr afPeakValues);
[PreserveSig]
int QueryHardwareSupport(out int pdwHardwareSupportMask);
};
}