├── CoreAudioApi.csproj
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Interface.png
├── Program.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── README.md
├── SystemVolumeControl
├── AUDIO_VOLUME_NOTIFICATION_DATA.cs
├── AudioEndPointVolumeVolumeRange.cs
├── AudioEndpointVolume.cs
├── AudioEndpointVolumeCallback.cs
├── AudioEndpointVolumeChannel.cs
├── AudioEndpointVolumeChannels.cs
├── AudioEndpointVolumeNotificationDelegate.cs
├── AudioEndpointVolumeStepInformation.cs
├── AudioMeterInformation.cs
├── AudioMeterInformationChannels.cs
├── AudioSessionControl.cs
├── AudioSessionDisconnectReason.cs
├── AudioSessionManager.cs
├── AudioSessionState.cs
├── AudioVolumeNotificationData.cs
├── Blob.cs
├── CLSCTX.cs
├── EDataFlow.cs
├── EDeviceState.cs
├── EEndpointHardwareSupport.cs
├── ERole.cs
├── IAudioEndpointVolume.cs
├── IAudioEndpointVolumeCallback.cs
├── IAudioMeterInformation.cs
├── IAudioPeakMeter.cs
├── IAudioSessionControl2.cs
├── IAudioSessionEnumerator.cs
├── IAudioSessionEvents.cs
├── IAudioSessionManager2.cs
├── IMMDevice.cs
├── IMMDeviceCollection.cs
├── IMMDeviceEnumerator.cs
├── IMMEndpoint.cs
├── IPropertyStore.cs
├── ISimpleAudioVolume.cs
├── MMDevice.cs
├── MMDeviceCollection.cs
├── MMDeviceEnumerator.cs
├── PKEY.cs
├── PropVariant.cs
├── PropertyKey.cs
├── PropertyStore.cs
├── PropertyStoreProperty.cs
├── SessionCollection.cs
├── SimpleAudioVolume.cs
└── eStgmAccess.cs
├── bin
├── Debug
│ ├── CoreAudioApi.exe
│ └── CoreAudioApi.pdb
└── Release
│ ├── CoreAudioApi.exe
│ ├── CoreAudioApi.pdb
│ └── 音量控制.exe
└── obj
├── Debug
├── CoreAudioApi.Form1.resources
├── CoreAudioApi.Properties.Resources.resources
├── CoreAudioApi.csproj.CoreCompileInputs.cache
├── CoreAudioApi.csproj.FileListAbsolute.txt
├── CoreAudioApi.csproj.GenerateResource.cache
├── CoreAudioApi.exe
├── CoreAudioApi.pdb
├── DesignTimeResolveAssemblyReferences.cache
└── DesignTimeResolveAssemblyReferencesInput.cache
└── Release
├── CoreAudioApi.Form1.resources
├── CoreAudioApi.Properties.Resources.resources
├── CoreAudioApi.csproj.CoreCompileInputs.cache
├── CoreAudioApi.csproj.FileListAbsolute.txt
├── CoreAudioApi.csproj.GenerateResource.cache
├── CoreAudioApi.csprojAssemblyReference.cache
├── CoreAudioApi.exe
├── CoreAudioApi.pdb
├── DesignTimeResolveAssemblyReferences.cache
└── DesignTimeResolveAssemblyReferencesInput.cache
/CoreAudioApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {592205AE-2BC0-4EBE-A832-1BD8F51775E9}
8 | WinExe
9 | CoreAudioApi
10 | CoreAudioApi
11 | v2.0
12 | 512
13 |
14 |
15 | AnyCPU
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | AnyCPU
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | Form
44 |
45 |
46 | Form1.cs
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 | Form1.cs
98 |
99 |
100 | ResXFileCodeGenerator
101 | Resources.Designer.cs
102 | Designer
103 |
104 |
105 | True
106 | Resources.resx
107 |
108 |
109 | SettingsSingleFileGenerator
110 | Settings.Designer.cs
111 |
112 |
113 | True
114 | Settings.settings
115 | True
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace CoreAudioApi
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要修改
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.components = new System.ComponentModel.Container();
32 | this.label1 = new System.Windows.Forms.Label();
33 | this.progressBar1 = new System.Windows.Forms.ProgressBar();
34 | this.label2 = new System.Windows.Forms.Label();
35 | this.label3 = new System.Windows.Forms.Label();
36 | this.progressBar2 = new System.Windows.Forms.ProgressBar();
37 | this.label4 = new System.Windows.Forms.Label();
38 | this.progressBar3 = new System.Windows.Forms.ProgressBar();
39 | this.label5 = new System.Windows.Forms.Label();
40 | this.timer1 = new System.Windows.Forms.Timer(this.components);
41 | this.button1 = new System.Windows.Forms.Button();
42 | this.button2 = new System.Windows.Forms.Button();
43 | this.SuspendLayout();
44 | //
45 | // label1
46 | //
47 | this.label1.AutoSize = true;
48 | this.label1.Location = new System.Drawing.Point(37, 110);
49 | this.label1.Name = "label1";
50 | this.label1.Size = new System.Drawing.Size(98, 18);
51 | this.label1.TabIndex = 0;
52 | this.label1.Text = "当前音量:";
53 | //
54 | // progressBar1
55 | //
56 | this.progressBar1.Location = new System.Drawing.Point(87, 153);
57 | this.progressBar1.Name = "progressBar1";
58 | this.progressBar1.Size = new System.Drawing.Size(226, 28);
59 | this.progressBar1.TabIndex = 1;
60 | //
61 | // label2
62 | //
63 | this.label2.AutoSize = true;
64 | this.label2.Location = new System.Drawing.Point(35, 158);
65 | this.label2.Name = "label2";
66 | this.label2.Size = new System.Drawing.Size(44, 18);
67 | this.label2.TabIndex = 2;
68 | this.label2.Text = "主:";
69 | //
70 | // label3
71 | //
72 | this.label3.AutoSize = true;
73 | this.label3.Location = new System.Drawing.Point(35, 224);
74 | this.label3.Name = "label3";
75 | this.label3.Size = new System.Drawing.Size(44, 18);
76 | this.label3.TabIndex = 4;
77 | this.label3.Text = "左:";
78 | //
79 | // progressBar2
80 | //
81 | this.progressBar2.Location = new System.Drawing.Point(87, 219);
82 | this.progressBar2.Name = "progressBar2";
83 | this.progressBar2.Size = new System.Drawing.Size(226, 28);
84 | this.progressBar2.TabIndex = 3;
85 | //
86 | // label4
87 | //
88 | this.label4.AutoSize = true;
89 | this.label4.Location = new System.Drawing.Point(35, 290);
90 | this.label4.Name = "label4";
91 | this.label4.Size = new System.Drawing.Size(44, 18);
92 | this.label4.TabIndex = 6;
93 | this.label4.Text = "右:";
94 | //
95 | // progressBar3
96 | //
97 | this.progressBar3.Location = new System.Drawing.Point(87, 285);
98 | this.progressBar3.Name = "progressBar3";
99 | this.progressBar3.Size = new System.Drawing.Size(226, 28);
100 | this.progressBar3.TabIndex = 5;
101 | //
102 | // label5
103 | //
104 | this.label5.AutoSize = true;
105 | this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
106 | this.label5.Location = new System.Drawing.Point(264, 9);
107 | this.label5.Name = "label5";
108 | this.label5.Size = new System.Drawing.Size(80, 18);
109 | this.label5.TabIndex = 7;
110 | this.label5.Text = "设计:Yu";
111 | //
112 | // timer1
113 | //
114 | this.timer1.Enabled = true;
115 | this.timer1.Interval = 200;
116 | this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
117 | //
118 | // button1
119 | //
120 | this.button1.Location = new System.Drawing.Point(76, 43);
121 | this.button1.Name = "button1";
122 | this.button1.Size = new System.Drawing.Size(76, 48);
123 | this.button1.TabIndex = 8;
124 | this.button1.Text = "加音量";
125 | this.button1.UseVisualStyleBackColor = true;
126 | this.button1.Click += new System.EventHandler(this.button1_Click);
127 | //
128 | // button2
129 | //
130 | this.button2.Location = new System.Drawing.Point(192, 43);
131 | this.button2.Name = "button2";
132 | this.button2.Size = new System.Drawing.Size(76, 48);
133 | this.button2.TabIndex = 9;
134 | this.button2.Text = "减音量";
135 | this.button2.UseVisualStyleBackColor = true;
136 | this.button2.Click += new System.EventHandler(this.button2_Click);
137 | //
138 | // Form1
139 | //
140 | this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
141 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
142 | this.ClientSize = new System.Drawing.Size(356, 342);
143 | this.Controls.Add(this.button2);
144 | this.Controls.Add(this.button1);
145 | this.Controls.Add(this.label5);
146 | this.Controls.Add(this.label4);
147 | this.Controls.Add(this.progressBar3);
148 | this.Controls.Add(this.label3);
149 | this.Controls.Add(this.progressBar2);
150 | this.Controls.Add(this.label2);
151 | this.Controls.Add(this.progressBar1);
152 | this.Controls.Add(this.label1);
153 | this.Name = "Form1";
154 | this.Text = "Form1";
155 | this.Load += new System.EventHandler(this.Form1_Load);
156 | this.ResumeLayout(false);
157 | this.PerformLayout();
158 |
159 | }
160 |
161 | #endregion
162 |
163 | private System.Windows.Forms.Label label1;
164 | private System.Windows.Forms.ProgressBar progressBar1;
165 | private System.Windows.Forms.Label label2;
166 | private System.Windows.Forms.Label label3;
167 | private System.Windows.Forms.ProgressBar progressBar2;
168 | private System.Windows.Forms.Label label4;
169 | private System.Windows.Forms.ProgressBar progressBar3;
170 | private System.Windows.Forms.Label label5;
171 | private System.Windows.Forms.Timer timer1;
172 | private System.Windows.Forms.Button button1;
173 | private System.Windows.Forms.Button button2;
174 | }
175 | }
176 |
177 |
--------------------------------------------------------------------------------
/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace CoreAudioApi
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | MMDevice device;
14 |
15 | private void Form1_Load(object sender, EventArgs e)
16 | {
17 | //初始化设备
18 | MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
19 | device = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
20 | }
21 |
22 | ///
23 | /// 获取当前音量
24 | ///
25 | public int CurrentVolume
26 | {
27 | get => Convert.ToInt32(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100.0f);
28 | }
29 | ///
30 | /// 设置音量
31 | ///
32 | public int SetVolume
33 | {
34 | get => CurrentVolume;
35 | set
36 | {
37 | if (value < 0) device.AudioEndpointVolume.MasterVolumeLevelScalar = 0.0f;
38 | else if (value > 100) device.AudioEndpointVolume.MasterVolumeLevelScalar = 100.0f;
39 | else device.AudioEndpointVolume.MasterVolumeLevelScalar = value / 100.0f;
40 | }
41 | }
42 | ///
43 | /// 定时器更新并显示当前音量和峰值
44 | ///
45 | ///
46 | ///
47 | private void timer1_Tick(object sender, EventArgs e)
48 | {
49 | label1.Text = "当前音量:"+ CurrentVolume;
50 |
51 | //使用Convert.ToInt32转换没有误差
52 | progressBar1.Value = Convert.ToInt32(device.AudioMeterInformation.MasterPeakValue * 100.0f);
53 | progressBar2.Value = Convert.ToInt32(device.AudioMeterInformation.PeakValues[0] * 100.0f);
54 | progressBar3.Value = Convert.ToInt32(device.AudioMeterInformation.PeakValues[1] * 100.0f);
55 | }
56 |
57 | private void button1_Click(object sender, EventArgs e)
58 | {
59 | //每点击一次,音量加10
60 | SetVolume += 10;
61 | }
62 |
63 | private void button2_Click(object sender, EventArgs e)
64 | {
65 | //每点击一次,音量减10
66 | SetVolume -= 10;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------
/Interface.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/Interface.png
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace CoreAudioApi
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// 应用程序的主入口点。
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(new Form1());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("CoreAudioApi")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CoreAudioApi")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("592205ae-2bc0-4ebe-a832-1bd8f51775e9")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CoreAudioApi.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoreAudioApi.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CoreAudioApi.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | C# win7 win10 系统音量控制 CoreAudioApi源码 显示峰值
2 | vs2017 + .net2.0
3 |
4 | 
5 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AUDIO_VOLUME_NOTIFICATION_DATA.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | internal struct AUDIO_VOLUME_NOTIFICATION_DATA
30 | {
31 | public Guid guidEventContext;
32 | public bool bMuted;
33 | public float fMasterVolume;
34 | public uint nChannels;
35 | public float ChannelVolume;
36 |
37 | //Code Should Compile at warning level4 without any warnings,
38 | //However this struct will give us Warning CS0649: Field [Fieldname]
39 | //is never assigned to, and will always have its default value
40 | //You can disable CS0649 in the project options but that will disable
41 | //the warning for the whole project, it's a nice warning and we do want
42 | //it in other places so we make a nice dummy function to keep the compiler
43 | //happy.
44 | private void FixCS0649()
45 | {
46 | guidEventContext = Guid.Empty;
47 | bMuted = false;
48 | fMasterVolume = 0;
49 | nChannels = 0;
50 | ChannelVolume = 0;
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndPointVolumeVolumeRange.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class AudioEndPointVolumeVolumeRange
31 | {
32 | float _VolumeMindB;
33 | float _VolumeMaxdB;
34 | float _VolumeIncrementdB;
35 |
36 | internal AudioEndPointVolumeVolumeRange(IAudioEndpointVolume parent)
37 | {
38 | Marshal.ThrowExceptionForHR(parent.GetVolumeRange(out _VolumeMindB,out _VolumeMaxdB,out _VolumeIncrementdB));
39 | }
40 |
41 | public float MindB
42 | {
43 | get
44 | {
45 | return _VolumeMindB;
46 | }
47 | }
48 |
49 | public float MaxdB
50 | {
51 | get
52 | {
53 | return _VolumeMaxdB;
54 | }
55 | }
56 |
57 | public float IncrementdB
58 | {
59 | get
60 | {
61 | return _VolumeIncrementdB;
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolume.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 | using System.Runtime.InteropServices;
28 |
29 | namespace CoreAudioApi
30 | {
31 |
32 | public class AudioEndpointVolume : IDisposable
33 | {
34 | private IAudioEndpointVolume _AudioEndPointVolume;
35 | private AudioEndpointVolumeChannels _Channels;
36 | private AudioEndpointVolumeStepInformation _StepInformation;
37 | private AudioEndPointVolumeVolumeRange _VolumeRange;
38 | private EEndpointHardwareSupport _HardwareSupport;
39 | private AudioEndpointVolumeCallback _CallBack;
40 | public event AudioEndpointVolumeNotificationDelegate OnVolumeNotification;
41 |
42 | public AudioEndPointVolumeVolumeRange VolumeRange
43 | {
44 | get
45 | {
46 | return _VolumeRange;
47 | }
48 | }
49 | public EEndpointHardwareSupport HardwareSupport
50 | {
51 | get
52 | {
53 | return _HardwareSupport;
54 | }
55 | }
56 | public AudioEndpointVolumeStepInformation StepInformation
57 | {
58 | get
59 | {
60 | return _StepInformation;
61 | }
62 | }
63 | public AudioEndpointVolumeChannels Channels
64 | {
65 | get
66 | {
67 | return _Channels;
68 | }
69 | }
70 | public float MasterVolumeLevel
71 | {
72 | get
73 | {
74 | float result;
75 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevel(out result));
76 | return result;
77 | }
78 | set
79 | {
80 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevel(value, Guid.Empty));
81 | }
82 | }
83 | public float MasterVolumeLevelScalar
84 | {
85 | get
86 | {
87 | float result;
88 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevelScalar(out result));
89 | return result;
90 | }
91 | set
92 | {
93 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevelScalar(value, Guid.Empty));
94 | }
95 | }
96 | public bool Mute
97 | {
98 | get
99 | {
100 | bool result;
101 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMute(out result));
102 | return result;
103 | }
104 | set
105 | {
106 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMute(value, Guid.Empty));
107 | }
108 | }
109 | public void VolumeStepUp()
110 | {
111 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepUp(Guid.Empty));
112 | }
113 | public void VolumeStepDown()
114 | {
115 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepDown(Guid.Empty));
116 | }
117 | internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume)
118 | {
119 | uint HardwareSupp;
120 |
121 | _AudioEndPointVolume = realEndpointVolume;
122 | _Channels = new AudioEndpointVolumeChannels(_AudioEndPointVolume);
123 | _StepInformation = new AudioEndpointVolumeStepInformation(_AudioEndPointVolume);
124 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.QueryHardwareSupport(out HardwareSupp));
125 | _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp;
126 | _VolumeRange = new AudioEndPointVolumeVolumeRange(_AudioEndPointVolume);
127 | _CallBack = new AudioEndpointVolumeCallback(this);
128 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.RegisterControlChangeNotify( _CallBack));
129 | }
130 | internal void FireNotification(AudioVolumeNotificationData NotificationData)
131 | {
132 | AudioEndpointVolumeNotificationDelegate del = OnVolumeNotification;
133 | if (del != null)
134 | {
135 | del(NotificationData);
136 | }
137 | }
138 | #region IDisposable Members
139 |
140 | public void Dispose()
141 | {
142 | if (_CallBack != null)
143 | {
144 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.UnregisterControlChangeNotify( _CallBack ));
145 | _CallBack = null;
146 | }
147 | }
148 |
149 | ~AudioEndpointVolume()
150 | {
151 | Dispose();
152 | }
153 |
154 | #endregion
155 |
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolumeCallback.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 | using System.Runtime.InteropServices;
28 |
29 | namespace CoreAudioApi
30 | {
31 | // This class implements the IAudioEndpointVolumeCallback interface,
32 | // it is implemented in this class because implementing it on AudioEndpointVolume
33 | // (where the functionality is really wanted, would cause the OnNotify function
34 | // to show up in the public API.
35 | internal class AudioEndpointVolumeCallback : IAudioEndpointVolumeCallback
36 | {
37 | private AudioEndpointVolume _Parent;
38 |
39 | internal AudioEndpointVolumeCallback(AudioEndpointVolume parent)
40 | {
41 | _Parent = parent;
42 | }
43 |
44 | [PreserveSig] public int OnNotify(IntPtr NotifyData)
45 | {
46 | //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the
47 | //number of audio channels available we cannot just call PtrToStructure
48 | //to get all data, thats why it is split up into two steps, first the static
49 | //data is marshalled into the data structure, then with some IntPtr math the
50 | //remaining floats are read from memory.
51 | //
52 | AUDIO_VOLUME_NOTIFICATION_DATA data = (AUDIO_VOLUME_NOTIFICATION_DATA) Marshal.PtrToStructure(NotifyData, typeof(AUDIO_VOLUME_NOTIFICATION_DATA));
53 |
54 | //Determine offset in structure of the first float
55 | IntPtr Offset = Marshal.OffsetOf(typeof(AUDIO_VOLUME_NOTIFICATION_DATA),"ChannelVolume");
56 | //Determine offset in memory of the first float
57 | IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset);
58 |
59 | float[] voldata = new float[data.nChannels];
60 |
61 | //Read all floats from memory.
62 | for (int i = 0; i < data.nChannels; i++)
63 | {
64 | voldata[i] = (float)Marshal.PtrToStructure(FirstFloatPtr, typeof(float));
65 | }
66 |
67 | //Create combined structure and Fire Event in parent class.
68 | AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata);
69 | _Parent.FireNotification(NotificationData);
70 | return 0; //S_OK
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolumeChannel.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 | using System.Runtime.InteropServices;
28 |
29 | namespace CoreAudioApi
30 | {
31 | public class AudioEndpointVolumeChannel
32 | {
33 | private uint _Channel;
34 | private IAudioEndpointVolume _AudioEndpointVolume;
35 |
36 | internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel)
37 | {
38 | _Channel = (uint)channel;
39 | _AudioEndpointVolume = parent;
40 | }
41 |
42 | public float VolumeLevel
43 | {
44 | get
45 | {
46 | float result;
47 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevel(_Channel,out result));
48 | return result;
49 | }
50 | set
51 | {
52 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevel(_Channel, value,Guid.Empty));
53 | }
54 | }
55 |
56 | public float VolumeLevelScalar
57 | {
58 | get
59 | {
60 | float result;
61 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevelScalar(_Channel, out result));
62 | return result;
63 | }
64 | set
65 | {
66 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevelScalar(_Channel, value, Guid.Empty));
67 | }
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolumeChannels.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 | using System.Runtime.InteropServices;
28 |
29 | namespace CoreAudioApi
30 | {
31 | public class AudioEndpointVolumeChannels
32 | {
33 | IAudioEndpointVolume _AudioEndPointVolume;
34 | AudioEndpointVolumeChannel[] _Channels;
35 | public int Count
36 | {
37 | get
38 | {
39 | int result;
40 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetChannelCount(out result));
41 | return result;
42 | }
43 | }
44 |
45 | public AudioEndpointVolumeChannel this[int index]
46 | {
47 | get
48 | {
49 | return _Channels[index];
50 | }
51 | }
52 |
53 | internal AudioEndpointVolumeChannels(IAudioEndpointVolume parent)
54 | {
55 | int ChannelCount;
56 | _AudioEndPointVolume = parent;
57 |
58 | ChannelCount = Count;
59 | _Channels = new AudioEndpointVolumeChannel[ChannelCount];
60 | for (int i = 0; i < ChannelCount; i++)
61 | {
62 | _Channels[i] = new AudioEndpointVolumeChannel(_AudioEndPointVolume, i);
63 | }
64 | }
65 |
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolumeNotificationDelegate.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 |
27 | namespace CoreAudioApi
28 | {
29 | public delegate void AudioEndpointVolumeNotificationDelegate( AudioVolumeNotificationData data);
30 | }
31 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioEndpointVolumeStepInformation.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class AudioEndpointVolumeStepInformation
31 | {
32 | private uint _Step;
33 | private uint _StepCount;
34 | internal AudioEndpointVolumeStepInformation(IAudioEndpointVolume parent)
35 | {
36 | Marshal.ThrowExceptionForHR(parent.GetVolumeStepInfo(out _Step, out _StepCount));
37 | }
38 |
39 | public uint Step
40 | {
41 | get
42 | {
43 | return _Step;
44 | }
45 | }
46 |
47 | public uint StepCount
48 | {
49 | get
50 | {
51 | return _StepCount;
52 | }
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioMeterInformation.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class AudioMeterInformation
31 | {
32 | private IAudioMeterInformation _AudioMeterInformation;
33 | private EEndpointHardwareSupport _HardwareSupport;
34 | private AudioMeterInformationChannels _Channels;
35 |
36 | internal AudioMeterInformation(IAudioMeterInformation realInterface)
37 | {
38 | int HardwareSupp;
39 |
40 | _AudioMeterInformation = realInterface;
41 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.QueryHardwareSupport(out HardwareSupp));
42 | _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp;
43 | _Channels = new AudioMeterInformationChannels(_AudioMeterInformation);
44 |
45 | }
46 |
47 | public AudioMeterInformationChannels PeakValues
48 | {
49 | get
50 | {
51 | return _Channels;
52 | }
53 | }
54 |
55 | public EEndpointHardwareSupport HardwareSupport
56 | {
57 | get
58 | {
59 | return _HardwareSupport;
60 | }
61 | }
62 |
63 | public float MasterPeakValue
64 | {
65 | get
66 | {
67 | float result;
68 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetPeakValue(out result));
69 | return result;
70 | }
71 | }
72 |
73 |
74 |
75 |
76 |
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioMeterInformationChannels.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class AudioMeterInformationChannels
31 | {
32 | IAudioMeterInformation _AudioMeterInformation;
33 |
34 | public int Count
35 | {
36 | get
37 | {
38 | int result;
39 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetMeteringChannelCount(out result));
40 | return result;
41 | }
42 | }
43 |
44 | public float this[int index]
45 | {
46 | get
47 | {
48 | float[] peakValues = new float[Count];
49 | GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
50 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
51 | Params.Free();
52 | return peakValues[index];
53 | }
54 | }
55 |
56 | internal AudioMeterInformationChannels(IAudioMeterInformation parent)
57 | {
58 | _AudioMeterInformation = parent;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioSessionControl.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | //using System.Linq;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 | using System.Runtime.InteropServices;
28 |
29 | namespace CoreAudioApi
30 | {
31 | public class AudioSessionControl
32 | {
33 | internal IAudioSessionControl2 _AudioSessionControl;
34 | internal AudioMeterInformation _AudioMeterInformation;
35 | internal SimpleAudioVolume _SimpleAudioVolume;
36 |
37 | public AudioMeterInformation AudioMeterInformation
38 | {
39 | get
40 | {
41 | return _AudioMeterInformation;
42 | }
43 | }
44 |
45 | public SimpleAudioVolume SimpleAudioVolume
46 | {
47 | get
48 | {
49 | return _SimpleAudioVolume;
50 | }
51 | }
52 |
53 |
54 | internal AudioSessionControl(IAudioSessionControl2 realAudioSessionControl)
55 | {
56 | IAudioMeterInformation _meters = realAudioSessionControl as IAudioMeterInformation;
57 | ISimpleAudioVolume _volume = realAudioSessionControl as ISimpleAudioVolume;
58 | if (_meters != null)
59 | _AudioMeterInformation = new CoreAudioApi.AudioMeterInformation(_meters);
60 | if (_volume != null)
61 | _SimpleAudioVolume = new SimpleAudioVolume(_volume);
62 | _AudioSessionControl = realAudioSessionControl;
63 |
64 | }
65 |
66 | public void RegisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
67 | {
68 | Marshal.ThrowExceptionForHR(_AudioSessionControl.RegisterAudioSessionNotification(eventConsumer));
69 | }
70 |
71 | public void UnregisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
72 | {
73 | Marshal.ThrowExceptionForHR(_AudioSessionControl.UnregisterAudioSessionNotification(eventConsumer));
74 | }
75 |
76 | public AudioSessionState State
77 | {
78 | get
79 | {
80 | AudioSessionState res;
81 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetState(out res));
82 | return res;
83 | }
84 | }
85 |
86 | public string DisplayName
87 | {
88 | get
89 | {
90 | IntPtr NamePtr;
91 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetDisplayName(out NamePtr));
92 | string res = Marshal.PtrToStringAuto(NamePtr);
93 | Marshal.FreeCoTaskMem(NamePtr);
94 | return res;
95 | }
96 | }
97 |
98 | public string IconPath
99 | {
100 | get
101 | {
102 | IntPtr NamePtr;
103 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetIconPath(out NamePtr));
104 | string res = Marshal.PtrToStringAuto(NamePtr);
105 | Marshal.FreeCoTaskMem(NamePtr);
106 | return res;
107 | }
108 | }
109 |
110 | public string SessionIdentifier
111 | {
112 | get
113 | {
114 | IntPtr NamePtr;
115 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionIdentifier(out NamePtr));
116 | string res = Marshal.PtrToStringAuto(NamePtr);
117 | Marshal.FreeCoTaskMem(NamePtr);
118 | return res;
119 | }
120 | }
121 |
122 | public string SessionInstanceIdentifier
123 | {
124 | get
125 | {
126 | IntPtr NamePtr;
127 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionInstanceIdentifier(out NamePtr));
128 | string res = Marshal.PtrToStringAuto(NamePtr);
129 | Marshal.FreeCoTaskMem(NamePtr);
130 | return res;
131 | }
132 | }
133 |
134 | public uint ProcessID
135 | {
136 | get
137 | {
138 | uint pid;
139 | Marshal.ThrowExceptionForHR(_AudioSessionControl.GetProcessId(out pid));
140 | return pid;
141 | }
142 | }
143 |
144 | public bool IsSystemIsSystemSoundsSession
145 | {
146 | get
147 | {
148 | return (_AudioSessionControl.IsSystemSoundsSession() == 0); //S_OK
149 | }
150 |
151 | }
152 |
153 |
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioSessionDisconnectReason.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | //using System.Linq;
25 | using System.Text;
26 |
27 | namespace CoreAudioApi
28 | {
29 | public enum AudioSessionDisconnectReason
30 | {
31 | DisconnectReasonDeviceRemoval = 0,
32 | DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1),
33 | DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1),
34 | DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1),
35 | DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1),
36 | DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioSessionManager.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | //using System.Linq;
26 | using System.Text;
27 | using CoreAudioApi.Interfaces;
28 | using System.Runtime.InteropServices;
29 |
30 | namespace CoreAudioApi
31 | {
32 | public class AudioSessionManager
33 | {
34 | private IAudioSessionManager2 _AudioSessionManager;
35 | private SessionCollection _Sessions;
36 |
37 | internal AudioSessionManager(IAudioSessionManager2 realAudioSessionManager)
38 | {
39 | _AudioSessionManager = realAudioSessionManager;
40 | IAudioSessionEnumerator _SessionEnum ;
41 | Marshal.ThrowExceptionForHR(_AudioSessionManager.GetSessionEnumerator(out _SessionEnum));
42 | _Sessions = new SessionCollection(_SessionEnum);
43 | }
44 |
45 | public SessionCollection Sessions
46 | {
47 | get
48 | {
49 | return _Sessions;
50 | }
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioSessionState.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | //using System.Linq;
25 | using System.Text;
26 |
27 | namespace CoreAudioApi
28 | {
29 | public enum AudioSessionState
30 | {
31 | AudioSessionStateInactive = 0,
32 | AudioSessionStateActive = 1,
33 | AudioSessionStateExpired = 2
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SystemVolumeControl/AudioVolumeNotificationData.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | public class AudioVolumeNotificationData
29 | {
30 | private Guid _EventContext;
31 | private bool _Muted;
32 | private float _MasterVolume;
33 | private int _Channels;
34 | private float[] _ChannelVolume;
35 |
36 | public Guid EventContext
37 | {
38 | get
39 | {
40 | return _EventContext;
41 | }
42 | }
43 |
44 | public bool Muted
45 | {
46 | get
47 | {
48 | return _Muted;
49 | }
50 | }
51 |
52 | public float MasterVolume
53 | {
54 | get
55 | {
56 | return _MasterVolume;
57 | }
58 | }
59 | public int Channels
60 | {
61 | get
62 | {
63 | return _Channels;
64 | }
65 | }
66 |
67 | public float[] ChannelVolume
68 | {
69 | get
70 | {
71 | return _ChannelVolume;
72 | }
73 | }
74 | public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume)
75 | {
76 | _EventContext = eventContext;
77 | _Muted = muted;
78 | _MasterVolume = masterVolume;
79 | _Channels = channelVolume.Length;
80 | _ChannelVolume = channelVolume;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/SystemVolumeControl/Blob.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | internal struct Blob
30 | {
31 | public int Length;
32 | public IntPtr Data;
33 |
34 | //Code Should Compile at warning level4 without any warnings,
35 | //However this struct will give us Warning CS0649: Field [Fieldname]
36 | //is never assigned to, and will always have its default value
37 | //You can disable CS0649 in the project options but that will disable
38 | //the warning for the whole project, it's a nice warning and we do want
39 | //it in other places so we make a nice dummy function to keep the compiler
40 | //happy.
41 | private void FixCS0649()
42 | {
43 | Length = 0;
44 | Data = IntPtr.Zero;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/SystemVolumeControl/CLSCTX.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi.Interfaces
27 | {
28 | [Flags]
29 | internal enum CLSCTX : uint
30 | {
31 | INPROC_SERVER = 0x1,
32 | INPROC_HANDLER = 0x2,
33 | LOCAL_SERVER = 0x4,
34 | INPROC_SERVER16 = 0x8,
35 | REMOTE_SERVER = 0x10,
36 | INPROC_HANDLER16 = 0x20,
37 | RESERVED1 = 0x40,
38 | RESERVED2 = 0x80,
39 | RESERVED3 = 0x100,
40 | RESERVED4 = 0x200,
41 | NO_CODE_DOWNLOAD = 0x400,
42 | RESERVED5 = 0x800,
43 | NO_CUSTOM_MARSHAL = 0x1000,
44 | ENABLE_CODE_DOWNLOAD = 0x2000,
45 | NO_FAILURE_LOG = 0x4000,
46 | DISABLE_AAA = 0x8000,
47 | ENABLE_AAA = 0x10000,
48 | FROM_DEFAULT_CONTEXT = 0x20000,
49 | INPROC = INPROC_SERVER | INPROC_HANDLER,
50 | SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER,
51 | ALL = SERVER | INPROC_HANDLER
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SystemVolumeControl/EDataFlow.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | public enum EDataFlow
29 | {
30 | eRender = 0,
31 | eCapture = 1,
32 | eAll = 2 ,
33 | EDataFlow_enum_count =3
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SystemVolumeControl/EDeviceState.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | [Flags]
29 | public enum EDeviceState : uint
30 | {
31 | DEVICE_STATE_ACTIVE = 0x00000001,
32 | DEVICE_STATE_UNPLUGGED = 0x00000002,
33 | DEVICE_STATE_NOTPRESENT = 0x00000004,
34 | DEVICE_STATEMASK_ALL = 0x00000007
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SystemVolumeControl/EEndpointHardwareSupport.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | [Flags]
29 | public enum EEndpointHardwareSupport
30 | {
31 | Volume = 0x00000001,
32 | Mute = 0x00000002,
33 | Meter = 0x00000004
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SystemVolumeControl/ERole.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | public enum ERole
29 | {
30 | eConsole =0,
31 | eMultimedia =1,
32 | eCommunications=2,
33 | ERole_enum_count=3
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioEndpointVolume.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IAudioEndpointVolume
32 | {
33 | [PreserveSig]
34 | int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
35 | [PreserveSig]
36 | int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
37 | [PreserveSig]
38 | int GetChannelCount(out int pnChannelCount);
39 | [PreserveSig]
40 | int SetMasterVolumeLevel(float fLevelDB, Guid pguidEventContext);
41 | [PreserveSig]
42 | int SetMasterVolumeLevelScalar(float fLevel, Guid pguidEventContext);
43 | [PreserveSig]
44 | int GetMasterVolumeLevel(out float pfLevelDB);
45 | [PreserveSig]
46 | int GetMasterVolumeLevelScalar(out float pfLevel);
47 | [PreserveSig]
48 | int SetChannelVolumeLevel(uint nChannel, float fLevelDB, Guid pguidEventContext);
49 | [PreserveSig]
50 | int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, Guid pguidEventContext);
51 | [PreserveSig]
52 | int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB);
53 | [PreserveSig]
54 | int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel);
55 | [PreserveSig]
56 | int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, Guid pguidEventContext);
57 | [PreserveSig]
58 | int GetMute(out bool pbMute);
59 | [PreserveSig]
60 | int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount);
61 | [PreserveSig]
62 | int VolumeStepUp(Guid pguidEventContext);
63 | [PreserveSig]
64 | int VolumeStepDown(Guid pguidEventContext);
65 | [PreserveSig]
66 | int QueryHardwareSupport(out uint pdwHardwareSupportMask);
67 | [PreserveSig]
68 | int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioEndpointVolumeCallback.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("657804FA-D6AD-4496-8A60-352752AF4F89"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IAudioEndpointVolumeCallback
32 | {
33 | [PreserveSig] int OnNotify(IntPtr pNotifyData);
34 | };
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioMeterInformation.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IAudioMeterInformation
32 | {
33 | [PreserveSig]
34 | int GetPeakValue(out float pfPeak);
35 | [PreserveSig]
36 | int GetMeteringChannelCount(out int pnChannelCount);
37 | [PreserveSig]
38 | int GetChannelsPeakValues( int u32ChannelCount,[In] IntPtr afPeakValues);
39 | [PreserveSig]
40 | int QueryHardwareSupport( out int pdwHardwareSupportMask);
41 | };
42 | }
43 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioPeakMeter.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 |
28 | namespace CoreAudioApi.Interfaces
29 | {
30 | [Guid("DD79923C-0599-45e0-B8B6-C8DF7DB6E796"),
31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
32 | internal interface IAudioPeakMeter
33 | {
34 | int GetChannelCount( out int pcChannels);
35 | int GetLevel( int Channel, out float level);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioSessionControl2.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("bfb7ff88-7239-4fc9-8fa2-07c950be9c6d"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | interface IAudioSessionControl2
32 | {
33 | //IAudioSession functions
34 | [PreserveSig]
35 | int GetState(out AudioSessionState state);
36 | [PreserveSig]
37 | int GetDisplayName(out IntPtr name);
38 | [PreserveSig]
39 | int SetDisplayName(string value, Guid EventContext);
40 | [PreserveSig]
41 | int GetIconPath(out IntPtr Path);
42 | [PreserveSig]
43 | int SetIconPath(string Value, Guid EventContext);
44 | [PreserveSig]
45 | int GetGroupingParam(out Guid GroupingParam);
46 | [PreserveSig]
47 | int SetGroupingParam(Guid Override, Guid Eventcontext);
48 | [PreserveSig]
49 | int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
50 | [PreserveSig]
51 | int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
52 | //IAudioSession2 functions
53 | [PreserveSig]
54 | int GetSessionIdentifier( out IntPtr retVal);
55 | [PreserveSig]
56 | int GetSessionInstanceIdentifier( out IntPtr retVal);
57 | [PreserveSig]
58 | int GetProcessId( out UInt32 retvVal);
59 | [PreserveSig]
60 | int IsSystemSoundsSession();
61 | [PreserveSig]
62 | int SetDuckingPreference( bool optOut);
63 |
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioSessionEnumerator.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System.Runtime.InteropServices;
24 | using System;
25 | namespace CoreAudioApi.Interfaces
26 | {
27 | [Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"),
28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
29 | internal interface IAudioSessionEnumerator
30 | {
31 | int GetCount( out int SessionCount);
32 | int GetSession( int SessionCount,out IAudioSessionControl2 Session );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioSessionEvents.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | public interface IAudioSessionEvents
32 | {
33 | [PreserveSig]
34 | int OnDisplayNameChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext );
35 | [PreserveSig]
36 | int OnIconPathChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext );
37 | [PreserveSig]
38 | int OnSimpleVolumeChanged( float NewVolume,bool newMute, Guid EventContext );
39 | [PreserveSig]
40 | int OnChannelVolumeChanged( UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext );
41 | [PreserveSig]
42 | int OnGroupingParamChanged( Guid NewGroupingParam, Guid EventContext );
43 | [PreserveSig]
44 | int OnStateChanged( AudioSessionState NewState);
45 | [PreserveSig]
46 | int OnSessionDisconnected( AudioSessionDisconnectReason DisconnectReason);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IAudioSessionManager2.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | //using System.Linq;
25 | using System.Text;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi.Interfaces
29 | {
30 | [Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"),
31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
32 | interface IAudioSessionManager2
33 | {
34 | [PreserveSig]
35 | int GetAudioSessionControl(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr ISessionControl );
36 | [PreserveSig]
37 | int GetSimpleAudioVolume(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr /*ISimpleAudioVolume*/ SimpleAudioVolume);
38 | [PreserveSig]
39 | int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum);
40 | [PreserveSig]
41 | int RegisterSessionNotification( IntPtr IAudioSessionNotification );
42 | [PreserveSig]
43 | int UnregisterSessionNotification( IntPtr IAudioSessionNotification );
44 | [PreserveSig]
45 | int RegisterDuckNotification( string sessionID, IntPtr IAudioVolumeDuckNotification);
46 | [PreserveSig]
47 | int UnregisterDuckNotification(IntPtr IAudioVolumeDuckNotification);
48 | };
49 | }
50 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IMMDevice.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("D666063F-1587-4E43-81F1-B948E807363F"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IMMDevice
32 | {
33 | [PreserveSig]
34 | int Activate(ref Guid iid, CLSCTX dwClsCtx, IntPtr pActivationParams, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface);
35 | [PreserveSig]
36 | int OpenPropertyStore(EStgmAccess stgmAccess, out IPropertyStore propertyStore);
37 | [PreserveSig]
38 | int GetId([MarshalAs(UnmanagedType.LPWStr)] out string ppstrId);
39 | [PreserveSig]
40 | int GetState(out EDeviceState pdwState);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IMMDeviceCollection.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IMMDeviceCollection
32 | {
33 | [PreserveSig]
34 | int GetCount(out uint pcDevices);
35 | [PreserveSig]
36 | int Item(uint nDevice, out IMMDevice Device);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IMMDeviceEnumerator.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IMMDeviceEnumerator
32 | {
33 | [PreserveSig]
34 | int EnumAudioEndpoints(EDataFlow dataFlow, EDeviceState StateMask, out IMMDeviceCollection device);
35 | [PreserveSig]
36 | int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice ppEndpoint);
37 | [PreserveSig]
38 | int GetDevice(string pwstrId, out IMMDevice ppDevice);
39 | [PreserveSig]
40 | int RegisterEndpointNotificationCallback(IntPtr pClient);
41 | [PreserveSig]
42 | int UnregisterEndpointNotificationCallback(IntPtr pClient);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IMMEndpoint.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("1BE09788-6894-4089-8586-9A2A6C265AC5"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IMMEndpoint
32 | {
33 | [PreserveSig]
34 | int GetDataFlow(out EDataFlow pDataFlow);
35 | };
36 | }
37 |
--------------------------------------------------------------------------------
/SystemVolumeControl/IPropertyStore.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace CoreAudioApi.Interfaces
28 | {
29 | [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"),
30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
31 | internal interface IPropertyStore
32 | {
33 | [PreserveSig]
34 | int GetCount( out Int32 count);
35 | [PreserveSig]
36 | int GetAt( int iProp, out PropertyKey pkey);
37 | [PreserveSig]
38 | int GetValue(ref PropertyKey key, out PropVariant pv);
39 | [PreserveSig]
40 | int SetValue(ref PropertyKey key, ref PropVariant propvar);
41 | [PreserveSig]
42 | int Commit( );
43 | };
44 | }
45 |
--------------------------------------------------------------------------------
/SystemVolumeControl/ISimpleAudioVolume.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 |
27 |
28 | namespace CoreAudioApi.Interfaces
29 | {
30 | [Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"),
31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
32 | internal interface ISimpleAudioVolume
33 | {
34 | [PreserveSig]
35 | int SetMasterVolume( float fLevel,ref Guid EventContext);
36 | [PreserveSig]
37 | int GetMasterVolume( out float pfLevel);
38 | [PreserveSig]
39 | int SetMute( bool bMute, ref Guid EventContext) ;
40 | [PreserveSig]
41 | int GetMute( out bool bMute);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/SystemVolumeControl/MMDevice.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class MMDevice
31 | {
32 | #region Variables
33 | private IMMDevice _RealDevice;
34 | private PropertyStore _PropertyStore;
35 | private AudioMeterInformation _AudioMeterInformation;
36 | private AudioEndpointVolume _AudioEndpointVolume;
37 | private AudioSessionManager _AudioSessionManager;
38 |
39 | #endregion
40 |
41 | #region Guids
42 | private static Guid IID_IAudioMeterInformation = typeof(IAudioMeterInformation).GUID;
43 | private static Guid IID_IAudioEndpointVolume = typeof(IAudioEndpointVolume).GUID;
44 | private static Guid IID_IAudioSessionManager = typeof(IAudioSessionManager2).GUID;
45 | #endregion
46 |
47 | #region Init
48 | private void GetPropertyInformation()
49 | {
50 | IPropertyStore propstore;
51 | Marshal.ThrowExceptionForHR(_RealDevice.OpenPropertyStore(EStgmAccess.STGM_READ, out propstore));
52 | _PropertyStore = new PropertyStore(propstore);
53 | }
54 |
55 | private void GetAudioSessionManager()
56 | {
57 | object result;
58 | Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioSessionManager, CLSCTX.ALL, IntPtr.Zero, out result));
59 | _AudioSessionManager = new AudioSessionManager(result as IAudioSessionManager2);
60 | }
61 |
62 | private void GetAudioMeterInformation()
63 | {
64 | object result;
65 | Marshal.ThrowExceptionForHR( _RealDevice.Activate(ref IID_IAudioMeterInformation, CLSCTX.ALL, IntPtr.Zero, out result));
66 | _AudioMeterInformation = new AudioMeterInformation( result as IAudioMeterInformation);
67 | }
68 |
69 | private void GetAudioEndpointVolume()
70 | {
71 | object result;
72 | Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioEndpointVolume, CLSCTX.ALL, IntPtr.Zero, out result));
73 | _AudioEndpointVolume = new AudioEndpointVolume(result as IAudioEndpointVolume);
74 | }
75 |
76 | #endregion
77 |
78 | #region Properties
79 |
80 | public AudioSessionManager AudioSessionManager
81 | {
82 | get
83 | {
84 | if (_AudioSessionManager == null)
85 | GetAudioSessionManager();
86 |
87 | return _AudioSessionManager;
88 | }
89 | }
90 |
91 | public AudioMeterInformation AudioMeterInformation
92 | {
93 | get
94 | {
95 | if (_AudioMeterInformation == null)
96 | GetAudioMeterInformation();
97 |
98 | return _AudioMeterInformation;
99 | }
100 | }
101 |
102 | public AudioEndpointVolume AudioEndpointVolume
103 | {
104 | get
105 | {
106 | if (_AudioEndpointVolume == null)
107 | GetAudioEndpointVolume();
108 |
109 | return _AudioEndpointVolume;
110 | }
111 | }
112 |
113 | public PropertyStore Properties
114 | {
115 | get
116 | {
117 | if (_PropertyStore == null)
118 | GetPropertyInformation();
119 | return _PropertyStore;
120 | }
121 | }
122 |
123 | public string FriendlyName
124 | {
125 | get
126 | {
127 | if (_PropertyStore == null)
128 | GetPropertyInformation();
129 | if (_PropertyStore.Contains(PKEY.PKEY_DeviceInterface_FriendlyName))
130 | {
131 | return (string)_PropertyStore[PKEY.PKEY_DeviceInterface_FriendlyName].Value;
132 | }
133 | else
134 | return "Unknown";
135 | }
136 | }
137 |
138 |
139 | public string ID
140 | {
141 | get
142 | {
143 | string Result;
144 | Marshal.ThrowExceptionForHR(_RealDevice.GetId(out Result));
145 | return Result;
146 | }
147 | }
148 |
149 | public EDataFlow DataFlow
150 | {
151 | get
152 | {
153 | EDataFlow Result;
154 | IMMEndpoint ep = _RealDevice as IMMEndpoint ;
155 | ep.GetDataFlow(out Result);
156 | return Result;
157 | }
158 | }
159 |
160 | public EDeviceState State
161 | {
162 | get
163 | {
164 | EDeviceState Result;
165 | Marshal.ThrowExceptionForHR(_RealDevice.GetState(out Result));
166 | return Result;
167 |
168 | }
169 | }
170 | #endregion
171 |
172 | #region Constructor
173 | internal MMDevice(IMMDevice realDevice)
174 | {
175 | _RealDevice = realDevice;
176 | }
177 | #endregion
178 |
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/SystemVolumeControl/MMDeviceCollection.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 | using CoreAudioApi.Interfaces;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class MMDeviceCollection
31 | {
32 | private IMMDeviceCollection _MMDeviceCollection;
33 |
34 | public int Count
35 | {
36 | get
37 | {
38 | uint result;
39 | Marshal.ThrowExceptionForHR(_MMDeviceCollection.GetCount(out result));
40 | return (int)result;
41 | }
42 | }
43 |
44 | public MMDevice this[int index]
45 | {
46 | get
47 | {
48 | IMMDevice result;
49 | _MMDeviceCollection.Item((uint)index, out result);
50 | return new MMDevice(result);
51 | }
52 | }
53 |
54 | internal MMDeviceCollection(IMMDeviceCollection parent)
55 | {
56 | _MMDeviceCollection = parent;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/SystemVolumeControl/MMDeviceEnumerator.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using System.Runtime.InteropServices;
26 | using CoreAudioApi.Interfaces;
27 |
28 | namespace CoreAudioApi
29 | {
30 | //Marked as internal, since on its own its no good
31 | [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
32 | internal class _MMDeviceEnumerator
33 | {
34 | }
35 |
36 | //Small wrapper class
37 | public class MMDeviceEnumerator
38 | {
39 | private IMMDeviceEnumerator _realEnumerator = new _MMDeviceEnumerator() as IMMDeviceEnumerator;
40 |
41 | public MMDeviceCollection EnumerateAudioEndPoints(EDataFlow dataFlow, EDeviceState dwStateMask)
42 | {
43 | IMMDeviceCollection result;
44 | Marshal.ThrowExceptionForHR(_realEnumerator.EnumAudioEndpoints(dataFlow,dwStateMask,out result));
45 | return new MMDeviceCollection(result);
46 | }
47 |
48 | public MMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role)
49 | {
50 | IMMDevice _Device = null;
51 | Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDefaultAudioEndpoint(dataFlow, role, out _Device));
52 | return new MMDevice(_Device);
53 | }
54 |
55 | public MMDevice GetDevice(string ID)
56 | {
57 | IMMDevice _Device = null;
58 | Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDevice(ID, out _Device));
59 | return new MMDevice(_Device);
60 | }
61 |
62 | public MMDeviceEnumerator()
63 | {
64 | if (System.Environment.OSVersion.Version.Major < 6)
65 | {
66 | throw new NotSupportedException("This functionality is only supported on Windows Vista or newer.");
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/SystemVolumeControl/PKEY.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | public static class PKEY
29 | {
30 | public static readonly Guid PKEY_DeviceInterface_FriendlyName = new Guid( 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0);
31 | public static readonly Guid PKEY_AudioEndpoint_FormFactor = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
32 | public static readonly Guid PKEY_AudioEndpoint_ControlPanelPageProvider = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
33 | public static readonly Guid PKEY_AudioEndpoint_Association = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
34 | public static readonly Guid PKEY_AudioEndpoint_PhysicalSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
35 | public static readonly Guid PKEY_AudioEndpoint_GUID = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
36 | public static readonly Guid PKEY_AudioEndpoint_Disable_SysFx = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
37 | public static readonly Guid PKEY_AudioEndpoint_FullRangeSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
38 | public static readonly Guid PKEY_AudioEngine_DeviceFormat = new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c);
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SystemVolumeControl/PropVariant.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using System.Runtime.InteropServices.ComTypes;
27 | using System.Runtime.InteropServices;
28 | using CoreAudioApi.Interfaces;
29 |
30 | namespace CoreAudioApi
31 | {
32 | [StructLayout(LayoutKind.Explicit)]
33 | public struct PropVariant
34 | {
35 | [FieldOffset(0)] short vt;
36 | [FieldOffset(2)] short wReserved1;
37 | [FieldOffset(4)] short wReserved2;
38 | [FieldOffset(6)] short wReserved3;
39 | [FieldOffset(8)] sbyte cVal;
40 | [FieldOffset(8)] byte bVal;
41 | [FieldOffset(8)] short iVal;
42 | [FieldOffset(8)] ushort uiVal;
43 | [FieldOffset(8)] int lVal;
44 | [FieldOffset(8)] uint ulVal;
45 | [FieldOffset(8)] long hVal;
46 | [FieldOffset(8)] ulong uhVal;
47 | [FieldOffset(8)] float fltVal;
48 | [FieldOffset(8)] double dblVal;
49 | [FieldOffset(8)] Blob blobVal;
50 | [FieldOffset(8)] DateTime date;
51 | [FieldOffset(8)] bool boolVal;
52 | [FieldOffset(8)] int scode;
53 | [FieldOffset(8)] System.Runtime.InteropServices.ComTypes.FILETIME filetime;
54 | [FieldOffset(8)] IntPtr everything_else;
55 |
56 | //I'm sure there is a more efficient way to do this but this works ..for now..
57 | internal byte[] GetBlob()
58 | {
59 | byte[] Result = new byte[blobVal.Length];
60 | for (int i = 0; i < blobVal.Length; i++)
61 | {
62 | Result[i] = Marshal.ReadByte((IntPtr) ((long)(blobVal.Data) + i));
63 | }
64 | return Result;
65 | }
66 |
67 | public object Value
68 | {
69 | get
70 | {
71 | VarEnum ve = (VarEnum)vt;
72 | switch (ve)
73 | {
74 | case VarEnum.VT_I1:
75 | return bVal;
76 | case VarEnum.VT_I2:
77 | return iVal;
78 | case VarEnum.VT_I4:
79 | return lVal;
80 | case VarEnum.VT_I8:
81 | return hVal;
82 | case VarEnum.VT_INT:
83 | return iVal;
84 | case VarEnum.VT_UI4:
85 | return ulVal;
86 | case VarEnum.VT_LPWSTR:
87 | return Marshal.PtrToStringUni(everything_else);
88 | case VarEnum.VT_BLOB:
89 | return GetBlob();
90 | }
91 | return "FIXME Type = " + ve.ToString();
92 | }
93 | }
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/SystemVolumeControl/PropertyKey.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi
27 | {
28 | public struct PropertyKey
29 | {
30 | public Guid fmtid;
31 | public int pid;
32 | };
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/SystemVolumeControl/PropertyStore.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 | using CoreAudioApi.Interfaces;
26 | using System.Runtime.InteropServices;
27 |
28 | namespace CoreAudioApi
29 | {
30 | ///
31 | /// Property Store class, only supports reading properties at the moment.
32 | ///
33 | public class PropertyStore
34 | {
35 | private IPropertyStore _Store;
36 |
37 | public int Count
38 | {
39 | get
40 | {
41 | int Result;
42 | Marshal.ThrowExceptionForHR(_Store.GetCount(out Result));
43 | return Result;
44 | }
45 | }
46 |
47 | public PropertyStoreProperty this[int index]
48 | {
49 | get
50 | {
51 | PropVariant result;
52 | PropertyKey key = Get(index);
53 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
54 | return new PropertyStoreProperty(key, result);
55 | }
56 | }
57 |
58 | public bool Contains(Guid guid)
59 | {
60 | for (int i = 0; i < Count; i++)
61 | {
62 | PropertyKey key = Get(i);
63 | if (key.fmtid == guid)
64 | return true;
65 | }
66 | return false;
67 | }
68 |
69 | public PropertyStoreProperty this[Guid guid]
70 | {
71 | get
72 | {
73 | PropVariant result;
74 | for (int i = 0; i < Count; i++)
75 | {
76 | PropertyKey key = Get(i);
77 | if (key.fmtid == guid)
78 | {
79 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
80 | return new PropertyStoreProperty(key, result);
81 | }
82 | }
83 | return null;
84 | }
85 | }
86 |
87 | public PropertyKey Get(int index)
88 | {
89 | PropertyKey key;
90 | Marshal.ThrowExceptionForHR( _Store.GetAt(index, out key));
91 | return key;
92 | }
93 |
94 | public PropVariant GetValue(int index)
95 | {
96 | PropVariant result;
97 | PropertyKey key = Get(index);
98 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
99 | return result;
100 | }
101 |
102 | internal PropertyStore(IPropertyStore store)
103 | {
104 | _Store = store;
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/SystemVolumeControl/PropertyStoreProperty.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Text;
26 | using CoreAudioApi.Interfaces;
27 |
28 | namespace CoreAudioApi
29 | {
30 | public class PropertyStoreProperty
31 | {
32 | private PropertyKey _PropertyKey;
33 | private PropVariant _PropValue;
34 |
35 | internal PropertyStoreProperty(PropertyKey key, PropVariant value)
36 | {
37 | _PropertyKey = key;
38 | _PropValue = value;
39 | }
40 |
41 | public PropertyKey Key
42 | {
43 | get
44 | {
45 | return _PropertyKey;
46 | }
47 | }
48 |
49 | public object Value
50 | {
51 | get
52 | {
53 | return _PropValue.Value;
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/SystemVolumeControl/SessionCollection.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | //using System.Linq;
26 | using System.Text;
27 | using CoreAudioApi.Interfaces;
28 | using System.Runtime.InteropServices;
29 |
30 | namespace CoreAudioApi
31 | {
32 | public class SessionCollection
33 | {
34 | IAudioSessionEnumerator _AudioSessionEnumerator;
35 | internal SessionCollection(IAudioSessionEnumerator realEnumerator)
36 | {
37 | _AudioSessionEnumerator = realEnumerator;
38 | }
39 |
40 | public AudioSessionControl this[int index]
41 | {
42 | get
43 | {
44 | IAudioSessionControl2 _Result;
45 | Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetSession(index, out _Result));
46 | return new AudioSessionControl(_Result);
47 | }
48 | }
49 |
50 | public int Count
51 | {
52 | get
53 | {
54 | int result;
55 | Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetCount(out result));
56 | return (int)result;
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/SystemVolumeControl/SimpleAudioVolume.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using System;
24 | using System.Collections.Generic;
25 | //using System.Linq;
26 | using System.Text;
27 | using CoreAudioApi.Interfaces;
28 | using System.Runtime.InteropServices;
29 |
30 | namespace CoreAudioApi
31 | {
32 | public class SimpleAudioVolume
33 | {
34 | ISimpleAudioVolume _SimpleAudioVolume;
35 | internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume)
36 | {
37 | _SimpleAudioVolume = realSimpleVolume;
38 | }
39 |
40 | public float MasterVolume
41 | {
42 | get
43 | {
44 | float ret;
45 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMasterVolume(out ret));
46 | return ret;
47 | }
48 | set
49 | {
50 | Guid Empty = Guid.Empty;
51 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMasterVolume(value, ref Empty));
52 | }
53 | }
54 |
55 | public bool Mute
56 | {
57 | get
58 | {
59 | bool ret;
60 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMute(out ret));
61 | return ret;
62 | }
63 | set
64 | {
65 | Guid Empty = Guid.Empty;
66 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMute(value, ref Empty));
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/SystemVolumeControl/eStgmAccess.cs:
--------------------------------------------------------------------------------
1 | /*
2 | LICENSE
3 | -------
4 | Copyright (C) 2007-2010 Ray Molenkamp
5 |
6 | This source code is provided 'as-is', without any express or implied
7 | warranty. In no event will the authors be held liable for any damages
8 | arising from the use of this source code or the software it produces.
9 |
10 | Permission is granted to anyone to use this source code for any purpose,
11 | including commercial applications, and to alter it and redistribute it
12 | freely, subject to the following restrictions:
13 |
14 | 1. The origin of this source code must not be misrepresented; you must not
15 | claim that you wrote the original source code. If you use this source code
16 | in a product, an acknowledgment in the product documentation would be
17 | appreciated but is not required.
18 | 2. Altered source versions must be plainly marked as such, and must not be
19 | misrepresented as being the original source code.
20 | 3. This notice may not be removed or altered from any source distribution.
21 | */
22 | using System;
23 | using System.Collections.Generic;
24 | using System.Text;
25 |
26 | namespace CoreAudioApi.Interfaces
27 | {
28 | internal enum EStgmAccess
29 | {
30 | STGM_READ = 0x00000000,
31 | STGM_WRITE = 0x00000001,
32 | STGM_READWRITE = 0x00000002
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/bin/Debug/CoreAudioApi.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/bin/Debug/CoreAudioApi.exe
--------------------------------------------------------------------------------
/bin/Debug/CoreAudioApi.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/bin/Debug/CoreAudioApi.pdb
--------------------------------------------------------------------------------
/bin/Release/CoreAudioApi.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/bin/Release/CoreAudioApi.exe
--------------------------------------------------------------------------------
/bin/Release/CoreAudioApi.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/bin/Release/CoreAudioApi.pdb
--------------------------------------------------------------------------------
/bin/Release/音量控制.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/bin/Release/音量控制.exe
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.Form1.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/CoreAudioApi.Form1.resources
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.Properties.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/CoreAudioApi.Properties.Resources.resources
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 61b9c8db36d8377970797a2acd3ae86205031f91
2 |
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\bin\Debug\CoreAudioApi.exe
2 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\bin\Debug\CoreAudioApi.pdb
3 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.Form1.resources
4 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.Properties.Resources.resources
5 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.csproj.GenerateResource.cache
6 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.csproj.CoreCompileInputs.cache
7 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.exe
8 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Debug\CoreAudioApi.pdb
9 |
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.csproj.GenerateResource.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/CoreAudioApi.csproj.GenerateResource.cache
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/CoreAudioApi.exe
--------------------------------------------------------------------------------
/obj/Debug/CoreAudioApi.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/CoreAudioApi.pdb
--------------------------------------------------------------------------------
/obj/Debug/DesignTimeResolveAssemblyReferences.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/DesignTimeResolveAssemblyReferences.cache
--------------------------------------------------------------------------------
/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.Form1.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.Form1.resources
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.Properties.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.Properties.Resources.resources
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 61b9c8db36d8377970797a2acd3ae86205031f91
2 |
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\bin\Release\CoreAudioApi.exe
2 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\bin\Release\CoreAudioApi.pdb
3 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.Form1.resources
4 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.Properties.Resources.resources
5 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.csproj.GenerateResource.cache
6 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.csproj.CoreCompileInputs.cache
7 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.exe
8 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.pdb
9 | E:\ProjectsVS\CoreAudioApi\CoreAudioApi\obj\Release\CoreAudioApi.csprojAssemblyReference.cache
10 |
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.csproj.GenerateResource.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.csproj.GenerateResource.cache
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.exe
--------------------------------------------------------------------------------
/obj/Release/CoreAudioApi.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/CoreAudioApi.pdb
--------------------------------------------------------------------------------
/obj/Release/DesignTimeResolveAssemblyReferences.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/DesignTimeResolveAssemblyReferences.cache
--------------------------------------------------------------------------------
/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yuxianqiang/CoreAudioApi/6b27c83b59dcec1fd257b89555130a8914be9aef/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------