├── .gitattributes ├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── .vscode └── settings.json ├── Assets └── coreaudio-sample-sessions.png ├── CoreAudio.sln ├── CoreAudio ├── AudioEndPointVolumeVolumeRange.cs ├── AudioEndpointVolume.cs ├── AudioEndpointVolumeCallback.cs ├── AudioEndpointVolumeChannel.cs ├── AudioEndpointVolumeChannels.cs ├── AudioEndpointVolumeNotificationDelegate.cs ├── AudioEndpointVolumeStepInformation.cs ├── AudioLoudness.cs ├── AudioMeterInformation.cs ├── AudioMeterInformationChannels.cs ├── AudioMute.cs ├── AudioPeakMeter.cs ├── AudioSessionControl.cs ├── AudioSessionControl2.cs ├── AudioSessionEvents.cs ├── AudioSessionManager.cs ├── AudioSessionManager2.cs ├── AudioSessionNotification.cs ├── AudioVolumeLevel.cs ├── AudioVolumeNotificationData.cs ├── CPolicyConfigClient.cs ├── CPolicyConfigVistaClient.cs ├── Connector.cs ├── Constants │ ├── AudioClientBufferFlags.cs │ ├── AudioClientReturnFlags.cs │ ├── AudioClientSessionFlags.cs │ ├── AudioClientStreamFlags.cs │ ├── DeviceState.cs │ └── EndpointHardwareSupport.cs ├── ControlChangeNotify.cs ├── ControlInterface.cs ├── CoreAudio.csproj ├── DefaultDeviceChangedEventArgs.cs ├── DeviceNotificationEventArgs.cs ├── DevicePropertyChangedEventArgs.cs ├── DeviceStateChangedEventArgs.cs ├── DeviceTopology.cs ├── Enumerations │ ├── AudioClientShareMode.cs │ ├── AudioSessionDisconnectReason.cs │ ├── AudioSessionState.cs │ ├── ConnectorType.cs │ ├── DataFlow.cs │ ├── EEndpointHardwareSupport.cs │ ├── KsCategory.cs │ ├── KsNodeType.cs │ ├── PartType.cs │ ├── REFIID.cs │ └── Role.cs ├── Interfaces │ ├── Blob.cs │ ├── CLSCTX.cs │ ├── DeviceTopology │ │ ├── IAudioLoudness.cs │ │ ├── IAudioMute.cs │ │ ├── IAudioPeakMeter.cs │ │ ├── IAudioVolumeLevel.cs │ │ ├── IConnector.cs │ │ ├── IControlChangeNotify.cs │ │ ├── IControlInterface.cs │ │ ├── IDeviceTopology.cs │ │ ├── IPart.cs │ │ ├── IPartsList.cs │ │ ├── IPerChannelDbLevel.cs │ │ └── ISubunit.cs │ ├── EndpointVolume │ │ ├── IAudioEndpointVolume.cs │ │ ├── IAudioEndpointVolumeCallback.cs │ │ └── IAudioMeterInformation.cs │ ├── IPolicyConfig.cs │ ├── IPolicyConfigVista.cs │ ├── IPropertyStore.cs │ ├── MMDevice │ │ ├── IMMDevice.cs │ │ ├── IMMDeviceCollection.cs │ │ ├── IMMDeviceEnumerator.cs │ │ ├── IMMEndpoint.cs │ │ └── IMMNotificationClient.cs │ ├── Undocumented │ │ ├── IAudioPolicyConfigFactory.cs │ │ ├── IAudioPolicyConfigFactoryVariantFor21H2.cs │ │ └── IAudioPolicyConfigFactoryVariantForDownlevel.cs │ ├── WASAPI │ │ ├── IAudioCaptureClient.cs │ │ ├── IAudioClient.cs │ │ ├── IAudioSessionControl.cs │ │ ├── IAudioSessionControl2.cs │ │ ├── IAudioSessionEnumerator.cs │ │ ├── IAudioSessionEvents.cs │ │ ├── IAudioSessionManager.cs │ │ ├── IAudioSessionManager2.cs │ │ ├── IAudioSessionNotification.cs │ │ └── ISimpleAudioVolume.cs │ └── eStgmAccess.cs ├── MMDevice.cs ├── MMDeviceCollection.cs ├── MMDeviceEnumerator.cs ├── MMNotificationClient.cs ├── PKEY.cs ├── Part.cs ├── PartsList.cs ├── PerChannelDbLevel.cs ├── PropVariant.cs ├── PropertyStore.cs ├── PropertyStoreProperty.cs ├── SessionCollection.cs ├── SimpleAudioVolume.cs ├── Structures │ ├── AudioVolumeNotificationData.cs │ ├── PROPERTYKEY.cs │ └── WAVEFORMATEX.cs ├── Subunit.cs ├── Undocumented │ ├── AudioPolicyConfigFactory.cs │ ├── AudioPolicyConfigFactoryVariantFor21H2.cs │ └── AudioPolicyConfigFactoryVariantForDownlevel.cs └── coreaudio.png ├── LICENSE ├── README.md └── samples ├── CoreAudioConsole.Core.Sample ├── CoreAudioConsole.Core.Sample.csproj └── Program.cs ├── CoreAudioConsole.Framework.Discover ├── App.config ├── CoreAudioForms.Framework.Discover.csproj ├── FormMain.Designer.cs ├── FormMain.cs ├── FormMain.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── Win32API.cs ├── CoreAudioConsole.Framework.Sample ├── App.config ├── CoreAudioConsole.Framework.Sample.csproj ├── Program.cs └── Properties │ └── AssemblyInfo.cs ├── CoreAudioForms.Core.Sample ├── CoreAudioForms.Core.Sample.csproj ├── FormMain.Designer.cs ├── FormMain.cs ├── FormMain.resx └── Program.cs ├── CoreAudioForms.Framework.Sample ├── App.config ├── CoreAudioForms.Framework.Sample.csproj ├── FormMain.Designer.cs ├── FormMain.cs ├── FormMain.resx ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── CoreAudioForms.Framework.Sessions ├── App.config ├── CoreAudioForms.Framework.Sessions.csproj ├── FormMain.Designer.cs ├── FormMain.cs ├── FormMain.resx ├── NativeMethods.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings └── UI ├── GraphicsExtension.cs ├── MACTrackBarLib ├── ColorHelper.cs ├── DrawMACStyleHelper.cs ├── MACTrackBar.bmp ├── MACTrackBar.cs ├── MACTrackBar.resx └── MACTrackBarDesigner.cs ├── SessionUI.Designer.cs ├── SessionUI.cs ├── SessionUI.resx ├── VU.Designer.cs ├── VU.cs └── VU.resx /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | 9 | runs-on: windows-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v1 16 | with: 17 | dotnet-version: 5.0.x 18 | 19 | - name: Build 20 | run: dotnet build ./CoreAudio/CoreAudio.csproj 21 | 22 | - name: Test 23 | run: dotnet test --no-build --verbosity normal 24 | 25 | - name: Set version in project file 26 | uses: roryprimrose/set-vs-sdk-project-version@v1 27 | with: 28 | version: 1.${{ github.run_number }}.0 29 | 30 | - name: Publish NuGet 31 | # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} 32 | uses: rohith/publish-nuget@v2 33 | with: 34 | PROJECT_FILE_PATH: ./CoreAudio/CoreAudio.csproj 35 | VERSION_STATIC: 1.${{ github.run_number }}.0 36 | TAG_COMMIT: true 37 | NUGET_KEY: ${{ secrets.NUGET_KEY }} 38 | INCLUDE_SYMBOLS: false 39 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dotnet.defaultSolution": "CoreAudio.sln" 3 | } -------------------------------------------------------------------------------- /Assets/coreaudio-sample-sessions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/morphx666/CoreAudio/024019df5f9e8b4eae4e129b67cf0a4f70675fab/Assets/coreaudio-sample-sessions.png -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System.Runtime.InteropServices; 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioEndPointVolumeVolumeRange { 28 | readonly float volumeMindB; 29 | readonly float volumeMaxdB; 30 | readonly float volumeIncrementdB; 31 | 32 | internal AudioEndPointVolumeVolumeRange(IAudioEndpointVolume parent) { 33 | Marshal.ThrowExceptionForHR(parent.GetVolumeRange(out volumeMindB, out volumeMaxdB, out volumeIncrementdB)); 34 | } 35 | 36 | public float MindB => volumeMindB; 37 | 38 | public float MaxdB => volumeMaxdB; 39 | 40 | public float IncrementdB => volumeIncrementdB; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CoreAudio/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 | /* Updated by John de Jong (2020/04/02) */ 23 | 24 | using System; 25 | using System.Runtime.InteropServices; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio { 29 | // This class implements the IAudioEndpointVolumeCallback interface, 30 | // it is implemented in this class because implementing it on AudioEndpointVolume 31 | // (where the functionality is really wanted, would cause the OnNotify function 32 | // to show up in the public API. 33 | internal class AudioEndpointVolumeCallback : IAudioEndpointVolumeCallback { 34 | readonly AudioEndpointVolume parent; 35 | 36 | internal AudioEndpointVolumeCallback(AudioEndpointVolume parent) { 37 | this.parent = parent; 38 | } 39 | 40 | [PreserveSig] 41 | public int OnNotify(IntPtr NotifyData) { 42 | //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the 43 | //number of audio channels available we cannot just call PtrToStructure 44 | //to get all data, that's why it is split up into two steps, first the static 45 | //data is marshalled into the data structure, then with some IntPtr math the 46 | //remaining floats are read from memory. 47 | // 48 | var data = Marshal.PtrToStructure(NotifyData); 49 | //if (data.GuidEventContext == parent.eventContext) 50 | // return 0; //S_OK 51 | 52 | //Determine offset in structure of the first float 53 | var Offset = Marshal.OffsetOf("ChannelVolume"); 54 | //Determine offset in memory of the first float 55 | var FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset); 56 | 57 | float[] voldata = new float[data.Channels]; 58 | 59 | //Read all floats from memory. 60 | for(var i = 0; i < data.Channels; i++) { 61 | voldata[i] = Marshal.PtrToStructure(FirstFloatPtr); 62 | } 63 | 64 | //Create combined structure and Fire Event in parent class. 65 | AudioVolumeNotificationData NotificationData = new(data.GuidEventContext, data.Muted, data.MasterVolume, voldata); 66 | parent.FireNotification(NotificationData); 67 | return 0; //S_OK 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CoreAudio/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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class AudioEndpointVolumeChannel { 29 | readonly uint channel; 30 | readonly IAudioEndpointVolume audioEndpointVolume; 31 | internal Guid eventContext; 32 | 33 | internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel, ref Guid eventContext) { 34 | audioEndpointVolume = parent; 35 | this.channel = (uint)channel; 36 | this.eventContext = eventContext; 37 | } 38 | 39 | public float VolumeLevel { 40 | get { 41 | Marshal.ThrowExceptionForHR(audioEndpointVolume.GetChannelVolumeLevel(channel, out var result)); 42 | return result; 43 | } 44 | set => Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevel(channel, value, ref eventContext)); 45 | } 46 | 47 | public float VolumeLevelScalar { 48 | get { 49 | Marshal.ThrowExceptionForHR(audioEndpointVolume.GetChannelVolumeLevelScalar(channel, out var result)); 50 | return result; 51 | } 52 | set => Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevelScalar(channel, value, ref eventContext)); 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /CoreAudio/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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class AudioEndpointVolumeChannels { 29 | readonly IAudioEndpointVolume audioEndPointVolume; 30 | readonly AudioEndpointVolumeChannel[] channels; 31 | internal Guid eventContext; 32 | 33 | public int Count { 34 | get { 35 | Marshal.ThrowExceptionForHR(audioEndPointVolume.GetChannelCount(out var result)); 36 | return result; 37 | } 38 | } 39 | 40 | public AudioEndpointVolumeChannel this[int index] => channels[index]; 41 | 42 | internal AudioEndpointVolumeChannels(IAudioEndpointVolume parent, ref Guid eventContext) { 43 | int channelCount; 44 | audioEndPointVolume = parent; 45 | this.eventContext = eventContext; 46 | 47 | channelCount = Count; 48 | channels = new AudioEndpointVolumeChannel[channelCount]; 49 | for(var i = 0; i < channelCount; i++) { 50 | channels[i] = new AudioEndpointVolumeChannel(audioEndPointVolume, i, ref eventContext); 51 | } 52 | } 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /CoreAudio/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 | namespace CoreAudio { 24 | public delegate void AudioEndpointVolumeNotificationDelegate(AudioVolumeNotificationData data); 25 | } 26 | -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System.Runtime.InteropServices; 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioEndpointVolumeStepInformation { 28 | readonly uint step; 29 | readonly uint stepCount; 30 | 31 | internal AudioEndpointVolumeStepInformation(IAudioEndpointVolume parent) { 32 | Marshal.ThrowExceptionForHR(parent.GetVolumeStepInfo(out step, out stepCount)); 33 | } 34 | 35 | public uint Step => step; 36 | 37 | public uint StepCount => stepCount; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreAudio/AudioLoudness.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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class AudioLoudness { 29 | readonly IAudioLoudness audioLoudness; 30 | internal Guid eventContext; 31 | 32 | internal AudioLoudness(IAudioLoudness audioLoudness, ref Guid eventContext) { 33 | this.audioLoudness = audioLoudness; 34 | this.eventContext = eventContext; 35 | } 36 | 37 | public bool Enabled { 38 | get { 39 | Marshal.ThrowExceptionForHR(audioLoudness.GetEnabled(out bool enabled)); 40 | return enabled; 41 | } 42 | set => Marshal.ThrowExceptionForHR(audioLoudness.SetEnabled(value, ref eventContext)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System.Runtime.InteropServices; 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioMeterInformation { 28 | readonly IAudioMeterInformation audioMeterInformation; 29 | readonly EEndpointHardwareSupport hardwareSupport; 30 | readonly AudioMeterInformationChannels channels; 31 | 32 | internal AudioMeterInformation(IAudioMeterInformation realInterface) { 33 | audioMeterInformation = realInterface; 34 | Marshal.ThrowExceptionForHR(audioMeterInformation.QueryHardwareSupport(out var HardwareSupp)); 35 | hardwareSupport = (EEndpointHardwareSupport)HardwareSupp; 36 | channels = new AudioMeterInformationChannels(audioMeterInformation); 37 | } 38 | 39 | public AudioMeterInformationChannels PeakValues => channels; 40 | 41 | public EEndpointHardwareSupport HardwareSupport => hardwareSupport; 42 | 43 | public float MasterPeakValue { 44 | get { 45 | Marshal.ThrowExceptionForHR(audioMeterInformation.GetPeakValue(out var result)); 46 | return result; 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System.Runtime.InteropServices; 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioMeterInformationChannels { 28 | readonly IAudioMeterInformation audioMeterInformation; 29 | 30 | public int Count { 31 | get { 32 | Marshal.ThrowExceptionForHR(audioMeterInformation.GetMeteringChannelCount(out var result)); 33 | return result; 34 | } 35 | } 36 | 37 | public float this[int index] { 38 | get { 39 | float[] peakValues = new float[Count]; 40 | GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned); 41 | Marshal.ThrowExceptionForHR(audioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject())); 42 | Params.Free(); 43 | return peakValues[index]; 44 | } 45 | } 46 | 47 | internal AudioMeterInformationChannels(IAudioMeterInformation parent) { 48 | audioMeterInformation = parent; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /CoreAudio/AudioMute.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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class AudioMute { 29 | readonly IAudioMute audioMute; 30 | internal Guid eventContext; 31 | 32 | internal AudioMute(IAudioMute audioMute, ref Guid eventContext) { 33 | this.audioMute = audioMute; 34 | this.eventContext = eventContext; 35 | } 36 | 37 | public bool Mute { 38 | get { 39 | Marshal.ThrowExceptionForHR(audioMute.GetMute(out var muted)); 40 | return muted; 41 | } 42 | set => Marshal.ThrowExceptionForHR(audioMute.SetMute(value, ref eventContext)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CoreAudio/AudioPeakMeter.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 CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioPeakMeter { 28 | IAudioPeakMeter audioPeakMeter; 29 | 30 | internal AudioPeakMeter(IAudioPeakMeter audioPeakMeter) { 31 | this.audioPeakMeter = audioPeakMeter; 32 | } 33 | 34 | public int ChannelCount { 35 | get { 36 | Marshal.ThrowExceptionForHR(audioPeakMeter.GetChannelCount(out var count)); 37 | return count; 38 | } 39 | } 40 | 41 | public float Level(int channel) { 42 | Marshal.ThrowExceptionForHR(audioPeakMeter.GetLevel((uint)channel, out var level)); 43 | return level; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CoreAudio/AudioSessionEvents.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 | /* Updated by John de Jong (2020/04/02) */ 23 | 24 | using System; 25 | using System.Runtime.InteropServices; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio { 29 | internal class AudioSessionEvents : IAudioSessionEvents { 30 | IIAudioSessionControl parent; 31 | 32 | internal AudioSessionEvents(IIAudioSessionControl parent) { 33 | this.parent = parent; 34 | } 35 | 36 | [PreserveSig] 37 | public int OnDisplayNameChanged([MarshalAs(UnmanagedType.LPWStr)] string newDisplayName, ref Guid eventContext) { 38 | parent.FireDisplayNameChanged(newDisplayName, ref eventContext); 39 | return 0; 40 | } 41 | 42 | [PreserveSig] 43 | public int OnIconPathChanged([MarshalAs(UnmanagedType.LPWStr)] string newIconPath, ref Guid eventContext) { 44 | parent.FireOnIconPathChanged(newIconPath, ref eventContext); 45 | return 0; 46 | } 47 | 48 | [PreserveSig] 49 | public int OnSimpleVolumeChanged(float newVolume, bool newMute, ref Guid eventContext) { 50 | parent.FireSimpleVolumeChanged(newVolume, newMute, ref eventContext); 51 | return 0; 52 | } 53 | 54 | [PreserveSig] 55 | public int OnChannelVolumeChanged(uint channelCount, IntPtr newChannelVolumeArray, uint changedChannel, ref Guid eventContext) { 56 | parent.FireChannelVolumeChanged(channelCount, newChannelVolumeArray, changedChannel, ref eventContext); 57 | return 0; 58 | } 59 | 60 | [PreserveSig] 61 | public int OnGroupingParamChanged(ref Guid newGroupingParam, ref Guid eventContext) { 62 | return 0; 63 | } 64 | 65 | [PreserveSig] 66 | public int OnStateChanged(AudioSessionState newState) { 67 | parent.FireStateChanged(newState); 68 | return 0; 69 | } 70 | 71 | [PreserveSig] 72 | public int OnSessionDisconnected(AudioSessionDisconnectReason disconnectReason) { 73 | return 0; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /CoreAudio/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 CoreAudio.Interfaces; 24 | 25 | namespace CoreAudio { 26 | public class AudioSessionManager { 27 | IAudioSessionManager audioSessionManager; 28 | 29 | internal AudioSessionManager(IAudioSessionManager realAudioSessionManager) { 30 | audioSessionManager = realAudioSessionManager; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/AudioSessionManager2.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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class AudioSessionManager2 : IDisposable { 29 | readonly IAudioSessionManager2 audioSessionManager2; 30 | SessionCollection? sessions; 31 | 32 | public delegate void SessionCreatedDelegate(object sender, IAudioSessionControl2 newSession); 33 | public event SessionCreatedDelegate? OnSessionCreated; 34 | internal Guid eventContext; 35 | 36 | AudioSessionNotification? _AudioSessionNotification; 37 | 38 | internal AudioSessionManager2(IAudioSessionManager2 realAudioSessionManager2, ref Guid eventContext) { 39 | audioSessionManager2 = realAudioSessionManager2; 40 | this.eventContext = eventContext; 41 | RefreshSessions(); 42 | } 43 | 44 | internal void FireSessionCreated(IAudioSessionControl2 newSession) { 45 | OnSessionCreated?.Invoke(this, newSession); 46 | } 47 | 48 | public void RefreshSessions() { 49 | UnregisterNotifications(); 50 | 51 | Marshal.ThrowExceptionForHR(audioSessionManager2.GetSessionEnumerator(out IAudioSessionEnumerator sessionEnum)); 52 | sessions = new SessionCollection(sessionEnum, ref eventContext); 53 | 54 | _AudioSessionNotification = new AudioSessionNotification(this); 55 | Marshal.ThrowExceptionForHR(audioSessionManager2.RegisterSessionNotification(_AudioSessionNotification)); 56 | } 57 | 58 | public SessionCollection? Sessions => sessions; 59 | 60 | void UnregisterNotifications() { 61 | sessions = null; 62 | 63 | if(_AudioSessionNotification != null) { 64 | try { 65 | Marshal.ThrowExceptionForHR(audioSessionManager2.UnregisterSessionNotification(_AudioSessionNotification)); 66 | } catch { } 67 | } 68 | } 69 | 70 | public void Dispose() { 71 | UnregisterNotifications(); 72 | } 73 | 74 | ~AudioSessionManager2() { 75 | Dispose(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /CoreAudio/AudioSessionNotification.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 CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | internal class AudioSessionNotification : IAudioSessionNotification { 28 | readonly AudioSessionManager2 parent; 29 | 30 | internal AudioSessionNotification(AudioSessionManager2 parent) { 31 | this.parent = parent; 32 | } 33 | 34 | [PreserveSig] 35 | public int OnSessionCreated(IAudioSessionControl2 NewSession) { 36 | parent.FireSessionCreated(NewSession); 37 | return 0; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudio/AudioVolumeLevel.cs: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | LICENSE 4 | ------- 5 | Copyright (C) 2007-2010 Ray Molenkamp 6 | 7 | This source code is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this source code or the software it produces. 10 | 11 | Permission is granted to anyone to use this source code for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this source code must not be misrepresented; you must not 16 | claim that you wrote the original source code. If you use this source code 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | */ 23 | 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class AudioVolumeLevel : PerChannelDbLevel { 28 | internal AudioVolumeLevel(IAudioVolumeLevel audioVolumeLevel) : base(audioVolumeLevel) { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System; 24 | 25 | namespace CoreAudio { 26 | public class AudioVolumeNotificationData { 27 | internal Guid eventContext; 28 | readonly bool muted; 29 | readonly float masterVolume; 30 | readonly int channels; 31 | readonly float[] channelVolume; 32 | 33 | public Guid EventContext => eventContext; 34 | 35 | public bool Muted => muted; 36 | 37 | public float MasterVolume => masterVolume; 38 | 39 | public int Channels => channels; 40 | 41 | public float[] ChannelVolume => channelVolume; 42 | 43 | public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume) { 44 | this.eventContext = eventContext; 45 | this.muted = muted; 46 | this.masterVolume = masterVolume; 47 | this.channels = channelVolume.Length; 48 | this.channelVolume = channelVolume; 49 | } 50 | 51 | public AudioVolumeNotificationData(bool muted, float masterVolume, float[] channelVolume) : 52 | this(Guid.Empty, muted, masterVolume, channelVolume) { 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CoreAudio/CPolicyConfigClient.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using CoreAudio.Interfaces; 3 | 4 | namespace CoreAudio { 5 | [ComImport, Guid("870af99c-171d-4f9e-af0d-e63df40c2bc9")] 6 | internal class CCPolicyConfigClient { 7 | } 8 | 9 | public class CPolicyConfigClient { 10 | IPolicyConfig policyConfigClient = (IPolicyConfig)new CCPolicyConfigClient(); 11 | 12 | public int SetDefaultDevice(string deviceID) { 13 | policyConfigClient.SetDefaultEndpoint(deviceID, Role.Console); 14 | policyConfigClient.SetDefaultEndpoint(deviceID, Role.Multimedia); 15 | policyConfigClient.SetDefaultEndpoint(deviceID, Role.Communications); 16 | 17 | return 0; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CoreAudio/CPolicyConfigVistaClient.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using CoreAudio.Interfaces; 3 | 4 | namespace CoreAudio { 5 | [ComImport, Guid("294935CE-F637-4E7C-A41B-AB255460B862")] 6 | internal class CCPolicyConfigVistaClient { 7 | } 8 | 9 | public class CPolicyConfigVistaClient { 10 | IPolicyConfigVista policyConfigVistaClient = (IPolicyConfigVista)new CCPolicyConfigVistaClient(); 11 | 12 | public int SetDefaultDevice(string deviceID) { 13 | policyConfigVistaClient.SetDefaultEndpoint(deviceID, Role.Console); 14 | policyConfigVistaClient.SetDefaultEndpoint(deviceID, Role.Multimedia); 15 | policyConfigVistaClient.SetDefaultEndpoint(deviceID, Role.Communications); 16 | 17 | return 0; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AudioClientBufferFlags.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | namespace CoreAudio { 26 | public enum AudioClientBufferFlags { 27 | DataDiscontinuity = 0x1, 28 | Silent = 0x2, 29 | TimestampError = 0x4 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AudioClientReturnFlags.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | 27 | namespace CoreAudio { 28 | [Flags] 29 | public enum AudioClientReturnFlags : uint { 30 | Ok = 0, 31 | NotInitialized = 0x001, 32 | AlreadyInitialized = 0x002, 33 | WrongEndpointType = 0x003, 34 | DeviceInvalidated = 0x004, 35 | NotStopped = 0x005, 36 | BufferTooLarge = 0x006, 37 | OutOfOrder = 0x007, 38 | UnsupportedFormat = 0x008, 39 | InvalidSize = 0x009, 40 | DeviceInUse = 0x00a, 41 | BufferOperationPending = 0x00b, 42 | ThreadNotRegistered = 0x00c, 43 | ExclusiveModeNotAllowed = 0x00e, 44 | EndpointCreateFailed = 0x00f, 45 | ServiceNotRunning = 0x010, 46 | EventhandleNotExpected = 0x011, 47 | ExclusiveModeOnly = 0x012, 48 | BufdurationPeriodNotEqual = 0x013, 49 | EventhandleNotSet = 0x014, 50 | IncorrectBufferSize = 0x015, 51 | BufferSizeError = 0x016, 52 | CpuusageExceeded = 0x017, 53 | BufferError = 0x018, 54 | BufferSizeNotAligned = 0x019, 55 | InvalidDevicePeriod = 0x020, 56 | BufferEmpty = 0x001, 57 | ThreadAlreadyRegistered = 0x002, 58 | PositionStalled = 0x003 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AudioClientSessionFlags.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | 27 | namespace CoreAudio { 28 | [Flags] 29 | public enum AudioClientSessionFlags : uint { 30 | ExpireWhenUnowned = 0x10000000, 31 | DisplayHide = 0x20000000, 32 | DisplayHideWhenExpired = 0x40000000 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AudioClientStreamFlags.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | 27 | namespace CoreAudio { 28 | [Flags] 29 | public enum AudioClientStreamFlags : uint { 30 | CrossProcess = 0x00010000, 31 | Loopback = 0x00020000, 32 | EventCallback = 0x00040000, 33 | NoPersist = 0x00080000, 34 | RateAdjust = 0x00100000 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreAudio/Constants/DeviceState.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 | /* Modified by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | 27 | namespace CoreAudio { 28 | [Flags] 29 | public enum DeviceState : uint { 30 | Active = 0x00000001, 31 | Disabled = 0x00000002, 32 | NotPresent = 0x00000004, 33 | Unplugged = 0x00000008, 34 | MaskAll = 0x0000000F 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreAudio/Constants/EndpointHardwareSupport.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | 27 | namespace CoreAudio { 28 | [Flags] 29 | public enum EndpointHardwareSupport : uint { 30 | Volume = 0x00000001, 31 | Mute = 0x00000002, 32 | Meter = 0x00000004 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/ControlChangeNotify.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.Diagnostics; 25 | using System.Runtime.InteropServices; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio { 29 | internal class ControlChangeNotify : IControlChangeNotify, IDisposable { 30 | readonly Part parent; 31 | GCHandle rcwHandle; 32 | 33 | internal ControlChangeNotify(Part parent) { 34 | this.parent = parent; 35 | rcwHandle = GCHandle.Alloc(this, GCHandleType.Normal); 36 | } 37 | 38 | public bool IsAllocated => rcwHandle.IsAllocated; 39 | 40 | [PreserveSig] 41 | public int OnNotify(uint dwSenderProcessId, ref Guid eventContext) { 42 | if(Process.GetCurrentProcess().Id != dwSenderProcessId) 43 | parent.FireNotification(dwSenderProcessId, ref eventContext); 44 | return 0; 45 | } 46 | 47 | #region IDisposable Members 48 | 49 | public void Dispose() { 50 | if(rcwHandle.IsAllocated) rcwHandle.Free(); 51 | } 52 | 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CoreAudio/ControlInterface.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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class ControlInterface { 29 | IControlInterface controlInterface; 30 | 31 | internal ControlInterface(IControlInterface controlInterface) { 32 | this.controlInterface = controlInterface; 33 | } 34 | 35 | public string GetName { 36 | get { 37 | Marshal.ThrowExceptionForHR(controlInterface.GetName(out string name)); 38 | return name; 39 | } 40 | } 41 | 42 | public Guid GetId { 43 | get { 44 | Marshal.ThrowExceptionForHR(controlInterface.GetID(out var id)); 45 | return id; 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CoreAudio/CoreAudio.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 2024.4.4.229 4 | 2024.4.4.229 5 | 9 6 | enable 7 | CoreAudio 8 | morphx666 9 | Windows CoreAudio wrapper for .NET 10 | https://github.com/morphx666/CoreAudio 11 | https://github.com/morphx666/CoreAudio 12 | net481;netstandard2.0;netstandard2.1 13 | README.md 14 | audio; coreaudio; 15 | coreaudio.png 16 | True 17 | snupkg 18 | git 19 | MIT 20 | 21 | 22 | 23 | false 24 | 25 | 26 | 27 | false 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CoreAudio/DefaultDeviceChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace CoreAudio { 2 | public class DefaultDeviceChangedEventArgs : DeviceNotificationEventArgs { 3 | public DataFlow DataFlow { get; private set; } 4 | public Role Role { get; private set; } 5 | 6 | public DefaultDeviceChangedEventArgs(string deviceId, DataFlow dataFlow, Role role) : base(deviceId) { 7 | DataFlow = dataFlow; 8 | Role = role; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CoreAudio/DeviceNotificationEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CoreAudio { 4 | public class DeviceNotificationEventArgs : EventArgs { 5 | public string DeviceId { get; private set; } 6 | 7 | public DeviceNotificationEventArgs(string deviceId) { 8 | DeviceId = deviceId; 9 | } 10 | 11 | public bool TryGetDevice(out MMDevice? device, Guid eventContext) { 12 | try { 13 | var deviceEnumerator = new MMDeviceEnumerator(eventContext); 14 | device = deviceEnumerator.GetDevice(DeviceId); 15 | return true; 16 | } catch(Exception) { 17 | device = null; 18 | } 19 | 20 | return false; 21 | } 22 | 23 | public bool TryGetDevice(out MMDevice? device) { 24 | return TryGetDevice(out device, Guid.Empty); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CoreAudio/DevicePropertyChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace CoreAudio { 2 | public class DevicePropertyChangedEventArgs : DeviceNotificationEventArgs { 3 | public PropertyKey PropertyKey { get; private set; } 4 | 5 | public DevicePropertyChangedEventArgs(string deviceId, PropertyKey propertyKey) : base(deviceId) { 6 | PropertyKey = propertyKey; 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CoreAudio/DeviceStateChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace CoreAudio { 2 | public class DeviceStateChangedEventArgs : DeviceNotificationEventArgs { 3 | public DeviceState DeviceState { get; private set; } 4 | 5 | public DeviceStateChangedEventArgs(string deviceId, DeviceState deviceState) : base(deviceId) { 6 | DeviceState = deviceState; 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CoreAudio/DeviceTopology.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 CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | public class DeviceTopology { 28 | IDeviceTopology deviceTopology; 29 | 30 | internal DeviceTopology(IDeviceTopology realInterface) { 31 | deviceTopology = realInterface; 32 | 33 | } 34 | 35 | public int GetConnectorCount { 36 | get { 37 | Marshal.ThrowExceptionForHR(deviceTopology.GetConnectorCount(out var count)); 38 | return count; 39 | } 40 | } 41 | 42 | public Connector GetConnector(int index) { 43 | Marshal.ThrowExceptionForHR(deviceTopology.GetConnector(index, out IConnector connector)); 44 | return new Connector(connector); 45 | } 46 | 47 | public int GetSubunitCount { 48 | get { 49 | Marshal.ThrowExceptionForHR(deviceTopology.GetSubunitCount(out var count)); 50 | return count; 51 | } 52 | } 53 | 54 | public Subunit GetSubunit(int index) { 55 | Marshal.ThrowExceptionForHR(deviceTopology.GetSubunit(index, out ISubunit subUnit)); 56 | return new Subunit(subUnit); 57 | } 58 | 59 | public Part GetPartById(int id) { 60 | Marshal.ThrowExceptionForHR(deviceTopology.GetPartById(id, out IPart part)); 61 | return new Part(part); 62 | } 63 | 64 | public string GetDeviceId { 65 | get { 66 | Marshal.ThrowExceptionForHR(deviceTopology.GetDeviceId(out string id)); 67 | return id; 68 | } 69 | } 70 | 71 | public PartsList GetSignalPath(Part from, Part to, bool rejectMixedPaths) { 72 | Marshal.ThrowExceptionForHR(deviceTopology.GetSignalPath((IPart)from, (IPart)to, rejectMixedPaths, out IPartsList partList)); 73 | return new PartsList(partList); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/AudioClientShareMode.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | namespace CoreAudio { 26 | public enum AudioClientShareMode { 27 | Shared, 28 | Exclusive 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/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 | 23 | namespace CoreAudio { 24 | public enum AudioSessionDisconnectReason { 25 | DisconnectReasonDeviceRemoval = 0, 26 | DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1), 27 | DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1), 28 | DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1), 29 | DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1), 30 | DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/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 | 23 | namespace CoreAudio { 24 | public enum AudioSessionState { 25 | AudioSessionStateInactive = 0, 26 | AudioSessionStateActive = 1, 27 | AudioSessionStateExpired = 2 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/ConnectorType.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 | namespace CoreAudio { 24 | public enum ConnectorType { 25 | Unknown_Connector = 0, 26 | Physical_Internal = (Unknown_Connector + 1), 27 | Physical_External = (Physical_Internal + 1), 28 | Software_IO = (Physical_External + 1), 29 | Software_Fixed = (Software_IO + 1), 30 | Network = (Software_Fixed + 1) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/DataFlow.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 | namespace CoreAudio { 24 | public enum DataFlow { 25 | Render = 0, 26 | Capture = 1, 27 | All = 2 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/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 | 23 | using System; 24 | 25 | namespace CoreAudio { 26 | [Flags] 27 | public enum EEndpointHardwareSupport { 28 | Volume = 0x00000001, 29 | Mute = 0x00000002, 30 | Meter = 0x00000004 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/PartType.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 | namespace CoreAudio { 24 | public enum PartType { 25 | Connector = 0, 26 | Subunit = (Connector + 1) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/REFIID.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio { 29 | public class RefIId { 30 | public static Guid IIdIAudioCaptureClient = typeof(IAudioCaptureClient).GUID; 31 | //public static Guid IIdIAudioClock 32 | //public static Guid IIdIAudioRenderClient 33 | //public static Guid IIdIAudioSessionControl 34 | //public static Guid IIdIAudioStreamVolume 35 | //public static Guid IIdIChannelAudioVolume 36 | //public static Guid IIdIMFTrustedOutput 37 | 38 | public static Guid IIdISimpleAudioVolume = typeof(ISimpleAudioVolume).GUID; 39 | public static Guid IIdIAudioVolumeLevel = typeof(IAudioVolumeLevel).GUID; 40 | public static Guid IIdIAudioMute = typeof(IAudioMute).GUID; 41 | public static Guid IIdIAudioPeakMeter = typeof(IAudioPeakMeter).GUID; 42 | public static Guid IIdIAudioLoudness = typeof(IAudioLoudness).GUID; 43 | 44 | public static Guid IIdIAudioMeterInformation = typeof(IAudioMeterInformation).GUID; 45 | public static Guid IIdIAudioEndpointVolume = typeof(IAudioEndpointVolume).GUID; 46 | public static Guid IIdIAudioSessionManager2 = typeof(IAudioSessionManager2).GUID; 47 | public static Guid IIdIDeviceTopology = typeof(IDeviceTopology).GUID; 48 | 49 | public static Guid IIdIPart = typeof(IPart).GUID; 50 | public static Guid IIdIConnector = typeof(IConnector).GUID; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/Role.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 | namespace CoreAudio { 24 | public enum Role { 25 | Console = 0, 26 | Multimedia = 1, 27 | Communications = 2, 28 | EnumCount = 3 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/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 | 23 | using System; 24 | 25 | namespace CoreAudio.Interfaces { 26 | internal struct Blob { 27 | public int Length; 28 | public IntPtr Data; 29 | 30 | //Code Should Compile at warning level4 without any warnings, 31 | //However this struct will give us Warning CS0649: Field [Fieldname] 32 | //is never assigned to, and will always have its default value 33 | //You can disable CS0649 in the project options but that will disable 34 | //the warning for the whole project, it's a nice warning and we do want 35 | //it in other places so we make a nice dummy function to keep the compiler 36 | //happy. 37 | void FixCS0649() { 38 | Length = 0; 39 | Data = IntPtr.Zero; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/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 | 23 | using System; 24 | 25 | namespace CoreAudio.Interfaces { 26 | [Flags] 27 | internal enum CLSCTX : uint { 28 | INPROC_SERVER = 0x1, 29 | INPROC_HANDLER = 0x2, 30 | LOCAL_SERVER = 0x4, 31 | INPROC_SERVER16 = 0x8, 32 | REMOTE_SERVER = 0x10, 33 | INPROC_HANDLER16 = 0x20, 34 | RESERVED1 = 0x40, 35 | RESERVED2 = 0x80, 36 | RESERVED3 = 0x100, 37 | RESERVED4 = 0x200, 38 | NO_CODE_DOWNLOAD = 0x400, 39 | RESERVED5 = 0x800, 40 | NO_CUSTOM_MARSHAL = 0x1000, 41 | ENABLE_CODE_DOWNLOAD = 0x2000, 42 | NO_FAILURE_LOG = 0x4000, 43 | DISABLE_AAA = 0x8000, 44 | ENABLE_AAA = 0x10000, 45 | FROM_DEFAULT_CONTEXT = 0x20000, 46 | INPROC = INPROC_SERVER | INPROC_HANDLER, 47 | SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER, 48 | ALL = SERVER | INPROC_HANDLER 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IAudioLoudness.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("7D8B1437-DD53-4350-9C1B-1EE2890BD938"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioLoudness { 30 | int GetEnabled([Out, MarshalAs(UnmanagedType.Bool)] out bool enabled); 31 | int SetEnabled([MarshalAs(UnmanagedType.Bool)] bool enabled, ref Guid eventContext); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IAudioMute.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioMute { 30 | int SetMute([MarshalAs(UnmanagedType.Bool)] bool muted, ref Guid eventContext); 31 | int GetMute([Out, MarshalAs(UnmanagedType.Bool)] out bool muted); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/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 | 23 | using System.Runtime.InteropServices; 24 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("DD79923C-0599-45e0-B8B6-C8DF7DB6E796"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IAudioPeakMeter { 29 | int GetChannelCount(out int pcChannels); 30 | int GetLevel(uint channel, out float level); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IAudioVolumeLevel.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IAudioVolumeLevel : IPerChannelDbLevel { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IConnector.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("9c2c4058-23f5-41de-877a-df3af236a09e"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IConnector { 29 | [PreserveSig] 30 | int GetType(out ConnectorType type); 31 | [PreserveSig] 32 | int GetDataFlow(out DataFlow flow); 33 | [PreserveSig] 34 | int ConnectTo(IConnector connectTo); 35 | [PreserveSig] 36 | int Disconnect(); 37 | [PreserveSig] 38 | int IsConnected(out bool connected); 39 | [PreserveSig] 40 | int GetConnectedTo(out IConnector connectedTo); 41 | [PreserveSig] 42 | int GetConnectorIdConnectedTo([Out, MarshalAs(UnmanagedType.LPWStr)] out string connectorId); 43 | [PreserveSig] 44 | int GetDeviceIdConnectedTo([Out, MarshalAs(UnmanagedType.LPWStr)] out string deviceId); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IControlChangeNotify.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("A09513ED-C709-4d21-BD7B-5F34C47F3947"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IControlChangeNotify { 30 | [PreserveSig] 31 | int OnNotify(uint dwSenderProcessId, ref Guid eventContext); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IControlInterface.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("45d37c3f-5140-444a-ae24-400789f3cbf3"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IControlInterface { 30 | [PreserveSig] 31 | int GetName([Out, MarshalAs(UnmanagedType.LPWStr)] out string name); 32 | [PreserveSig] 33 | int GetID(out Guid id); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IDeviceTopology.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("2A07407E-6497-4A18-9787-32F79BD0D98F"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IDeviceTopology { 29 | [PreserveSig] 30 | int GetConnectorCount(out int count); 31 | [PreserveSig] 32 | int GetConnector(int index, out IConnector connector); 33 | [PreserveSig] 34 | int GetSubunitCount(out int count); 35 | [PreserveSig] 36 | int GetSubunit(int index, out ISubunit subunit); 37 | [PreserveSig] 38 | int GetPartById(int id, out IPart part); 39 | [PreserveSig] 40 | int GetDeviceId([Out, MarshalAs(UnmanagedType.LPWStr)] out string deviceId); 41 | [PreserveSig] 42 | int GetSignalPath(IPart partFrom, IPart partTo, bool rejectMixedPaths, out IPartsList parts); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IPart.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IPart { 30 | [PreserveSig] 31 | int GetName([Out, MarshalAs(UnmanagedType.LPWStr)] out string name); 32 | [PreserveSig] 33 | int GetLocalId(out int id); 34 | [PreserveSig] 35 | int GetGlobalId([Out, MarshalAs(UnmanagedType.LPWStr)] out string globalId); 36 | [PreserveSig] 37 | int GetPartType(out PartType partType); 38 | [PreserveSig] 39 | int GetSubType(out Guid subType); 40 | [PreserveSig] 41 | int GetControlInterfaceCount(out int count); 42 | [PreserveSig] 43 | int GetControlInterface(int index, out IControlInterface pInterface); 44 | [PreserveSig] 45 | int EnumPartsIncoming(out IPartsList? parts); 46 | [PreserveSig] 47 | int EnumPartsOutgoing(out IPartsList? parts); 48 | [PreserveSig] 49 | int GetTopologyObject(out IDeviceTopology topology); 50 | [PreserveSig] 51 | int Activate(CLSCTX dwClsContext, ref Guid refiid, [Out, MarshalAs(UnmanagedType.IUnknown)] out object? ppvObject); 52 | [PreserveSig] 53 | int RegisterControlChangeCallback(ref Guid refiid, IControlChangeNotify? notify); 54 | [PreserveSig] 55 | int UnregisterControlChangeCallback(IControlChangeNotify? notify); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IPartsList.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IPartsList { 29 | [PreserveSig] 30 | int GetCount(out int count); 31 | [PreserveSig] 32 | int GetPart(int index, out IPart part); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/IPerChannelDbLevel.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("C2F8E001-F205-4BC9-99BC-C13B1E048CCB"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IPerChannelDbLevel { 30 | [PreserveSig] 31 | int GetChannelCount(out uint count); 32 | [PreserveSig] 33 | int GetLevelRange(uint channel, out float minLevel, out float maxLevel, out float stepping); 34 | [PreserveSig] 35 | int GetLevel(uint channel, out float level); 36 | [PreserveSig] 37 | int SetLevel(uint channel, float level, out Guid eventContext); 38 | [PreserveSig] 39 | int SetLevelUniform(float level, out Guid eventContext); 40 | [PreserveSig] 41 | int SetLevelAllChannels(float[] levelsDB, ulong channels, ref Guid eventContext); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/DeviceTopology/ISubunit.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("82149A85-DBA6-4487-86BB-EA8F7FEFCC71"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface ISubunit { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/EndpointVolume/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioEndpointVolume { 30 | [PreserveSig] 31 | int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); 32 | [PreserveSig] 33 | int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); 34 | [PreserveSig] 35 | int GetChannelCount(out int pnChannelCount); 36 | [PreserveSig] 37 | int SetMasterVolumeLevel(float fLevelDB, ref Guid eventContext); 38 | [PreserveSig] 39 | int SetMasterVolumeLevelScalar(float fLevel, ref Guid eventContext); 40 | [PreserveSig] 41 | int GetMasterVolumeLevel(out float pfLevelDB); 42 | [PreserveSig] 43 | int GetMasterVolumeLevelScalar(out float pfLevel); 44 | [PreserveSig] 45 | int SetChannelVolumeLevel(uint nChannel, float fLevelDB, ref Guid eventContext); 46 | [PreserveSig] 47 | int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, ref Guid eventContext); 48 | [PreserveSig] 49 | int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB); 50 | [PreserveSig] 51 | int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel); 52 | [PreserveSig] 53 | int SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, ref Guid eventContext); 54 | [PreserveSig] 55 | int GetMute(out bool pbMute); 56 | [PreserveSig] 57 | int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount); 58 | [PreserveSig] 59 | int VolumeStepUp(Guid eventContext); 60 | [PreserveSig] 61 | int VolumeStepDown(Guid eventContext); 62 | [PreserveSig] 63 | int QueryHardwareSupport(out uint pdwHardwareSupportMask); 64 | [PreserveSig] 65 | int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/EndpointVolume/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("657804FA-D6AD-4496-8A60-352752AF4F89"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioEndpointVolumeCallback { 30 | [PreserveSig] 31 | int OnNotify(IntPtr pNotifyData); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/EndpointVolume/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioMeterInformation { 30 | [PreserveSig] 31 | int GetPeakValue(out float pfPeak); 32 | [PreserveSig] 33 | int GetMeteringChannelCount(out int pnChannelCount); 34 | [PreserveSig] 35 | int GetChannelsPeakValues(int u32ChannelCount, [In] IntPtr afPeakValues); 36 | [PreserveSig] 37 | int QueryHardwareSupport(out int pdwHardwareSupportMask); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/IPolicyConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | // http://eretik.omegahg.com/download/PolicyConfig.h 4 | // http://social.microsoft.com/Forums/en-US/Offtopic/thread/9ebd7ad6-a460-4a28-9de9-2af63fd4a13e/ 5 | 6 | namespace CoreAudio.Interfaces { 7 | [Guid("f8679f50-850a-41cf-9c72-430f290290c8"), 8 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 9 | internal interface IPolicyConfig { 10 | [PreserveSig] 11 | int GetMixFormat(); 12 | [PreserveSig] 13 | int GetDeviceFormat(); 14 | [PreserveSig] 15 | int SetDeviceFormat(); 16 | [PreserveSig] 17 | int GetProcessingPeriod(); 18 | [PreserveSig] 19 | int SetProcessingPeriod(); 20 | [PreserveSig] 21 | int GetShareMode(); 22 | [PreserveSig] 23 | int SetShareMode(); 24 | [PreserveSig] 25 | int GetPropertyValue(); 26 | [PreserveSig] 27 | int SetPropertyValue(); 28 | [PreserveSig] 29 | int SetDefaultEndpoint([MarshalAs(UnmanagedType.LPWStr)] string wszDeviceId, Role eRole); 30 | [PreserveSig] 31 | int SetEndpointVisibility(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/IPolicyConfigVista.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | // http://eretik.omegahg.com/download/PolicyConfig.h 4 | // http://social.microsoft.com/Forums/en-US/Offtopic/thread/9ebd7ad6-a460-4a28-9de9-2af63fd4a13e/ 5 | 6 | namespace CoreAudio.Interfaces { 7 | [Guid("568b9108-44bf-40b4-9006-86afe5b5a620"), 8 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 9 | internal interface IPolicyConfigVista { 10 | [PreserveSig] 11 | int GetMixFormat(); 12 | [PreserveSig] 13 | int GetDeviceFormat(); 14 | [PreserveSig] 15 | int SetDeviceFormat(); 16 | [PreserveSig] 17 | int GetProcessingPeriod(); 18 | [PreserveSig] 19 | int SetProcessingPeriod(); 20 | [PreserveSig] 21 | int GetShareMode(); 22 | [PreserveSig] 23 | int SetShareMode(); 24 | [PreserveSig] 25 | int GetPropertyValue(); 26 | [PreserveSig] 27 | int SetPropertyValue(); 28 | [PreserveSig] 29 | int SetDefaultEndpoint([MarshalAs(UnmanagedType.LPWStr)] string wszDeviceId, Role eRole); 30 | [PreserveSig] 31 | int SetEndpointVisibility(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/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 | 23 | using System.Runtime.InteropServices; 24 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IPropertyStore { 29 | [PreserveSig] 30 | int GetCount(out int count); 31 | [PreserveSig] 32 | int GetAt(int iProp, out PropertyKey pkey); 33 | [PreserveSig] 34 | int GetValue(ref PropertyKey key, out PropVariant pv); 35 | [PreserveSig] 36 | int SetValue(ref PropertyKey key, ref PropVariant propvar); 37 | [PreserveSig] 38 | int Commit(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/MMDevice/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("D666063F-1587-4E43-81F1-B948E807363F"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IMMDevice { 30 | [PreserveSig] 31 | int Activate(ref Guid iid, CLSCTX dwClsCtx, IntPtr pActivationParams, [Out, MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); 32 | [PreserveSig] 33 | int OpenPropertyStore(EStgmAccess stgmAccess, out IPropertyStore propertyStore); 34 | [PreserveSig] 35 | int GetId([Out, MarshalAs(UnmanagedType.LPWStr)] out string ppstrId); 36 | [PreserveSig] 37 | int GetState(out DeviceState pdwState); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/MMDevice/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 | 23 | using System.Runtime.InteropServices; 24 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IMMDeviceCollection { 29 | [PreserveSig] 30 | int GetCount(out uint pcDevices); 31 | [PreserveSig] 32 | int Item(uint nDevice, out IMMDevice Device); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/MMDevice/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IMMDeviceEnumerator { 30 | [PreserveSig] 31 | int EnumAudioEndpoints(DataFlow dataFlow, DeviceState StateMask, out IMMDeviceCollection device); 32 | [PreserveSig] 33 | int GetDefaultAudioEndpoint(DataFlow dataFlow, Role role, out IMMDevice ppEndpoint); 34 | //[PreserveSig] 35 | //int SetDefaultAudioEndpoint(IMMDevice ppEndpoint); 36 | [PreserveSig] 37 | int GetDevice(string pwstrId, out IMMDevice ppDevice); 38 | [PreserveSig] 39 | int RegisterEndpointNotificationCallback(IMMNotificationClient pClient); 40 | [PreserveSig] 41 | int UnregisterEndpointNotificationCallback(IMMNotificationClient pClient); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/MMDevice/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 | 23 | using System.Runtime.InteropServices; 24 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("1BE09788-6894-4089-8586-9A2A6C265AC5"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IMMEndpoint { 29 | [PreserveSig] 30 | int GetDataFlow(out DataFlow pDataFlow); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/MMDevice/IMMNotificationClient.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces { 28 | [Guid("7991EEC9-7E89-4D85-8390-6C703CEC60C0"), 29 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 30 | internal interface IMMNotificationClient { 31 | [PreserveSig] 32 | void OnDeviceStateChanged([In, MarshalAs(UnmanagedType.LPWStr)] string deviceId, DeviceState dwNewState); 33 | [PreserveSig] 34 | void OnDeviceAdded([In, MarshalAs(UnmanagedType.LPWStr)] string deviceId); 35 | [PreserveSig] 36 | void OnDeviceRemoved([In, MarshalAs(UnmanagedType.LPWStr)] string deviceId); 37 | [PreserveSig] 38 | void OnDefaultDeviceChanged(DataFlow flow, Role role, [In, MarshalAs(UnmanagedType.LPWStr)] string deviceId); 39 | [PreserveSig] 40 | void OnPropertyValueChanged([In, MarshalAs(UnmanagedType.LPWStr)] string deviceId, PropertyKey key); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/Undocumented/IAudioPolicyConfigFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | // Original code from the EarTrumpet project 4 | // https://github.com/File-New-Project/EarTrumpet 5 | 6 | namespace CoreAudio.Interfaces.Undocumented { 7 | public interface IAudioPolicyConfigFactory { 8 | int SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, IntPtr deviceId); 9 | int GetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, out string deviceId); 10 | int ClearAllPersistedApplicationDefaultEndpoints(); 11 | 12 | MMDevice? GetPersistedDefaultAudioEndpoint(MMDeviceEnumerator deviceEnumerator, int processId, DataFlow flow, Role role, DeviceState state = DeviceState.MaskAll); 13 | void SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, MMDevice device); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/Undocumented/IAudioPolicyConfigFactoryVariantFor21H2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | // Original code from the EarTrumpet project 5 | // https://github.com/File-New-Project/EarTrumpet 6 | 7 | namespace CoreAudio.Interfaces.Undocumented { 8 | [Guid("ab3d4648-e242-459f-b02f-541c70306324")] 9 | [InterfaceType(ComInterfaceType.InterfaceIsIInspectable)] 10 | public interface IAudioPolicyConfigFactoryVariantFor21H2 { 11 | int __incomplete__add_CtxVolumeChange(); 12 | int __incomplete__remove_CtxVolumeChanged(); 13 | int __incomplete__add_RingerVibrateStateChanged(); 14 | int __incomplete__remove_RingerVibrateStateChange(); 15 | int __incomplete__SetVolumeGroupGainForId(); 16 | int __incomplete__GetVolumeGroupGainForId(); 17 | int __incomplete__GetActiveVolumeGroupForEndpointId(); 18 | int __incomplete__GetVolumeGroupsForEndpoint(); 19 | int __incomplete__GetCurrentVolumeContext(); 20 | int __incomplete__SetVolumeGroupMuteForId(); 21 | int __incomplete__GetVolumeGroupMuteForId(); 22 | int __incomplete__SetRingerVibrateState(); 23 | int __incomplete__GetRingerVibrateState(); 24 | int __incomplete__SetPreferredChatApplication(); 25 | int __incomplete__ResetPreferredChatApplication(); 26 | int __incomplete__GetPreferredChatApplication(); 27 | int __incomplete__GetCurrentChatApplications(); 28 | int __incomplete__add_ChatContextChanged(); 29 | int __incomplete__remove_ChatContextChanged(); 30 | [PreserveSig] 31 | int SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, IntPtr deviceId); 32 | [PreserveSig] 33 | int GetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, [Out, MarshalAs(UnmanagedType.HString)] out string deviceId); 34 | [PreserveSig] 35 | int ClearAllPersistedApplicationDefaultEndpoints(); 36 | 37 | MMDevice? GetPersistedDefaultAudioEndpoint(MMDeviceEnumerator deviceEnumerator, int processId, DataFlow flow, Role role, DeviceState state = DeviceState.MaskAll); 38 | void SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, MMDevice device); 39 | } 40 | } -------------------------------------------------------------------------------- /CoreAudio/Interfaces/Undocumented/IAudioPolicyConfigFactoryVariantForDownlevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | // Original code from the EarTrumpet project 5 | // https://github.com/File-New-Project/EarTrumpet 6 | 7 | namespace CoreAudio.Interfaces.Undocumented { 8 | [Guid("2a59116d-6c4f-45e0-a74f-707e3fef9258")] 9 | [InterfaceType(ComInterfaceType.InterfaceIsIInspectable)] 10 | public interface IAudioPolicyConfigFactoryVariantForDownlevel { 11 | int __incomplete__add_CtxVolumeChange(); 12 | int __incomplete__remove_CtxVolumeChanged(); 13 | int __incomplete__add_RingerVibrateStateChanged(); 14 | int __incomplete__remove_RingerVibrateStateChange(); 15 | int __incomplete__SetVolumeGroupGainForId(); 16 | int __incomplete__GetVolumeGroupGainForId(); 17 | int __incomplete__GetActiveVolumeGroupForEndpointId(); 18 | int __incomplete__GetVolumeGroupsForEndpoint(); 19 | int __incomplete__GetCurrentVolumeContext(); 20 | int __incomplete__SetVolumeGroupMuteForId(); 21 | int __incomplete__GetVolumeGroupMuteForId(); 22 | int __incomplete__SetRingerVibrateState(); 23 | int __incomplete__GetRingerVibrateState(); 24 | int __incomplete__SetPreferredChatApplication(); 25 | int __incomplete__ResetPreferredChatApplication(); 26 | int __incomplete__GetPreferredChatApplication(); 27 | int __incomplete__GetCurrentChatApplications(); 28 | int __incomplete__add_ChatContextChanged(); 29 | int __incomplete__remove_ChatContextChanged(); 30 | [PreserveSig] 31 | int SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, IntPtr deviceId); 32 | [PreserveSig] 33 | int GetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, [Out, MarshalAs(UnmanagedType.HString)] out string deviceId); 34 | [PreserveSig] 35 | int ClearAllPersistedApplicationDefaultEndpoints(); 36 | 37 | MMDevice? GetPersistedDefaultAudioEndpoint(MMDeviceEnumerator deviceEnumerator, int processId, DataFlow flow, Role role, DeviceState state = DeviceState.MaskAll); 38 | void SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, MMDevice device); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/IAudioCaptureClient.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces { 28 | [Guid("C8ADBD64-E71E-48a0-A4DE-185C395CD317"), 29 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 30 | internal interface IAudioCaptureClient { 31 | [PreserveSig] 32 | AudioClientReturnFlags GetBuffer(out byte[] ppData, out AudioClientBufferFlags pNumFramesToRead, ulong pu64DevicePosition, ulong pu64QPCPosition); 33 | [PreserveSig] 34 | AudioClientReturnFlags ReleaseBuffer(uint NumFramesRead); 35 | [PreserveSig] 36 | AudioClientReturnFlags GetNextPacketSize(out uint pNumFramesInNextPacket); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/IAudioClient.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 | /* Created by Xavier Flix (2010/11/18) */ 24 | 25 | using System; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio.Interfaces { 29 | [Guid("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IAudioClient { 32 | [PreserveSig] 33 | AudioClientReturnFlags Initialize(AudioClientShareMode ShareMode, AudioClientStreamFlags StreamFlags, long hnsBufferDuration, long hnsPeriodicity, WaveFormatEx pFormat, Guid AudioSessionGuid); 34 | [PreserveSig] 35 | AudioClientReturnFlags GetBufferSize(out uint pNumBufferFrames); 36 | [PreserveSig] 37 | AudioClientReturnFlags GetStreamLatency(out long phnsLatency); 38 | [PreserveSig] 39 | AudioClientReturnFlags GetCurrentPadding(out long pNumPaddingFrames); 40 | [PreserveSig] 41 | AudioClientReturnFlags IsFormatSupported(AudioClientShareMode ShareMode, WaveFormatEx pFormat, out WaveFormatEx ppClosestMatch); 42 | [PreserveSig] 43 | AudioClientReturnFlags GetMixFormat(out WaveFormatEx ppDeviceFormat); 44 | [PreserveSig] 45 | AudioClientReturnFlags GetDevicePeriod(out long phnsDefaultDevicePeriod, out long phnsMinimumDevicePeriod); 46 | [PreserveSig] 47 | AudioClientReturnFlags Start(); 48 | [PreserveSig] 49 | AudioClientReturnFlags Stop(); 50 | [PreserveSig] 51 | AudioClientReturnFlags Reset(); 52 | [PreserveSig] 53 | AudioClientReturnFlags SetEventHandle(IntPtr eventHandle); 54 | [PreserveSig] 55 | AudioClientReturnFlags GetService(ref Guid riid, [Out, MarshalAs(UnmanagedType.IUnknown)] out object ppv); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/IAudioSessionControl.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("F4B1A599-7266-4319-A8CA-E70ACB11E8CD"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | public interface IAudioSessionControl { 30 | [PreserveSig] 31 | int GetState(out AudioSessionState state); 32 | [PreserveSig] 33 | int GetDisplayName([MarshalAs(UnmanagedType.LPWStr)] out string name); 34 | [PreserveSig] 35 | int SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string value, ref Guid eventContext); 36 | [PreserveSig] 37 | int GetIconPath([MarshalAs(UnmanagedType.LPWStr)] out string Path); 38 | [PreserveSig] 39 | int SetIconPath([MarshalAs(UnmanagedType.LPWStr)] string Value, ref Guid eventContext); 40 | [PreserveSig] 41 | int GetGroupingParam(out Guid GroupingParam); 42 | [PreserveSig] 43 | int SetGroupingParam(Guid Override, ref Guid eventContext); 44 | [PreserveSig] 45 | int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 46 | [PreserveSig] 47 | int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | public interface IAudioSessionControl2 { 30 | [PreserveSig] 31 | int GetState(out AudioSessionState state); 32 | [PreserveSig] 33 | int GetDisplayName([Out, MarshalAs(UnmanagedType.LPWStr)] out string name); 34 | [PreserveSig] 35 | int SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string value, ref Guid EventContext); 36 | [PreserveSig] 37 | int GetIconPath([Out, MarshalAs(UnmanagedType.LPWStr)] out string Path); 38 | [PreserveSig] 39 | int SetIconPath([MarshalAs(UnmanagedType.LPWStr)] string Value, ref Guid EventContext); 40 | [PreserveSig] 41 | int GetGroupingParam(out Guid GroupingParam); 42 | [PreserveSig] 43 | int SetGroupingParam(ref Guid Override, ref Guid Eventcontext); 44 | [PreserveSig] 45 | int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 46 | [PreserveSig] 47 | int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 48 | [PreserveSig] 49 | int GetSessionIdentifier([Out, MarshalAs(UnmanagedType.LPWStr)] out string retVal); 50 | [PreserveSig] 51 | int GetSessionInstanceIdentifier([Out, MarshalAs(UnmanagedType.LPWStr)] out string retVal); 52 | [PreserveSig] 53 | int GetProcessId(out uint retvVal); 54 | [PreserveSig] 55 | int IsSystemSoundsSession(); 56 | [PreserveSig] 57 | int SetDuckingPreference(bool optOut); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | internal interface IAudioSessionEnumerator { 29 | int GetCount(out int SessionCount); 30 | int GetSession(int SessionCount, out IAudioSessionControl2 Session); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | public interface IAudioSessionEvents { 30 | [PreserveSig] 31 | int OnDisplayNameChanged([MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, ref Guid EventContext); 32 | [PreserveSig] 33 | int OnIconPathChanged([MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, ref Guid EventContext); 34 | [PreserveSig] 35 | int OnSimpleVolumeChanged(float NewVolume, bool newMute, ref Guid EventContext); 36 | [PreserveSig] 37 | int OnChannelVolumeChanged(uint ChannelCount, IntPtr NewChannelVolumeArray, uint ChangedChannel, ref Guid EventContext); 38 | [PreserveSig] 39 | int OnGroupingParamChanged(ref Guid NewGroupingParam, ref Guid EventContext); 40 | [PreserveSig] 41 | int OnStateChanged(AudioSessionState NewState); 42 | [PreserveSig] 43 | int OnSessionDisconnected(AudioSessionDisconnectReason DisconnectReason); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/IAudioSessionManager.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.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("BFA971F1-4D5E-40BB-935E-967039BFBEE4"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioSessionManager { 30 | [PreserveSig] 31 | int GetAudioSessionControl(ref Guid AudioSessionGuid, uint StreamFlags, out IAudioSessionControl ISessionControl); 32 | [PreserveSig] 33 | int GetSimpleAudioVolume(ref Guid AudioSessionGuid, uint StreamFlags, out ISimpleAudioVolume SimpleAudioVolume); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioSessionManager2 { 30 | [PreserveSig] 31 | int GetAudioSessionControl(ref Guid AudioSessionGuid, uint StreamFlags, out IAudioSessionControl2 ISessionControl); 32 | [PreserveSig] 33 | int GetSimpleAudioVolume(ref Guid AudioSessionGuid, uint StreamFlags, out ISimpleAudioVolume SimpleAudioVolume); 34 | [PreserveSig] 35 | int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum); 36 | [PreserveSig] 37 | int RegisterSessionNotification(IAudioSessionNotification SessionNotification); 38 | [PreserveSig] 39 | int UnregisterSessionNotification(IAudioSessionNotification SessionNotification); 40 | [PreserveSig] 41 | int RegisterDuckNotification(string sessionID, IAudioSessionNotification IAudioVolumeDuckNotification); 42 | [PreserveSig] 43 | int UnregisterDuckNotification(IntPtr IAudioVolumeDuckNotification); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/IAudioSessionNotification.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 | 25 | namespace CoreAudio.Interfaces { 26 | [Guid("641DD20B-4D41-49CC-ABA3-174B9477BB08"), 27 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 28 | public interface IAudioSessionNotification { 29 | [PreserveSig] 30 | int OnSessionCreated(IAudioSessionControl2 NewSession); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/WASAPI/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 | 23 | using System; 24 | using System.Runtime.InteropServices; 25 | 26 | namespace CoreAudio.Interfaces { 27 | [Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface ISimpleAudioVolume { 30 | [PreserveSig] 31 | int SetMasterVolume(float fLevel, ref Guid EventContext); 32 | [PreserveSig] 33 | int GetMasterVolume(out float pfLevel); 34 | [PreserveSig] 35 | int SetMute(bool bMute, ref Guid EventContext); 36 | [PreserveSig] 37 | int GetMute(out bool bMute); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/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 | 23 | namespace CoreAudio.Interfaces { 24 | internal enum EStgmAccess { 25 | STGM_READ = 0x00000000, 26 | STGM_WRITE = 0x00000001, 27 | STGM_READWRITE = 0x00000002 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CoreAudio/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 | /* Updated by John de Jong (2020/04/02) */ 23 | 24 | using System; 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | using System.Runtime.InteropServices; 28 | using CoreAudio.Interfaces; 29 | 30 | namespace CoreAudio { 31 | public class MMDeviceCollection : IEnumerable { 32 | readonly IMMDeviceCollection mMDeviceCollection; 33 | internal Guid eventContext; 34 | 35 | public int Count { 36 | get { 37 | Marshal.ThrowExceptionForHR(mMDeviceCollection.GetCount(out var result)); 38 | return (int)result; 39 | } 40 | } 41 | 42 | public MMDevice this[int index] { 43 | get { 44 | mMDeviceCollection.Item((uint)index, out IMMDevice result); 45 | return new MMDevice(result, ref eventContext); 46 | } 47 | } 48 | 49 | internal MMDeviceCollection(IMMDeviceCollection parent, ref Guid eventContext) { 50 | mMDeviceCollection = parent; 51 | this.eventContext = eventContext; 52 | } 53 | 54 | public IEnumerator GetEnumerator() { 55 | for(var index = 0; index < Count; index++) { 56 | yield return this[index]; 57 | } 58 | } 59 | 60 | IEnumerator IEnumerable.GetEnumerator() { 61 | return GetEnumerator(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /CoreAudio/MMNotificationClient.cs: -------------------------------------------------------------------------------- 1 | using CoreAudio.Interfaces; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | /* 6 | Created by Xavier Flix (2022/10/22) 7 | 8 | Portions of the code inspired by or blatanly copied from filoe/cscore 9 | */ 10 | 11 | namespace CoreAudio { 12 | [Guid("7991EEC9-7E89-4D85-8390-6C703CEC60C0")] 13 | public class MMNotificationClient : IMMNotificationClient { 14 | private readonly MMDeviceEnumerator deviceEnumerator; 15 | 16 | public event EventHandler? DeviceStateChanged; 17 | public event EventHandler? DeviceAdded; 18 | public event EventHandler? DeviceRemoved; 19 | public event EventHandler? DefaultDeviceChanged; 20 | public event EventHandler? DevicePropertyChanged; 21 | 22 | public MMNotificationClient(MMDeviceEnumerator enumerator) { 23 | deviceEnumerator = enumerator; 24 | Marshal.ThrowExceptionForHR(deviceEnumerator.RegisterEndpointNotificationCallback(this)); 25 | } 26 | 27 | public void OnDefaultDeviceChanged(DataFlow flow, Role role, string deviceId) { 28 | DefaultDeviceChanged?.Invoke(this, new DefaultDeviceChangedEventArgs(deviceId, flow, role)); 29 | } 30 | 31 | public void OnDeviceAdded(string deviceId) { 32 | DeviceAdded?.Invoke(this, new DeviceNotificationEventArgs(deviceId)); 33 | } 34 | 35 | public void OnDeviceRemoved(string deviceId) { 36 | DeviceRemoved?.Invoke(this, new DeviceNotificationEventArgs(deviceId)); 37 | } 38 | 39 | public void OnDeviceStateChanged(string deviceId, DeviceState newState) { 40 | DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs(deviceId, newState)); 41 | } 42 | 43 | public void OnPropertyValueChanged(string deviceId, PropertyKey key) { 44 | DevicePropertyChanged?.Invoke(this, new DevicePropertyChangedEventArgs(deviceId, key)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CoreAudio/PartsList.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.Collections.Generic; 24 | using System.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class PartsList { 29 | IPartsList partsList; 30 | Dictionary partsCache; 31 | 32 | internal PartsList(IPartsList partsList) { 33 | this.partsList = partsList; 34 | partsCache = new Dictionary(); 35 | } 36 | 37 | public int Count { 38 | get { 39 | Marshal.ThrowExceptionForHR(partsList.GetCount(out var count)); 40 | return count; 41 | } 42 | } 43 | 44 | public Part Part(int index) { 45 | if(partsCache.ContainsKey(index)) { 46 | return partsCache[index]; 47 | } 48 | 49 | Marshal.ThrowExceptionForHR(partsList.GetPart(index, out IPart ipart)); 50 | Part part = new Part(ipart); 51 | partsCache.Add(index, part); 52 | return part; 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /CoreAudio/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 | 23 | using System.Runtime.InteropServices; 24 | using CoreAudio.Interfaces; 25 | 26 | namespace CoreAudio { 27 | /// 28 | /// Property Store class, only supports reading properties at the moment. 29 | /// 30 | public class PropertyStore { 31 | IPropertyStore store; 32 | 33 | public int Count { 34 | get { 35 | Marshal.ThrowExceptionForHR(store.GetCount(out var result)); 36 | return result; 37 | } 38 | } 39 | 40 | public PropertyStoreProperty this[int index] { 41 | get { 42 | var key = Get(index); 43 | Marshal.ThrowExceptionForHR(store.GetValue(ref key, out var result)); 44 | return new PropertyStoreProperty(key, result); 45 | } 46 | } 47 | 48 | public bool Contains(PropertyKey testKey) { 49 | for(var i = 0; i < Count; i++) { 50 | var key = Get(i); 51 | if(key.fmtId == testKey.fmtId && key.PId == testKey.PId) 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | public PropertyStoreProperty? this[PropertyKey testKey] { 58 | get { 59 | for(var i = 0; i < Count; i++) { 60 | var key = Get(i); 61 | if(key.fmtId == testKey.fmtId && key.PId == testKey.PId) { 62 | Marshal.ThrowExceptionForHR(store.GetValue(ref key, out var result)); 63 | return new PropertyStoreProperty(key, result); 64 | } 65 | } 66 | return null; 67 | } 68 | } 69 | 70 | public PropertyKey Get(int index) { 71 | Marshal.ThrowExceptionForHR(store.GetAt(index, out var key)); 72 | return key; 73 | } 74 | 75 | public PropVariant GetValue(int index) { 76 | var key = Get(index); 77 | Marshal.ThrowExceptionForHR(store.GetValue(ref key, out var result)); 78 | return result; 79 | } 80 | 81 | internal PropertyStore(IPropertyStore store) { 82 | this.store = store; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /CoreAudio/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 | 24 | namespace CoreAudio { 25 | public class PropertyStoreProperty { 26 | PropertyKey propertyKey; 27 | PropVariant propValue; 28 | 29 | internal PropertyStoreProperty(PropertyKey key, PropVariant value) { 30 | propertyKey = key; 31 | propValue = value; 32 | } 33 | 34 | public PropertyKey Key => propertyKey; 35 | 36 | public object Value => propValue.Value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreAudio/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 | /* Updated by John de Jong (2020/04/02) */ 23 | 24 | using System; 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | using System.Runtime.InteropServices; 28 | using CoreAudio.Interfaces; 29 | 30 | namespace CoreAudio { 31 | public class SessionCollection : IEnumerable { 32 | readonly IAudioSessionEnumerator audioSessionEnumerator; 33 | internal Guid eventContext; 34 | internal SessionCollection(IAudioSessionEnumerator realEnumerator, ref Guid eventContext) { 35 | audioSessionEnumerator = realEnumerator; 36 | this.eventContext = eventContext; 37 | } 38 | 39 | public AudioSessionControl2 this[int index] { 40 | get { 41 | Marshal.ThrowExceptionForHR(audioSessionEnumerator.GetSession(index, out IAudioSessionControl2 _Result)); 42 | return new AudioSessionControl2(_Result, ref eventContext); 43 | } 44 | } 45 | 46 | public int Count { 47 | get { 48 | Marshal.ThrowExceptionForHR(audioSessionEnumerator.GetCount(out var result)); 49 | return result; 50 | } 51 | } 52 | 53 | public IEnumerator GetEnumerator() { 54 | for(var index = 0; index < Count; index++) { 55 | yield return this[index]; 56 | } 57 | } 58 | 59 | IEnumerator IEnumerable.GetEnumerator() { 60 | return GetEnumerator(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /CoreAudio/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.Runtime.InteropServices; 25 | using CoreAudio.Interfaces; 26 | 27 | namespace CoreAudio { 28 | public class SimpleAudioVolume { 29 | ISimpleAudioVolume simpleAudioVolume; 30 | private Guid eventContext; 31 | internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume, ref Guid eventContext) { 32 | simpleAudioVolume = realSimpleVolume; 33 | this.eventContext = eventContext; 34 | } 35 | 36 | public float MasterVolume { 37 | get { 38 | Marshal.ThrowExceptionForHR(simpleAudioVolume.GetMasterVolume(out var ret)); 39 | return ret; 40 | } 41 | set { 42 | Marshal.ThrowExceptionForHR(simpleAudioVolume.SetMasterVolume(value, ref eventContext)); 43 | } 44 | } 45 | 46 | public bool Mute { 47 | get { 48 | Marshal.ThrowExceptionForHR(simpleAudioVolume.GetMute(out var ret)); 49 | return ret; 50 | } 51 | set { 52 | Marshal.ThrowExceptionForHR(simpleAudioVolume.SetMute(value, ref eventContext)); 53 | } 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CoreAudio/Structures/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 | 23 | using System; 24 | 25 | namespace CoreAudio.Interfaces { 26 | internal struct AudioVolumeNotificationData { 27 | #pragma warning disable CS0649 28 | public Guid GuidEventContext; 29 | public bool Muted; 30 | public float MasterVolume; 31 | public uint Channels; 32 | public float ChannelVolume; 33 | #pragma warning restore CS0649 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreAudio/Structures/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 | 23 | using System; 24 | 25 | namespace CoreAudio { 26 | public struct PropertyKey { 27 | public Guid fmtId; 28 | public int PId; 29 | 30 | public PropertyKey(Guid fmtId, int pId) { 31 | this.fmtId = fmtId; 32 | this.PId = pId; 33 | } 34 | 35 | public static bool operator ==(PropertyKey pk1, PropertyKey pk2) { 36 | return (pk1.fmtId == pk2.fmtId) && (pk1.PId == pk2.PId); 37 | } 38 | 39 | public static bool operator !=(PropertyKey pk1, PropertyKey pk2) { 40 | return !(pk1 == pk2); 41 | } 42 | 43 | public override bool Equals(object obj) { 44 | return base.Equals(obj); 45 | } 46 | 47 | public override int GetHashCode() { 48 | return base.GetHashCode(); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /CoreAudio/Structures/WAVEFORMATEX.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 | 25 | namespace CoreAudio.Interfaces { 26 | [StructLayout(LayoutKind.Sequential)] 27 | internal struct WaveFormatEx { 28 | ushort FormatTag; // format type 29 | ushort Channels; // number of channels (i.e. mono, stereo...) 30 | uint SamplesPerSec; // sample rate 31 | uint AvgBytesPerSec; // for buffer estimation 32 | ushort BlockAlign; // block size of data 33 | ushort BitsPerSample; // number of bits per sample of mono data 34 | ushort Size; // the count in bytes of 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CoreAudio/Subunit.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 CoreAudio.Interfaces; 24 | 25 | namespace CoreAudio { 26 | public class Subunit { 27 | ISubunit _Subunit; 28 | 29 | internal Subunit(ISubunit subunit) { 30 | _Subunit = subunit; 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CoreAudio/Undocumented/AudioPolicyConfigFactory.cs: -------------------------------------------------------------------------------- 1 | using CoreAudio.Interfaces.Undocumented; 2 | using System; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace CoreAudio.Undocumented { 7 | public class AudioPolicyConfigFactory { 8 | public static IAudioPolicyConfigFactory Create() { 9 | int osBuildNumber = int.Parse(RuntimeInformation.OSDescription.Split('.').Last()); 10 | 11 | if(osBuildNumber >= 21390) { // Windows 10 21H2 12 | return new AudioPolicyConfigFactoryVariantFor21H2(); 13 | } else { 14 | return new AudioPolicyConfigFactoryVariantForDownlevel(); 15 | } 16 | } 17 | } 18 | 19 | internal static class Combase { 20 | [DllImport("combase.dll", PreserveSig = false)] 21 | public static extern void RoGetActivationFactory( 22 | [MarshalAs(UnmanagedType.HString)] string activatableClassId, 23 | [In] ref Guid iid, 24 | [Out, MarshalAs(UnmanagedType.IInspectable)] out Object factory); 25 | 26 | [DllImport("combase.dll", PreserveSig = false)] 27 | public static extern void WindowsCreateString( 28 | [MarshalAs(UnmanagedType.LPWStr)] string src, 29 | [In] uint length, 30 | [Out] out IntPtr hstring); 31 | } 32 | } -------------------------------------------------------------------------------- /CoreAudio/Undocumented/AudioPolicyConfigFactoryVariantFor21H2.cs: -------------------------------------------------------------------------------- 1 | using CoreAudio.Interfaces.Undocumented; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace CoreAudio.Undocumented { 6 | class AudioPolicyConfigFactoryVariantFor21H2 : IAudioPolicyConfigFactory { 7 | private readonly IAudioPolicyConfigFactoryVariantFor21H2 _factory; 8 | 9 | internal AudioPolicyConfigFactoryVariantFor21H2() { 10 | var iid = typeof(IAudioPolicyConfigFactoryVariantFor21H2).GUID; 11 | Combase.RoGetActivationFactory("Windows.Media.Internal.AudioPolicyConfig", ref iid, out object factory); 12 | _factory = (IAudioPolicyConfigFactoryVariantFor21H2)factory; 13 | } 14 | 15 | public int ClearAllPersistedApplicationDefaultEndpoints() { 16 | return _factory.ClearAllPersistedApplicationDefaultEndpoints(); 17 | } 18 | 19 | public int GetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, out string deviceId) { 20 | return _factory.GetPersistedDefaultAudioEndpoint(processId, flow, role, out deviceId); 21 | } 22 | 23 | public int SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, IntPtr deviceId) { 24 | return _factory.SetPersistedDefaultAudioEndpoint(processId, flow, role, deviceId); 25 | } 26 | 27 | public MMDevice? GetPersistedDefaultAudioEndpoint(MMDeviceEnumerator deviceEnumerator, int processId, DataFlow flow, Role role, DeviceState state = DeviceState.MaskAll) { 28 | MMDevice? device = null; 29 | 30 | int r = GetPersistedDefaultAudioEndpoint(processId, flow, role, out string deviceId); 31 | if(r == 0 && deviceId != "") { 32 | foreach(MMDevice dev in deviceEnumerator.EnumerateAudioEndPoints(flow, state)) { 33 | if(deviceId.Contains(dev.ID)) { 34 | device = dev; 35 | break; 36 | } 37 | } 38 | } 39 | device ??= deviceEnumerator.GetDefaultAudioEndpoint(flow, role); 40 | 41 | return device; 42 | } 43 | 44 | public void SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, MMDevice device) { 45 | if(!string.IsNullOrWhiteSpace(device.ID)) { 46 | string id = $@"\\?\SWD#MMDEVAPI#{device.ID}#{{e6327cad-dcec-4949-ae8a-991e976a79d2}}"; 47 | Combase.WindowsCreateString(id, (uint)id.Length, out IntPtr hstring); 48 | 49 | SetPersistedDefaultAudioEndpoint(processId, flow, role, hstring); 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /CoreAudio/Undocumented/AudioPolicyConfigFactoryVariantForDownlevel.cs: -------------------------------------------------------------------------------- 1 | using CoreAudio.Interfaces.Undocumented; 2 | using System; 3 | 4 | namespace CoreAudio.Undocumented { 5 | class AudioPolicyConfigFactoryVariantForDownlevel : IAudioPolicyConfigFactory { 6 | private readonly IAudioPolicyConfigFactoryVariantForDownlevel _factory; 7 | 8 | internal AudioPolicyConfigFactoryVariantForDownlevel() { 9 | var iid = typeof(IAudioPolicyConfigFactoryVariantForDownlevel).GUID; 10 | Combase.RoGetActivationFactory("Windows.Media.Internal.AudioPolicyConfig", ref iid, out object factory); 11 | _factory = (IAudioPolicyConfigFactoryVariantForDownlevel)factory; 12 | } 13 | 14 | public int ClearAllPersistedApplicationDefaultEndpoints() { 15 | return _factory.ClearAllPersistedApplicationDefaultEndpoints(); 16 | } 17 | 18 | public int GetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, out string deviceId) { 19 | return _factory.GetPersistedDefaultAudioEndpoint(processId, flow, role, out deviceId); 20 | } 21 | 22 | public int SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, IntPtr deviceId) { 23 | return _factory.SetPersistedDefaultAudioEndpoint(processId, flow, role, deviceId); 24 | } 25 | 26 | public MMDevice? GetPersistedDefaultAudioEndpoint(MMDeviceEnumerator deviceEnumerator, int processId, DataFlow flow, Role role, DeviceState state = DeviceState.MaskAll) { 27 | MMDevice? device = null; 28 | 29 | int r = GetPersistedDefaultAudioEndpoint(processId, flow, role, out string deviceId); 30 | if(r == 0 && deviceId != "") { 31 | foreach(MMDevice dev in deviceEnumerator.EnumerateAudioEndPoints(flow, state)) { 32 | if(deviceId.Contains(dev.ID)) { 33 | device = dev; 34 | break; 35 | } 36 | } 37 | } 38 | device ??= deviceEnumerator.GetDefaultAudioEndpoint(flow, role); 39 | 40 | return device; 41 | } 42 | 43 | public void SetPersistedDefaultAudioEndpoint(int processId, DataFlow flow, Role role, MMDevice device) { 44 | if(!string.IsNullOrWhiteSpace(device.ID)) { 45 | string id = $@"\\?\SWD#MMDEVAPI#{device.ID}#{{e6327cad-dcec-4949-ae8a-991e976a79d2}}"; 46 | Combase.WindowsCreateString(id, (uint)id.Length, out IntPtr hstring); 47 | 48 | SetPersistedDefaultAudioEndpoint(processId, flow, role, hstring); 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /CoreAudio/coreaudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/morphx666/CoreAudio/024019df5f9e8b4eae4e129b67cf0a4f70675fab/CoreAudio/coreaudio.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Xavier Flix 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoreAudio 2 | Windows CoreAudio wrapper for .NET 3 | 4 | ## Installation 5 | 6 | Thanks to [@uxsoft](https://github.com/uxsoft) there's now a NuGet Package available: 7 | https://www.nuget.org/packages/CoreAudio/ 8 | 9 | ## Documentation 10 | 11 | Since this project is just a wrapper for the native Win32 API you should be able to follow Microsoft's official C++ documentation: 12 | https://docs.microsoft.com/en-us/windows/win32/coreaudio/core-audio-apis-in-windows-vista 13 | 14 | You may also refer to the [included samples](https://github.com/morphx666/CoreAudio/tree/master/samples), kindly provided by contributors to this project. 15 | 16 | --- 17 | 18 | Sample application demonstrating how to handle sessions 19 | ![image](https://raw.githubusercontent.com/morphx666/CoreAudio/master/Assets/coreaudio-sample-sessions.png) 20 | 21 | ![Alt](https://repobeats.axiom.co/api/embed/6f15cce788304cd23220af997f3a0d49c98ba11e.svg "Repobeats analytics image") 22 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Core.Sample/CoreAudioConsole.Core.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 2024.3.18.139 7 | 2024.3.18.139 8 | 9 | 10 | 11 | ..\..\Release\samples\NetCore\Sessions 12 | 13 | 14 | 15 | ..\..\Release\samples\NetCore\Sessions 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace CoreAudioForms.Framework.Discover.Tester { 5 | internal static class Program { 6 | /// 7 | /// The main entry point for the application. 8 | /// 9 | [STAThread] 10 | static void Main() { 11 | Application.EnableVisualStyles(); 12 | Application.SetCompatibleTextRenderingDefault(false); 13 | Application.Run(new FomMain()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Tester")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("xFX JumpStart")] 11 | [assembly: AssemblyProduct("Tester")] 12 | [assembly: AssemblyCopyright("Copyright © xFX JumpStart 2022")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("f95c6bb8-63fe-42a5-9ca8-2d5a6dbf002c")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2024.3.18.347")] 35 | [assembly: AssemblyFileVersion("2024.3.18.347")] 36 | 37 | [assembly: AssemblyInformationalVersion("2024.3.18")] -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/Properties/Resources.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 CoreAudioForms.Framework.Discover.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoreAudioForms.Framework.Discover.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/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 CoreAudioForms.Framework.Discover.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Discover/Win32API.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Runtime.InteropServices; 4 | using System.Windows.Forms; 5 | 6 | namespace CoreAudioForms.Framework.Discover { 7 | internal static class Win32API { 8 | [DllImport("user32.dll")] private static extern int SendMessage(IntPtr hwndLock, Int32 wMsg, Int32 wParam, ref Point pt); 9 | [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); 10 | 11 | private const int WM_USER = 0x400; 12 | private const int EM_GETSCROLLPOS = WM_USER + 0xDD; 13 | private const int EM_SETSCROLLPOS = WM_USER + 0xDE; 14 | private const int WM_SETREDRAW = 0x0b; 15 | 16 | public static Point GetScrollPos(this RichTextBox txtbox) { 17 | Point pt = new Point(); 18 | SendMessage(txtbox.Handle, EM_GETSCROLLPOS, 0, ref pt); 19 | return pt; 20 | } 21 | 22 | public static void SetScrollPos(this RichTextBox txtbox, Point pt) { 23 | SendMessage(txtbox.Handle, EM_SETSCROLLPOS, 0, ref pt); 24 | } 25 | 26 | public static void SuspendDrawing(this RichTextBox richTextBox) { 27 | SendMessage(richTextBox.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero); 28 | } 29 | 30 | public static void ResumeDrawing(this RichTextBox richTextBox) { 31 | SendMessage(richTextBox.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero); 32 | richTextBox.Invalidate(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Sample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Sample/CoreAudioConsole.Framework.Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D269CDEE-2D69-471E-8436-48DC89BCF7CF} 8 | Exe 9 | CoreAudioConsole.Framework.Sample 10 | CoreAudioConsole.Framework.Sample 11 | v4.8.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | ..\..\Release\samples\Framework\Sessions\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | ..\..\Release\samples\Framework\Sessions\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | {8a45ad26-c5ce-4288-bb9e-6d6807966760} 55 | CoreAudio 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /samples/CoreAudioConsole.Framework.Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("CoreAudioConsole.Framework.Sample")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("CoreAudioConsole.Framework.Sample")] 12 | [assembly: AssemblyCopyright("Copyright © 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("d269cdee-2d69-471e-8436-48dc89bcf7cf")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2024.3.18.125")] 35 | [assembly: AssemblyFileVersion("2024.3.18.125")] 36 | 37 | [assembly: AssemblyInformationalVersion("2024.3.18")] -------------------------------------------------------------------------------- /samples/CoreAudioForms.Core.Sample/CoreAudioForms.Core.Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | netcoreapp3.1 6 | true 7 | 2024.4.1.235 8 | 2024.4.1.235 9 | 10 | 11 | 12 | ..\..\Release\samples\NetCore\MainVolume 13 | 14 | 15 | 16 | ..\..\Release\samples\NetCore\MainVolume 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Form 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Core.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace CoreAudioForms.Core.Sample { 5 | static class Program { 6 | /// 7 | /// The main entry point for the application. 8 | /// 9 | [STAThread] 10 | static void Main() { 11 | Application.SetHighDpiMode(HighDpiMode.SystemAware); 12 | Application.EnableVisualStyles(); 13 | Application.SetCompatibleTextRenderingDefault(false); 14 | Application.Run(new FormMain()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/FormMain.cs: -------------------------------------------------------------------------------- 1 | using CoreAudio; 2 | using System; 3 | using System.Windows.Forms; 4 | 5 | namespace CoreAudioForms.Framework.Sample { 6 | public partial class FormMain : Form { 7 | private readonly MMDevice device; 8 | 9 | public FormMain() { 10 | InitializeComponent(); 11 | 12 | var devEnum = new MMDeviceEnumerator(Guid.NewGuid()); 13 | device = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); 14 | 15 | TrackBarMaster.Value = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); 16 | CheckBoxMute.Checked = device.AudioEndpointVolume.Mute; 17 | 18 | device.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); 19 | } 20 | 21 | private void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data) { 22 | if(InvokeRequired) { 23 | object[] args = new object[1]; 24 | args[0] = data; 25 | Invoke(new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification), args); 26 | } else { 27 | TrackBarMaster.Value = (int)(data.MasterVolume * 100); 28 | CheckBoxMute.Checked = data.Muted; 29 | } 30 | } 31 | 32 | private void UpdateTimer_Tick(object sender, EventArgs e) { 33 | ProgressBarMaster.Value = (int)(device.AudioMeterInformation.MasterPeakValue * 100.0f); 34 | ProgressBarLeft.Value = (int)(device.AudioMeterInformation.PeakValues[0] * 100.0f); 35 | ProgressBarRight.Value = (int)(device.AudioMeterInformation.PeakValues[1] * 100.0f); 36 | } 37 | 38 | private void CheckBoxMute_CheckedChanged(object sender, EventArgs e) { 39 | device.AudioEndpointVolume.Mute = CheckBoxMute.Checked; 40 | } 41 | 42 | private void TrackBarMaster_Scroll(object sender, EventArgs e) { 43 | device.AudioEndpointVolume.MasterVolumeLevelScalar = (TrackBarMaster.Value / 100.0f); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace CoreAudioForms.Framework.Sample { 5 | static class Program { 6 | /// 7 | /// The main entry point for the application. 8 | /// 9 | [STAThread] 10 | static void Main() { 11 | Application.EnableVisualStyles(); 12 | Application.SetCompatibleTextRenderingDefault(false); 13 | Application.Run(new FormMain()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("CoreAudioForms.Framework.Sample")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("CoreAudioForms.Framework.Sample")] 12 | [assembly: AssemblyCopyright("Copyright © 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("3c36b004-a097-4640-bfca-ea810434fef5")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2024.3.18.167")] 35 | [assembly: AssemblyFileVersion("2024.3.18.167")] 36 | 37 | [assembly: AssemblyInformationalVersion("2024.3.18")] -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/Properties/Resources.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 CoreAudioForms.Framework.Sample.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 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 | /// Returns the cached ResourceManager instance used by this class. 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("CoreAudioForms.Framework.Sample.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 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 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/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 CoreAudioForms.Framework.Sample.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 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sample/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Drawing; 4 | using System.IO; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace CoreAudioForms.Framework.Sessions { 8 | public static class NativeMethods { 9 | private const uint SHGFI_ICON = 0x100; 10 | private const uint SHGFI_SMALLICON = 1; 11 | private const uint SHGFI_LARGEICON = 0; 12 | 13 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] 14 | private struct SHFILEINFO { 15 | public IntPtr hIcon; 16 | public int iIcon; 17 | public uint dwAttributes; 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szDisplayName; 19 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public string szTypeName; 20 | } 21 | 22 | [DllImport("shell32.dll", CharSet = CharSet.Auto)] 23 | private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags); 24 | 25 | public static Icon GetIconFromFile(string fileName, int index = 0, bool smallIcon = false) { 26 | if(fileName.Contains(",") && int.TryParse(fileName.Split(',')[1], out index)) fileName = fileName.Split(',')[0]; 27 | fileName = Environment.ExpandEnvironmentVariables(fileName); 28 | if(fileName.Contains("@")) fileName = fileName.Replace("@", ""); 29 | 30 | if(File.Exists(fileName)) { 31 | SHFILEINFO shInfo = new SHFILEINFO { 32 | szDisplayName = new string('\0', 260), 33 | szTypeName = new string('\0', 80), 34 | iIcon = index 35 | }; 36 | 37 | var r = SHGetFileInfo(fileName, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), SHGFI_ICON | (smallIcon ? SHGFI_SMALLICON : SHGFI_LARGEICON)); 38 | 39 | return shInfo.hIcon.ToInt32() == 0 ? null : Icon.FromHandle(shInfo.hIcon); 40 | } 41 | 42 | return null; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace CoreAudioForms.Framework.Sessions { 5 | static class Program { 6 | /// 7 | /// The main entry point for the application. 8 | /// 9 | [STAThread] 10 | static void Main() { 11 | Application.EnableVisualStyles(); 12 | Application.SetCompatibleTextRenderingDefault(false); 13 | Application.Run(new FormMain()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("CoreAudioForms.Framework.Sessions")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("CoreAudioForms.Framework.Sessions")] 12 | [assembly: AssemblyCopyright("Copyright © 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("826914c2-0bd8-4c8e-807f-95f5853a94d3")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2024.3.18.666")] 35 | [assembly: AssemblyFileVersion("2024.3.18.666")] 36 | 37 | [assembly: AssemblyInformationalVersion("2024.3.18")] -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/Properties/Resources.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 CoreAudioForms.Framework.Sessions.Properties { 12 | 13 | 14 | /// 15 | /// A strongly-typed resource class, for looking up localized strings, etc. 16 | /// 17 | // This class was auto-generated by the StronglyTypedResourceBuilder 18 | // class via a tool like ResGen or Visual Studio. 19 | // To add or remove a member, edit your .ResX file then rerun ResGen 20 | // with the /str option, or rebuild your VS project. 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources { 25 | 26 | private static global::System.Resources.ResourceManager resourceMan; 27 | 28 | private static global::System.Globalization.CultureInfo resourceCulture; 29 | 30 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 31 | internal Resources() { 32 | } 33 | 34 | /// 35 | /// Returns the cached ResourceManager instance used by this class. 36 | /// 37 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 38 | internal static global::System.Resources.ResourceManager ResourceManager { 39 | get { 40 | if((resourceMan == null)) { 41 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoreAudioForms.Framework.Sessions.Properties.Resources", typeof(Resources).Assembly); 42 | resourceMan = temp; 43 | } 44 | return resourceMan; 45 | } 46 | } 47 | 48 | /// 49 | /// Overrides the current thread's CurrentUICulture property for all 50 | /// resource lookups using this strongly typed resource class. 51 | /// 52 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 53 | internal static global::System.Globalization.CultureInfo Culture { 54 | get { 55 | return resourceCulture; 56 | } 57 | set { 58 | resourceCulture = value; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/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 CoreAudioForms.Framework.Sessions.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/UI/MACTrackBarLib/MACTrackBar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/morphx666/CoreAudio/024019df5f9e8b4eae4e129b67cf0a4f70675fab/samples/CoreAudioForms.Framework.Sessions/UI/MACTrackBarLib/MACTrackBar.bmp -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/UI/MACTrackBarLib/MACTrackBar.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | text/microsoft-resx 32 | 33 | 34 | 1.0.0.0 35 | 36 | 37 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 38 | 39 | 40 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 41 | 42 | 43 | -------------------------------------------------------------------------------- /samples/CoreAudioForms.Framework.Sessions/UI/VU.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CoreAudioForms.Framework.Sessions { 2 | partial class VU { 3 | /// 4 | /// Required designer variable. 5 | /// 6 | private System.ComponentModel.IContainer components = null; 7 | 8 | /// 9 | /// Clean up any resources being used. 10 | /// 11 | /// true if managed resources should be disposed; otherwise, false. 12 | protected override void Dispose(bool disposing) { 13 | if(disposing && (components != null)) { 14 | components.Dispose(); 15 | } 16 | base.Dispose(disposing); 17 | } 18 | 19 | #region Component Designer generated code 20 | 21 | /// 22 | /// Required method for Designer support - do not modify 23 | /// the contents of this method with the code editor. 24 | /// 25 | private void InitializeComponent() { 26 | this.SuspendLayout(); 27 | // 28 | // VU 29 | // 30 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 31 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 32 | this.ForeColor = System.Drawing.SystemColors.Highlight; 33 | this.Name = "VU"; 34 | this.Size = new System.Drawing.Size(120, 20); 35 | this.ResumeLayout(false); 36 | 37 | } 38 | 39 | #endregion 40 | } 41 | } 42 | --------------------------------------------------------------------------------