├── .gitignore ├── 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 │ ├── AUDCLNT_RETURNFLAGS.cs │ ├── AUDCLNT_SESSIONFLAGS.cs │ ├── AUDCLNT_STREAMFLAGS.cs │ ├── DEVICE_STATE.cs │ ├── ENDPOINT_HARDWARE_SUPPORT.cs │ └── _AUDCLNT_BUFFERFLAGS.cs ├── ControlChangeNotify.cs ├── ControlInterface.cs ├── CoreAudio.csproj ├── CoreAudio.sln ├── DeviceTopology.cs ├── Enumerations │ ├── AUDCLNT_SHAREMODE.cs │ ├── AudioSessionDisconnectReason.cs │ ├── AudioSessionState.cs │ ├── ConnectorType.cs │ ├── EDataFlow.cs │ ├── EEndpointHardwareSupport.cs │ ├── ERole.cs │ ├── KSNODETYPE.cs │ ├── PartType.cs │ └── REFIID.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 │ ├── 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 ├── PKEY.cs ├── Part.cs ├── PartsList.cs ├── PerChannelDbLevel.cs ├── PropVariant.cs ├── Properties │ └── AssemblyInfo.cs ├── PropertyStore.cs ├── PropertyStoreProperty.cs ├── SessionCollection.cs ├── SimpleAudioVolume.cs ├── Structures │ ├── AUDIO_VOLUME_NOTIFICATION_DATA.cs │ ├── PROPERTYKEY.cs │ └── WAVEFORMATEX.cs └── Subunit.cs ├── CoreAudioSample ├── CoreAudioConsoleTest │ ├── CoreAudioConsoleTest.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── app.config ├── CoreAudioSample.sln └── CoreAudioSample │ ├── Class1.cs │ ├── CoreAudioSample.csproj │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── Properties │ └── AssemblyInfo.cs │ └── app.config ├── LICENSE ├── README.md └── Tester ├── App.config ├── My Project ├── Application.Designer.vb ├── Application.myapp ├── AssemblyInfo.vb ├── Resources.Designer.vb ├── Resources.resx ├── Settings.Designer.vb └── Settings.settings ├── Tester.vbproj ├── frmMain.Designer.vb ├── frmMain.resx └── frmMain.vb /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | *.obj 3 | *.exe 4 | *.pdb 5 | *.user 6 | *.aps 7 | *.pch 8 | *.vspscc 9 | *_i.c 10 | *_p.c 11 | *.ncb 12 | *.suo 13 | *.tlb 14 | *.tlh 15 | *.bak 16 | *.cache 17 | *.ilk 18 | *.log 19 | [Bb]in 20 | [Dd]ebug*/ 21 | *.lib 22 | *.sbr 23 | obj/ 24 | [Rr]elease*/ 25 | _ReSharper*/ 26 | [Tt]est[Rr]esult* 27 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioEndPointVolumeVolumeRange 31 | { 32 | float _VolumeMindB; 33 | float _VolumeMaxdB; 34 | float _VolumeIncrementdB; 35 | 36 | internal AudioEndPointVolumeVolumeRange(IAudioEndpointVolume parent) 37 | { 38 | Marshal.ThrowExceptionForHR(parent.GetVolumeRange(out _VolumeMindB,out _VolumeMaxdB,out _VolumeIncrementdB)); 39 | } 40 | 41 | public float MindB 42 | { 43 | get 44 | { 45 | return _VolumeMindB; 46 | } 47 | } 48 | 49 | public float MaxdB 50 | { 51 | get 52 | { 53 | return _VolumeMaxdB; 54 | } 55 | } 56 | 57 | public float IncrementdB 58 | { 59 | get 60 | { 61 | return _VolumeIncrementdB; 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /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 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | // This class implements the IAudioEndpointVolumeCallback interface, 32 | // it is implemented in this class because implementing it on AudioEndpointVolume 33 | // (where the functionality is really wanted, would cause the OnNotify function 34 | // to show up in the public API. 35 | internal class AudioEndpointVolumeCallback : IAudioEndpointVolumeCallback 36 | { 37 | private AudioEndpointVolume _Parent; 38 | 39 | internal AudioEndpointVolumeCallback(AudioEndpointVolume parent) 40 | { 41 | _Parent = parent; 42 | } 43 | 44 | [PreserveSig] public int OnNotify(IntPtr NotifyData) 45 | { 46 | //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the 47 | //number of audio channels available we cannot just call PtrToStructure 48 | //to get all data, that's why it is split up into two steps, first the static 49 | //data is marshalled into the data structure, then with some IntPtr math the 50 | //remaining floats are read from memory. 51 | // 52 | AUDIO_VOLUME_NOTIFICATION_DATA data = (AUDIO_VOLUME_NOTIFICATION_DATA) Marshal.PtrToStructure(NotifyData, typeof(AUDIO_VOLUME_NOTIFICATION_DATA)); 53 | 54 | //Determine offset in structure of the first float 55 | IntPtr Offset = Marshal.OffsetOf(typeof(AUDIO_VOLUME_NOTIFICATION_DATA),"ChannelVolume"); 56 | //Determine offset in memory of the first float 57 | IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset); 58 | 59 | float[] voldata = new float[data.nChannels]; 60 | 61 | //Read all floats from memory. 62 | for (int i = 0; i < data.nChannels; i++) 63 | { 64 | voldata[i] = (float)Marshal.PtrToStructure(FirstFloatPtr, typeof(float)); 65 | } 66 | 67 | //Create combined structure and Fire Event in parent class. 68 | AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata); 69 | _Parent.FireNotification(NotificationData); 70 | return 0; //S_OK 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /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.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | public class AudioEndpointVolumeChannel 32 | { 33 | private uint _Channel; 34 | private IAudioEndpointVolume _AudioEndpointVolume; 35 | 36 | internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel) 37 | { 38 | _Channel = (uint)channel; 39 | _AudioEndpointVolume = parent; 40 | } 41 | 42 | public float VolumeLevel 43 | { 44 | get 45 | { 46 | float result; 47 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevel(_Channel,out result)); 48 | return result; 49 | } 50 | set 51 | { 52 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevel(_Channel, value,Guid.Empty)); 53 | } 54 | } 55 | 56 | public float VolumeLevelScalar 57 | { 58 | get 59 | { 60 | float result; 61 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevelScalar(_Channel, out result)); 62 | return result; 63 | } 64 | set 65 | { 66 | Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevelScalar(_Channel, value, Guid.Empty)); 67 | } 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /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.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | public class AudioEndpointVolumeChannels 32 | { 33 | IAudioEndpointVolume _AudioEndPointVolume; 34 | AudioEndpointVolumeChannel[] _Channels; 35 | public int Count 36 | { 37 | get 38 | { 39 | int result; 40 | Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetChannelCount(out result)); 41 | return result; 42 | } 43 | } 44 | 45 | public AudioEndpointVolumeChannel this[int index] 46 | { 47 | get 48 | { 49 | return _Channels[index]; 50 | } 51 | } 52 | 53 | internal AudioEndpointVolumeChannels(IAudioEndpointVolume parent) 54 | { 55 | int ChannelCount; 56 | _AudioEndPointVolume = parent; 57 | 58 | ChannelCount = Count; 59 | _Channels = new AudioEndpointVolumeChannel[ChannelCount]; 60 | for (int i = 0; i < ChannelCount; i++) 61 | { 62 | _Channels[i] = new AudioEndpointVolumeChannel(_AudioEndPointVolume, i); 63 | } 64 | } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /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 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace CoreAudio 28 | { 29 | public delegate void AudioEndpointVolumeNotificationDelegate(AudioVolumeNotificationData data); 30 | } 31 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioEndpointVolumeStepInformation 31 | { 32 | private uint _Step; 33 | private uint _StepCount; 34 | internal AudioEndpointVolumeStepInformation(IAudioEndpointVolume parent) 35 | { 36 | Marshal.ThrowExceptionForHR(parent.GetVolumeStepInfo(out _Step, out _StepCount)); 37 | } 38 | 39 | public uint Step 40 | { 41 | get 42 | { 43 | return _Step; 44 | } 45 | } 46 | 47 | public uint StepCount 48 | { 49 | get 50 | { 51 | return _StepCount; 52 | } 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioLoudness 31 | { 32 | private IAudioLoudness _AudioLoudness; 33 | 34 | internal AudioLoudness(IAudioLoudness audioLoudness) 35 | { 36 | _AudioLoudness = audioLoudness; 37 | } 38 | 39 | public bool Enabled 40 | { 41 | get 42 | { 43 | bool enabled; 44 | Marshal.ThrowExceptionForHR(_AudioLoudness.GetEnabled(out enabled)); 45 | return enabled; 46 | } 47 | set 48 | { 49 | Guid eventContext; 50 | Marshal.ThrowExceptionForHR(_AudioLoudness.SetEnabled(value, out eventContext)); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioMeterInformation 31 | { 32 | private IAudioMeterInformation _AudioMeterInformation; 33 | private EEndpointHardwareSupport _HardwareSupport; 34 | private AudioMeterInformationChannels _Channels; 35 | 36 | internal AudioMeterInformation(IAudioMeterInformation realInterface) 37 | { 38 | int HardwareSupp; 39 | 40 | _AudioMeterInformation = realInterface; 41 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.QueryHardwareSupport(out HardwareSupp)); 42 | _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp; 43 | _Channels = new AudioMeterInformationChannels(_AudioMeterInformation); 44 | 45 | } 46 | 47 | public AudioMeterInformationChannels PeakValues 48 | { 49 | get 50 | { 51 | return _Channels; 52 | } 53 | } 54 | 55 | public EEndpointHardwareSupport HardwareSupport 56 | { 57 | get 58 | { 59 | return _HardwareSupport; 60 | } 61 | } 62 | 63 | public float MasterPeakValue 64 | { 65 | get 66 | { 67 | float result; 68 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetPeakValue(out result)); 69 | return result; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioMeterInformationChannels 31 | { 32 | IAudioMeterInformation _AudioMeterInformation; 33 | 34 | public int Count 35 | { 36 | get 37 | { 38 | int result; 39 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetMeteringChannelCount(out result)); 40 | return result; 41 | } 42 | } 43 | 44 | public float this[int index] 45 | { 46 | get 47 | { 48 | float[] peakValues = new float[Count]; 49 | GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned); 50 | Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject())); 51 | Params.Free(); 52 | return peakValues[index]; 53 | } 54 | } 55 | 56 | internal AudioMeterInformationChannels(IAudioMeterInformation parent) 57 | { 58 | _AudioMeterInformation = parent; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioMute 31 | { 32 | private IAudioMute _AudioMute; 33 | 34 | internal AudioMute(IAudioMute audioMute) 35 | { 36 | _AudioMute = audioMute; 37 | } 38 | 39 | public bool Mute 40 | { 41 | get 42 | { 43 | bool muted; 44 | Marshal.ThrowExceptionForHR(_AudioMute.GetMute(out muted)); 45 | return muted; 46 | } 47 | set 48 | { 49 | Guid eventContext; 50 | Marshal.ThrowExceptionForHR(_AudioMute.SetMute(value, out eventContext)); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class AudioPeakMeter 31 | { 32 | private IAudioPeakMeter _AudioPeakMeter; 33 | 34 | internal AudioPeakMeter(IAudioPeakMeter audioPeakMeter) 35 | { 36 | _AudioPeakMeter = audioPeakMeter; 37 | } 38 | 39 | public int GetChannelCount 40 | { 41 | get 42 | { 43 | int count; 44 | Marshal.ThrowExceptionForHR(_AudioPeakMeter.GetChannelCount(out count)); 45 | return count; 46 | } 47 | } 48 | 49 | public float GetLevel(int channel) 50 | { 51 | float level = 0; 52 | Marshal.ThrowExceptionForHR(_AudioPeakMeter.GetLevel((uint)channel, out level)); 53 | return level; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /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 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | internal class AudioSessionEvents : IAudioSessionEvents 32 | { 33 | private AudioSessionControl2 _Parent; 34 | 35 | internal AudioSessionEvents(AudioSessionControl2 parent) 36 | { 37 | _Parent = parent; 38 | } 39 | 40 | [PreserveSig] 41 | public int OnDisplayNameChanged([MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext) 42 | { 43 | _Parent.FireDisplayNameChanged(NewDisplayName, EventContext); 44 | return 0; 45 | } 46 | 47 | [PreserveSig] 48 | public int OnIconPathChanged([MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext) 49 | { 50 | _Parent.FireOnIconPathChanged(NewIconPath, EventContext); 51 | return 0; 52 | } 53 | 54 | [PreserveSig] 55 | public int OnSimpleVolumeChanged(float NewVolume, bool newMute, Guid EventContext) 56 | { 57 | _Parent.FireSimpleVolumeChanged(NewVolume, newMute, EventContext); 58 | return 0; 59 | } 60 | 61 | [PreserveSig] 62 | public int OnChannelVolumeChanged(UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext) 63 | { 64 | _Parent.FireChannelVolumeChanged(ChannelCount, NewChannelVolumeArray, ChangedChannel, EventContext); 65 | return 0; 66 | } 67 | 68 | [PreserveSig] 69 | public int OnGroupingParamChanged(Guid NewGroupingParam, Guid EventContext) 70 | { 71 | return 0; 72 | } 73 | 74 | [PreserveSig] 75 | public int OnStateChanged(AudioSessionState NewState) 76 | { 77 | _Parent.FireStateChanged(NewState); 78 | return 0; 79 | } 80 | 81 | [PreserveSig] 82 | public int OnSessionDisconnected(AudioSessionDisconnectReason DisconnectReason) 83 | { 84 | return 0; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /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 System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | using CoreAudio.Interfaces; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace CoreAudio 31 | { 32 | public class AudioSessionManager 33 | { 34 | private IAudioSessionManager _AudioSessionManager; 35 | 36 | internal AudioSessionManager(IAudioSessionManager realAudioSessionManager) 37 | { 38 | _AudioSessionManager = realAudioSessionManager; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /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.Collections.Generic; 25 | #if (NET40) 26 | using System.Linq; 27 | #endif 28 | using System.Text; 29 | using CoreAudio.Interfaces; 30 | using System.Runtime.InteropServices; 31 | 32 | namespace CoreAudio 33 | { 34 | public class AudioSessionManager2 : IDisposable 35 | { 36 | private IAudioSessionManager2 _AudioSessionManager2; 37 | private SessionCollection _Sessions; 38 | 39 | public delegate void SessionCreatedDelegate(object sender, IAudioSessionControl2 newSession); 40 | public event SessionCreatedDelegate OnSessionCreated; 41 | 42 | private AudioSessionNotification _AudioSessionNotification; 43 | 44 | internal AudioSessionManager2(IAudioSessionManager2 realAudioSessionManager2) 45 | { 46 | _AudioSessionManager2 = realAudioSessionManager2; 47 | 48 | RefreshSessions(); 49 | } 50 | 51 | internal void FireSessionCreated(IAudioSessionControl2 newSession) 52 | { 53 | if (OnSessionCreated != null) OnSessionCreated(this, newSession); 54 | } 55 | 56 | public void RefreshSessions() 57 | { 58 | UnregisterNotifications(); 59 | 60 | IAudioSessionEnumerator _SessionEnum; 61 | Marshal.ThrowExceptionForHR(_AudioSessionManager2.GetSessionEnumerator(out _SessionEnum)); 62 | _Sessions = new SessionCollection(_SessionEnum); 63 | 64 | _AudioSessionNotification = new AudioSessionNotification(this); 65 | Marshal.ThrowExceptionForHR(_AudioSessionManager2.RegisterSessionNotification(_AudioSessionNotification)); 66 | } 67 | 68 | public SessionCollection Sessions 69 | { 70 | get 71 | { 72 | return _Sessions; 73 | } 74 | } 75 | 76 | private void UnregisterNotifications() 77 | { 78 | if (_Sessions != null) 79 | _Sessions = null; 80 | 81 | if (_AudioSessionNotification != null) 82 | Marshal.ThrowExceptionForHR(_AudioSessionManager2.UnregisterSessionNotification(_AudioSessionNotification)); 83 | } 84 | 85 | public void Dispose() 86 | { 87 | UnregisterNotifications(); 88 | } 89 | 90 | ~AudioSessionManager2() 91 | { 92 | Dispose(); 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /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; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | internal class AudioSessionNotification : IAudioSessionNotification 32 | { 33 | private AudioSessionManager2 _Parent; 34 | 35 | internal AudioSessionNotification(AudioSessionManager2 parent) 36 | { 37 | _Parent = parent; 38 | } 39 | 40 | [PreserveSig] 41 | public int OnSessionCreated(IAudioSessionControl2 NewSession) 42 | { 43 | _Parent.FireSessionCreated(NewSession); 44 | return 0; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /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 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio { 30 | public class AudioVolumeLevel : PerChannelDbLevel { 31 | internal AudioVolumeLevel(IAudioVolumeLevel audioVolumeLevel) : base(audioVolumeLevel) { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public class AudioVolumeNotificationData 29 | { 30 | private Guid _EventContext; 31 | private bool _Muted; 32 | private float _MasterVolume; 33 | private int _Channels; 34 | private float[] _ChannelVolume; 35 | 36 | public Guid EventContext 37 | { 38 | get 39 | { 40 | return _EventContext; 41 | } 42 | } 43 | 44 | public bool Muted 45 | { 46 | get 47 | { 48 | return _Muted; 49 | } 50 | } 51 | 52 | public float MasterVolume 53 | { 54 | get 55 | { 56 | return _MasterVolume; 57 | } 58 | } 59 | public int Channels 60 | { 61 | get 62 | { 63 | return _Channels; 64 | } 65 | } 66 | 67 | public float[] ChannelVolume 68 | { 69 | get 70 | { 71 | return _ChannelVolume; 72 | } 73 | } 74 | public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume) 75 | { 76 | _EventContext = eventContext; 77 | _Muted = muted; 78 | _MasterVolume = masterVolume; 79 | _Channels = channelVolume.Length; 80 | _ChannelVolume = channelVolume; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /CoreAudio/CPolicyConfigClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using CoreAudio.Interfaces; 6 | 7 | namespace CoreAudio 8 | { 9 | [ComImport, Guid("870af99c-171d-4f9e-af0d-e63df40c2bc9")] 10 | internal class _CPolicyConfigClient 11 | { 12 | } 13 | 14 | public class CPolicyConfigClient 15 | { 16 | private IPolicyConfig _policyConfigClient = new _CPolicyConfigClient() as IPolicyConfig; 17 | 18 | public int SetDefaultDevie(string deviceID) 19 | { 20 | _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eConsole); 21 | _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eMultimedia); 22 | _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eCommunications); 23 | 24 | return 0; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CoreAudio/CPolicyConfigVistaClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using CoreAudio.Interfaces; 6 | 7 | namespace CoreAudio 8 | { 9 | [ComImport, Guid("294935CE-F637-4E7C-A41B-AB255460B862")] 10 | internal class _CPolicyConfigVistaClient 11 | { 12 | } 13 | 14 | public class CPolicyConfigVistaClient 15 | { 16 | private IPolicyConfigVista _policyConfigVistaClient = new _CPolicyConfigVistaClient() as IPolicyConfigVista; 17 | 18 | public int SetDefaultDevie(string deviceID) 19 | { 20 | _policyConfigVistaClient.SetDefaultEndpoint(deviceID, ERole.eConsole); 21 | _policyConfigVistaClient.SetDefaultEndpoint(deviceID, ERole.eMultimedia); 22 | _policyConfigVistaClient.SetDefaultEndpoint(deviceID, ERole.eCommunications); 23 | 24 | return 0; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CoreAudio/Connector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class Connector 31 | { 32 | private IConnector _Connector; 33 | private Part _Part; 34 | 35 | internal Connector(IConnector connector) 36 | { 37 | _Connector = connector; 38 | } 39 | 40 | public ConnectorType GetConnectorType 41 | { 42 | get 43 | { 44 | ConnectorType type; 45 | Marshal.ThrowExceptionForHR(_Connector.GetType(out type)); 46 | return type; 47 | } 48 | } 49 | 50 | public EDataFlow GetDataFlow 51 | { 52 | get 53 | { 54 | EDataFlow flow; 55 | Marshal.ThrowExceptionForHR(_Connector.GetDataFlow(out flow)); 56 | return flow; 57 | } 58 | } 59 | 60 | public void ConnecTo(Connector connectTo) 61 | { 62 | Marshal.ThrowExceptionForHR(_Connector.ConnectTo((IConnector)connectTo)); 63 | } 64 | 65 | public void Disconnect() 66 | { 67 | Marshal.ThrowExceptionForHR(_Connector.Disconnect()); 68 | } 69 | 70 | public bool IsConnected 71 | { 72 | get 73 | { 74 | bool result; 75 | Marshal.ThrowExceptionForHR(_Connector.IsConnected(out result)); 76 | return result; 77 | } 78 | } 79 | 80 | public Connector GetConnectedTo 81 | { 82 | get 83 | { 84 | IConnector connectedTo; 85 | Marshal.ThrowExceptionForHR(_Connector.GetConnectedTo(out connectedTo)); 86 | return new Connector(connectedTo); 87 | } 88 | } 89 | 90 | public string GetConnectorIdConnectedTo 91 | { 92 | get 93 | { 94 | string id; 95 | Marshal.ThrowExceptionForHR(_Connector.GetConnectorIdConnectedTo(out id)); 96 | return id; 97 | } 98 | } 99 | 100 | public string GetDeviceIdConnectedTo 101 | { 102 | get 103 | { 104 | string id; 105 | Marshal.ThrowExceptionForHR(_Connector.GetDeviceIdConnectedTo(out id)); 106 | return id; 107 | } 108 | } 109 | 110 | public Part GetPart 111 | { 112 | get 113 | { 114 | if (_Part == null) 115 | { 116 | IntPtr pUnk = Marshal.GetIUnknownForObject(_Connector); 117 | IntPtr ppv; 118 | 119 | int res = Marshal.QueryInterface(pUnk, ref IIDs.IID_IPart, out ppv); 120 | if (ppv != IntPtr.Zero) 121 | _Part = new Part((IPart)Marshal.GetObjectForIUnknown(ppv)); 122 | else 123 | _Part = null; 124 | } 125 | return _Part; 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AUDCLNT_RETURNFLAGS.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.Collections.Generic; 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | [Flags] 32 | public enum AUDCLNT_RETURNFLAGS : uint 33 | { 34 | S_OK = 0, 35 | AUDCLNT_E_NOT_INITIALIZED = 0x001, 36 | AUDCLNT_E_ALREADY_INITIALIZED = 0x002, 37 | AUDCLNT_E_WRONG_ENDPOINT_TYPE = 0x003, 38 | AUDCLNT_E_DEVICE_INVALIDATED = 0x004, 39 | AUDCLNT_E_NOT_STOPPED = 0x005, 40 | AUDCLNT_E_BUFFER_TOO_LARGE = 0x006, 41 | AUDCLNT_E_OUT_OF_ORDER = 0x007, 42 | AUDCLNT_E_UNSUPPORTED_FORMAT = 0x008, 43 | AUDCLNT_E_INVALID_SIZE = 0x009, 44 | AUDCLNT_E_DEVICE_IN_USE = 0x00a, 45 | AUDCLNT_E_BUFFER_OPERATION_PENDING = 0x00b, 46 | AUDCLNT_E_THREAD_NOT_REGISTERED = 0x00c, 47 | AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED = 0x00e, 48 | AUDCLNT_E_ENDPOINT_CREATE_FAILED = 0x00f, 49 | AUDCLNT_E_SERVICE_NOT_RUNNING = 0x010, 50 | AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED = 0x011, 51 | AUDCLNT_E_EXCLUSIVE_MODE_ONLY = 0x012, 52 | AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL = 0x013, 53 | AUDCLNT_E_EVENTHANDLE_NOT_SET = 0x014, 54 | AUDCLNT_E_INCORRECT_BUFFER_SIZE = 0x015, 55 | AUDCLNT_E_BUFFER_SIZE_ERROR = 0x016, 56 | AUDCLNT_E_CPUUSAGE_EXCEEDED = 0x017, 57 | AUDCLNT_E_BUFFER_ERROR = 0x018, 58 | AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED = 0x019, 59 | AUDCLNT_E_INVALID_DEVICE_PERIOD = 0x020, 60 | AUDCLNT_S_BUFFER_EMPTY = 0x001, 61 | AUDCLNT_S_THREAD_ALREADY_REGISTERED = 0x002, 62 | AUDCLNT_S_POSITION_STALLED = 0x003 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AUDCLNT_SESSIONFLAGS.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.Collections.Generic; 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | [Flags] 32 | public enum AUDCLNT_SESSIONFLAGS : uint 33 | { 34 | AUDCLNT_SESSIONFLAGS_EXPIREWHENUNOWNED = 0x10000000, 35 | AUDCLNT_SESSIONFLAGS_DISPLAY_HIDE = 0x20000000, 36 | AUDCLNT_SESSIONFLAGS_DISPLAY_HIDEWHENEXPIRED = 0x40000000 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreAudio/Constants/AUDCLNT_STREAMFLAGS.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.Collections.Generic; 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | [Flags] 32 | public enum AUDCLNT_STREAMFLAGS : uint 33 | { 34 | AUDCLNT_STREAMFLAGS_CROSSPROCESS = 0x00010000, 35 | AUDCLNT_STREAMFLAGS_LOOPBACK = 0x00020000, 36 | AUDCLNT_STREAMFLAGS_EVENTCALLBACK = 0x00040000, 37 | AUDCLNT_STREAMFLAGS_NOPERSIST = 0x00080000, 38 | AUDCLNT_STREAMFLAGS_RATEADJUST = 0x00100000 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudio/Constants/DEVICE_STATE.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 | using System.Collections.Generic; 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | [Flags] 32 | public enum DEVICE_STATE : uint 33 | { 34 | DEVICE_STATE_ACTIVE = 0x00000001, 35 | DEVICE_STATE_DISABLED = 0x00000002, 36 | DEVICE_STATE_NOTPRESENT = 0x00000004, 37 | DEVICE_STATE_UNPLUGGED = 0x00000008, 38 | DEVICE_STATEMASK_ALL = 0x0000000F 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudio/Constants/ENDPOINT_HARDWARE_SUPPORT.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.Collections.Generic; 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | [Flags] 32 | public enum ENDPOINT_HARDWARE_SUPPORT : uint 33 | { 34 | ENDPOINT_HARDWARE_SUPPORT_VOLUME = 0x00000001, 35 | ENDPOINT_HARDWARE_SUPPORT_MUTE = 0x00000002, 36 | ENDPOINT_HARDWARE_SUPPORT_METER = 0x00000004 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreAudio/Constants/_AUDCLNT_BUFFERFLAGS.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.Collections.Generic; 27 | #if (NET40) 28 | using System.Linq; 29 | #endif 30 | using System.Text; 31 | 32 | namespace CoreAudio 33 | { 34 | public enum _AUDCLNT_BUFFERFLAGS 35 | { 36 | AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY = 0x1, 37 | AUDCLNT_BUFFERFLAGS_SILENT = 0x2, 38 | AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR = 0x4 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /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.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace CoreAudio 30 | { 31 | internal class ControlChangeNotify : IControlChangeNotify, IDisposable 32 | { 33 | private Part _Parent; 34 | private GCHandle rcwHandle; 35 | 36 | internal ControlChangeNotify(Part parent) 37 | { 38 | _Parent = parent; 39 | rcwHandle = GCHandle.Alloc(this, GCHandleType.Normal); 40 | } 41 | 42 | public bool IsAllocated 43 | { 44 | get { return rcwHandle.IsAllocated; } 45 | } 46 | 47 | [PreserveSig] 48 | public int OnNotify(UInt32 dwSenderProcessId, ref Guid pguidEventContext) 49 | { 50 | if(System.Diagnostics.Process.GetCurrentProcess().Id != dwSenderProcessId) 51 | _Parent.FireNotification(dwSenderProcessId, ref pguidEventContext); 52 | return 0; 53 | } 54 | 55 | #region IDisposable Members 56 | 57 | public void Dispose() 58 | { 59 | if(rcwHandle.IsAllocated) rcwHandle.Free(); 60 | } 61 | 62 | #endregion 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class ControlInterface 31 | { 32 | private IControlInterface _ControlInterface; 33 | 34 | internal ControlInterface(IControlInterface controlInterface) 35 | { 36 | _ControlInterface = controlInterface; 37 | } 38 | 39 | public string GetName 40 | { 41 | get 42 | { 43 | string name; 44 | Marshal.ThrowExceptionForHR(_ControlInterface.GetName(out name)); 45 | return name; 46 | } 47 | } 48 | 49 | public Guid GetId 50 | { 51 | get 52 | { 53 | Guid id; 54 | Marshal.ThrowExceptionForHR(_ControlInterface.GetID(out id)); 55 | return id; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CoreAudio/CoreAudio.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreAudio", "CoreAudio.csproj", "{9F1076AA-63DF-4128-9C10-FD65E425C783}" 5 | EndProject 6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Tester", "..\Tester\Tester.vbproj", "{5FD98961-3778-49BF-8C65-276EB9A49A7B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|x86.ActiveCfg = Debug|x86 15 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|x86.Build.0 = Debug|x86 16 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|x86.ActiveCfg = Release|x86 17 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|x86.Build.0 = Release|x86 18 | {5FD98961-3778-49BF-8C65-276EB9A49A7B}.Debug|x86.ActiveCfg = Debug|x86 19 | {5FD98961-3778-49BF-8C65-276EB9A49A7B}.Debug|x86.Build.0 = Debug|x86 20 | {5FD98961-3778-49BF-8C65-276EB9A49A7B}.Release|x86.ActiveCfg = Release|x86 21 | {5FD98961-3778-49BF-8C65-276EB9A49A7B}.Release|x86.Build.0 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class DeviceTopology 31 | { 32 | private IDeviceTopology _DeviceTopology; 33 | 34 | internal DeviceTopology(IDeviceTopology realInterface) 35 | { 36 | _DeviceTopology = realInterface; 37 | 38 | } 39 | 40 | public int GetConnectorCount 41 | { 42 | get 43 | { 44 | int count = 0; 45 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetConnectorCount(out count)); 46 | return count; 47 | } 48 | } 49 | 50 | public Connector GetConnector(int index) 51 | { 52 | IConnector connector; 53 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetConnector(index, out connector)); 54 | return new Connector(connector); 55 | } 56 | 57 | public int GetSubunitCount 58 | { 59 | get 60 | { 61 | int count = 0; 62 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetSubunitCount(out count)); 63 | return count; 64 | } 65 | } 66 | 67 | public Subunit GetSubunit(int index) 68 | { 69 | ISubunit subUnit; 70 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetSubunit(index, out subUnit)); 71 | return new Subunit(subUnit); 72 | } 73 | 74 | public Part GetPartById(int id) 75 | { 76 | IPart part; 77 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetPartById(id, out part)); 78 | return new Part(part); 79 | } 80 | 81 | public string GetDeviceId 82 | { 83 | get 84 | { 85 | string id; 86 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetDeviceId(out id)); 87 | return id; 88 | } 89 | } 90 | 91 | public PartsList GetSignalPath(Part from, Part to, bool rejectMixedPaths) 92 | { 93 | IPartsList partList; 94 | Marshal.ThrowExceptionForHR(_DeviceTopology.GetSignalPath((IPart)from, (IPart)to, rejectMixedPaths, out partList)); 95 | return new PartsList(partList); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/AUDCLNT_SHAREMODE.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.Collections.Generic; 27 | #if (NET40) 28 | using System.Linq; 29 | #endif 30 | using System.Text; 31 | 32 | namespace CoreAudio 33 | { 34 | public enum AUDCLNT_SHAREMODE 35 | { 36 | AUDCLNT_SHAREMODE_SHARED, 37 | AUDCLNT_SHAREMODE_EXCLUSIVE 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | #if (NET40) 25 | using System.Linq; 26 | #endif 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | public enum AudioSessionDisconnectReason 32 | { 33 | DisconnectReasonDeviceRemoval = 0, 34 | DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1), 35 | DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1), 36 | DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1), 37 | DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1), 38 | DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | #if (NET40) 25 | using System.Linq; 26 | #endif 27 | using System.Text; 28 | 29 | namespace CoreAudio 30 | { 31 | public enum AudioSessionState 32 | { 33 | AudioSessionStateInactive = 0, 34 | AudioSessionStateActive = 1, 35 | AudioSessionStateExpired = 2 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public enum ConnectorType 29 | { 30 | Unknown_Connector = 0, 31 | Physical_Internal = (Unknown_Connector + 1), 32 | Physical_External = (Physical_Internal + 1), 33 | Software_IO = (Physical_External + 1), 34 | Software_Fixed = (Software_IO + 1), 35 | Network = (Software_Fixed + 1) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/EDataFlow.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public enum EDataFlow 29 | { 30 | eRender = 0, 31 | eCapture = 1, 32 | eAll = 2 , 33 | EDataFlow_enum_count =3 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | [Flags] 29 | public enum EEndpointHardwareSupport 30 | { 31 | Volume = 0x00000001, 32 | Mute = 0x00000002, 33 | Meter = 0x00000004 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CoreAudio/Enumerations/ERole.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public enum ERole 29 | { 30 | eConsole =0, 31 | eMultimedia =1, 32 | eCommunications=2, 33 | ERole_enum_count=3 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public enum PartType 29 | { 30 | Connector = 0, 31 | Subunit = (Connector + 1) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /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 System.Collections.Generic; 27 | #if (NET40) 28 | using System.Linq; 29 | #endif 30 | using System.Text; 31 | 32 | namespace CoreAudio 33 | { 34 | public class IIDs 35 | { 36 | public static Guid IID_IAudioCaptureClient = typeof(Interfaces.IAudioCaptureClient).GUID; 37 | //public static Guid IID_IAudioClock 38 | //public static Guid IID_IAudioRenderClient 39 | //public static Guid IID_IAudioSessionControl 40 | //public static Guid IID_IAudioStreamVolume 41 | //public static Guid IID_IChannelAudioVolume 42 | //public static Guid IID_IMFTrustedOutput 43 | 44 | public static Guid IID_ISimpleAudioVolume = typeof(Interfaces.ISimpleAudioVolume).GUID; 45 | public static Guid IID_IAudioVolumeLevel = typeof(Interfaces.IAudioVolumeLevel).GUID; 46 | public static Guid IID_IAudioMute = typeof(Interfaces.IAudioMute).GUID; 47 | public static Guid IID_IAudioPeakMeter = typeof(Interfaces.IAudioPeakMeter).GUID; 48 | public static Guid IID_IAudioLoudness = typeof(Interfaces.IAudioLoudness).GUID; 49 | 50 | public static Guid IID_IAudioMeterInformation = typeof(Interfaces.IAudioMeterInformation).GUID; 51 | public static Guid IID_IAudioEndpointVolume = typeof(Interfaces.IAudioEndpointVolume).GUID; 52 | public static Guid IID_IAudioSessionManager2 = typeof(Interfaces.IAudioSessionManager2).GUID; 53 | public static Guid IID_IDeviceTopology = typeof(Interfaces.IDeviceTopology).GUID; 54 | 55 | public static Guid IID_IPart = typeof(Interfaces.IPart).GUID; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | internal struct Blob 30 | { 31 | public int Length; 32 | public IntPtr Data; 33 | 34 | //Code Should Compile at warning level4 without any warnings, 35 | //However this struct will give us Warning CS0649: Field [Fieldname] 36 | //is never assigned to, and will always have its default value 37 | //You can disable CS0649 in the project options but that will disable 38 | //the warning for the whole project, it's a nice warning and we do want 39 | //it in other places so we make a nice dummy function to keep the compiler 40 | //happy. 41 | private void FixCS0649() 42 | { 43 | Length = 0; 44 | Data = IntPtr.Zero; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio.Interfaces 27 | { 28 | [Flags] 29 | internal enum CLSCTX : uint 30 | { 31 | INPROC_SERVER = 0x1, 32 | INPROC_HANDLER = 0x2, 33 | LOCAL_SERVER = 0x4, 34 | INPROC_SERVER16 = 0x8, 35 | REMOTE_SERVER = 0x10, 36 | INPROC_HANDLER16 = 0x20, 37 | RESERVED1 = 0x40, 38 | RESERVED2 = 0x80, 39 | RESERVED3 = 0x100, 40 | RESERVED4 = 0x200, 41 | NO_CODE_DOWNLOAD = 0x400, 42 | RESERVED5 = 0x800, 43 | NO_CUSTOM_MARSHAL = 0x1000, 44 | ENABLE_CODE_DOWNLOAD = 0x2000, 45 | NO_FAILURE_LOG = 0x4000, 46 | DISABLE_AAA = 0x8000, 47 | ENABLE_AAA = 0x10000, 48 | FROM_DEFAULT_CONTEXT = 0x20000, 49 | INPROC = INPROC_SERVER | INPROC_HANDLER, 50 | SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER, 51 | ALL = SERVER | INPROC_HANDLER 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("7D8B1437-DD53-4350-9C1B-1EE2890BD938"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IAudioLoudness 33 | { 34 | int GetEnabled([Out(), MarshalAs(UnmanagedType.Bool)] out bool enabled); 35 | int SetEnabled([MarshalAs(UnmanagedType.Bool)] bool enabled, out Guid eventContext); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IAudioMute 33 | { 34 | int SetMute([MarshalAs(UnmanagedType.Bool)] bool muted, out Guid eventContext); 35 | int GetMute([Out(), MarshalAs(UnmanagedType.Bool)] out bool muted); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("DD79923C-0599-45e0-B8B6-C8DF7DB6E796"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IAudioPeakMeter 33 | { 34 | int GetChannelCount(out int pcChannels); 35 | int GetLevel(uint channel, out float level); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IAudioVolumeLevel : IPerChannelDbLevel { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("9c2c4058-23f5-41de-877a-df3af236a09e"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IConnector 33 | { 34 | [PreserveSig] 35 | int GetType(out ConnectorType type); 36 | [PreserveSig] 37 | int GetDataFlow(out EDataFlow flow); 38 | [PreserveSig] 39 | int ConnectTo(IConnector connectTo); 40 | [PreserveSig] 41 | int Disconnect(); 42 | [PreserveSig] 43 | int IsConnected(out bool connected); 44 | [PreserveSig] 45 | int GetConnectedTo(out IConnector connectedTo); 46 | [PreserveSig] 47 | int GetConnectorIdConnectedTo([Out(), MarshalAs(UnmanagedType.LPWStr)] out string connectorId); 48 | [PreserveSig] 49 | int GetDeviceIdConnectedTo([Out(), MarshalAs(UnmanagedType.LPWStr)] out string deviceId); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("A09513ED-C709-4d21-BD7B-5F34C47F3947"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IControlChangeNotify 32 | { 33 | [PreserveSig] 34 | int OnNotify(UInt32 dwSenderProcessId, ref Guid pguidEventContext); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("45d37c3f-5140-444a-ae24-400789f3cbf3"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IControlInterface 33 | { 34 | [PreserveSig] 35 | int GetName([Out(), MarshalAs(UnmanagedType.LPWStr)] out string name); 36 | [PreserveSig] 37 | int GetID(out Guid id); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("2A07407E-6497-4A18-9787-32F79BD0D98F"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IDeviceTopology 33 | { 34 | [PreserveSig] 35 | int GetConnectorCount(out int count); 36 | [PreserveSig] 37 | int GetConnector(int index, out IConnector connector); 38 | [PreserveSig] 39 | int GetSubunitCount(out int count); 40 | [PreserveSig] 41 | int GetSubunit(int index, out ISubunit subunit); 42 | [PreserveSig] 43 | int GetPartById(int id, out IPart part); 44 | [PreserveSig] 45 | int GetDeviceId([Out(), MarshalAs(UnmanagedType.LPWStr)] out string deviceId); 46 | [PreserveSig] 47 | int GetSignalPath(IPart partFrom, IPart partTo, bool rejectMixedPaths, out IPartsList parts); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IPart 33 | { 34 | [PreserveSig] 35 | int GetName([Out(), MarshalAs(UnmanagedType.LPWStr)] out string name); 36 | [PreserveSig] 37 | int GetLocalId(out int id); 38 | [PreserveSig] 39 | int GetGlobalId([Out(), MarshalAs(UnmanagedType.LPWStr)] out string globalId); 40 | [PreserveSig] 41 | int GetPartType(out PartType partType); 42 | [PreserveSig] 43 | int GetSubType(out Guid subType); 44 | [PreserveSig] 45 | int GetControlInterfaceCount(out int count); 46 | [PreserveSig] 47 | int GetControlInterface(int index, out IControlInterface pInterface); 48 | [PreserveSig] 49 | int EnumPartsIncoming(out IPartsList parts); 50 | [PreserveSig] 51 | int EnumPartsOutgoing(out IPartsList parts); 52 | [PreserveSig] 53 | int GetTopologyObject(out IDeviceTopology topology); 54 | [PreserveSig] 55 | int Activate(CLSCTX dwClsContext, ref Guid refiid, [Out(), MarshalAs(UnmanagedType.IUnknown)] out object ppvObject); 56 | [PreserveSig] 57 | int RegisterControlChangeCallback(ref Guid refiid, IControlChangeNotify notify); 58 | [PreserveSig] 59 | int UnregisterControlChangeCallback(IControlChangeNotify notify); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IPartsList 33 | { 34 | [PreserveSig] 35 | int GetCount(out int count); 36 | [PreserveSig] 37 | int GetPart(int index, out IPart part); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("C2F8E001-F205-4BC9-99BC-C13B1E048CCB"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface IPerChannelDbLevel 33 | { 34 | [PreserveSig] 35 | int GetChannelCount(out uint count); 36 | [PreserveSig] 37 | int GetLevelRange(uint channel, out float minLevel, out float maxLevel, out float stepping); 38 | [PreserveSig] 39 | int GetLevel(uint channel, out float level); 40 | [PreserveSig] 41 | int SetLevel(uint channel, float level, out Guid eventContext); 42 | [PreserveSig] 43 | int SetLevelUniform(float level, out Guid eventContext); 44 | [PreserveSig] 45 | int SetLevelAllChannels(float[] levelsDB, ulong channels, Guid eventContext); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("82149A85-DBA6-4487-86BB-EA8F7FEFCC71"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface ISubunit 33 | { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IAudioEndpointVolume 32 | { 33 | [PreserveSig] 34 | int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); 35 | [PreserveSig] 36 | int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify); 37 | [PreserveSig] 38 | int GetChannelCount(out int pnChannelCount); 39 | [PreserveSig] 40 | int SetMasterVolumeLevel(float fLevelDB, Guid pguidEventContext); 41 | [PreserveSig] 42 | int SetMasterVolumeLevelScalar(float fLevel, Guid pguidEventContext); 43 | [PreserveSig] 44 | int GetMasterVolumeLevel(out float pfLevelDB); 45 | [PreserveSig] 46 | int GetMasterVolumeLevelScalar(out float pfLevel); 47 | [PreserveSig] 48 | int SetChannelVolumeLevel(uint nChannel, float fLevelDB, Guid pguidEventContext); 49 | [PreserveSig] 50 | int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, Guid pguidEventContext); 51 | [PreserveSig] 52 | int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB); 53 | [PreserveSig] 54 | int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel); 55 | [PreserveSig] 56 | int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, Guid pguidEventContext); 57 | [PreserveSig] 58 | int GetMute(out bool pbMute); 59 | [PreserveSig] 60 | int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount); 61 | [PreserveSig] 62 | int VolumeStepUp(Guid pguidEventContext); 63 | [PreserveSig] 64 | int VolumeStepDown(Guid pguidEventContext); 65 | [PreserveSig] 66 | int QueryHardwareSupport(out uint pdwHardwareSupportMask); 67 | [PreserveSig] 68 | int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("657804FA-D6AD-4496-8A60-352752AF4F89"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IAudioEndpointVolumeCallback 32 | { 33 | [PreserveSig] 34 | int OnNotify(IntPtr pNotifyData); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IAudioMeterInformation 32 | { 33 | [PreserveSig] 34 | int GetPeakValue(out float pfPeak); 35 | [PreserveSig] 36 | int GetMeteringChannelCount(out int pnChannelCount); 37 | [PreserveSig] 38 | int GetChannelsPeakValues( int u32ChannelCount,[In] IntPtr afPeakValues); 39 | [PreserveSig] 40 | int QueryHardwareSupport( out int pdwHardwareSupportMask); 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/IPolicyConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | 6 | // http://eretik.omegahg.com/download/PolicyConfig.h 7 | // http://social.microsoft.com/Forums/en-US/Offtopic/thread/9ebd7ad6-a460-4a28-9de9-2af63fd4a13e/ 8 | 9 | namespace CoreAudio.Interfaces 10 | { 11 | [Guid("f8679f50-850a-41cf-9c72-430f290290c8"), 12 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IPolicyConfig 14 | { 15 | [PreserveSig] 16 | int GetMixFormat(); 17 | [PreserveSig] 18 | int GetDeviceFormat(); 19 | [PreserveSig] 20 | int SetDeviceFormat(); 21 | [PreserveSig] 22 | int GetProcessingPeriod(); 23 | [PreserveSig] 24 | int SetProcessingPeriod(); 25 | [PreserveSig] 26 | int GetShareMode(); 27 | [PreserveSig] 28 | int SetShareMode(); 29 | [PreserveSig] 30 | int GetPropertyValue(); 31 | [PreserveSig] 32 | int SetPropertyValue(); 33 | [PreserveSig] 34 | int SetDefaultEndpoint([MarshalAs(UnmanagedType.LPWStr)] string wszDeviceId, ERole eRole); 35 | [PreserveSig] 36 | int SetEndpointVisibility(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CoreAudio/Interfaces/IPolicyConfigVista.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | 6 | // http://eretik.omegahg.com/download/PolicyConfig.h 7 | // http://social.microsoft.com/Forums/en-US/Offtopic/thread/9ebd7ad6-a460-4a28-9de9-2af63fd4a13e/ 8 | 9 | namespace CoreAudio.Interfaces 10 | { 11 | [Guid("568b9108-44bf-40b4-9006-86afe5b5a620"), 12 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | internal interface IPolicyConfigVista 14 | { 15 | [PreserveSig] 16 | int GetMixFormat(); 17 | [PreserveSig] 18 | int GetDeviceFormat(); 19 | [PreserveSig] 20 | int SetDeviceFormat(); 21 | [PreserveSig] 22 | int GetProcessingPeriod(); 23 | [PreserveSig] 24 | int SetProcessingPeriod(); 25 | [PreserveSig] 26 | int GetShareMode(); 27 | [PreserveSig] 28 | int SetShareMode(); 29 | [PreserveSig] 30 | int GetPropertyValue(); 31 | [PreserveSig] 32 | int SetPropertyValue(); 33 | [PreserveSig] 34 | int SetDefaultEndpoint([MarshalAs(UnmanagedType.LPWStr)] string wszDeviceId, ERole eRole); 35 | [PreserveSig] 36 | int SetEndpointVisibility(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IPropertyStore 32 | { 33 | [PreserveSig] 34 | int GetCount( out Int32 count); 35 | [PreserveSig] 36 | int GetAt(int iProp, out PROPERTYKEY pkey); 37 | [PreserveSig] 38 | int GetValue(ref PROPERTYKEY key, out PropVariant pv); 39 | [PreserveSig] 40 | int SetValue(ref PROPERTYKEY key, ref PropVariant propvar); 41 | [PreserveSig] 42 | int Commit( ); 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("D666063F-1587-4E43-81F1-B948E807363F"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IMMDevice 32 | { 33 | [PreserveSig] 34 | int Activate(ref Guid iid, CLSCTX dwClsCtx, IntPtr pActivationParams, [Out(), MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); 35 | [PreserveSig] 36 | int OpenPropertyStore(EStgmAccess stgmAccess, out IPropertyStore propertyStore); 37 | [PreserveSig] 38 | int GetId([Out(), MarshalAs(UnmanagedType.LPWStr)] out string ppstrId); 39 | [PreserveSig] 40 | int GetState(out DEVICE_STATE pdwState); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IMMDeviceCollection 32 | { 33 | [PreserveSig] 34 | int GetCount(out uint pcDevices); 35 | [PreserveSig] 36 | int Item(uint nDevice, out IMMDevice Device); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IMMDeviceEnumerator 32 | { 33 | [PreserveSig] 34 | int EnumAudioEndpoints(EDataFlow dataFlow, DEVICE_STATE StateMask, out IMMDeviceCollection device); 35 | [PreserveSig] 36 | int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice ppEndpoint); 37 | //[PreserveSig] 38 | //int SetDefaultAudioEndpoint(IMMDevice ppEndpoint); 39 | [PreserveSig] 40 | int GetDevice(string pwstrId, out IMMDevice ppDevice); 41 | [PreserveSig] 42 | int RegisterEndpointNotificationCallback(IntPtr pClient); 43 | [PreserveSig] 44 | int UnregisterEndpointNotificationCallback(IntPtr pClient); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("1BE09788-6894-4089-8586-9A2A6C265AC5"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | internal interface IMMEndpoint 32 | { 33 | [PreserveSig] 34 | int GetDataFlow(out EDataFlow pDataFlow); 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /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; 26 | using System.Collections.Generic; 27 | using System.Text; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace CoreAudio.Interfaces 31 | { 32 | [Guid("7991EEC9-7E89-4D85-8390-6C703CEC60C0"), 33 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 34 | internal interface IMMNotificationClient 35 | { 36 | [PreserveSig] 37 | void OnDeviceStateChanged([In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, DEVICE_STATE dwNewState); 38 | [PreserveSig] 39 | void OnDeviceAdded([In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId); 40 | [PreserveSig] 41 | void OnDeviceRemoved([In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId); 42 | [PreserveSig] 43 | void OnDefaultDeviceChanged(EDataFlow flow, ERole role, [In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId); 44 | [PreserveSig] 45 | void OnPropertyValueChanged([In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PROPERTYKEY key); 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /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; 26 | using System.Collections.Generic; 27 | using System.Text; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace CoreAudio.Interfaces 31 | { 32 | [Guid("C8ADBD64-E71E-48a0-A4DE-185C395CD317"), 33 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 34 | interface IAudioCaptureClient 35 | { 36 | [PreserveSig] 37 | AUDCLNT_RETURNFLAGS GetBuffer(out byte[] ppData, out _AUDCLNT_BUFFERFLAGS pNumFramesToRead, UInt64 pu64DevicePosition, UInt64 pu64QPCPosition); 38 | [PreserveSig] 39 | AUDCLNT_RETURNFLAGS ReleaseBuffer(UInt32 NumFramesRead); 40 | [PreserveSig] 41 | AUDCLNT_RETURNFLAGS GetNextPacketSize(out UInt32 pNumFramesInNextPacket); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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.Collections.Generic; 27 | using System.Text; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace CoreAudio.Interfaces 31 | { 32 | [Guid("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2"), 33 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 34 | interface IAudioClient 35 | { 36 | [PreserveSig] 37 | AUDCLNT_RETURNFLAGS Initialize(AUDCLNT_SHAREMODE ShareMode, AUDCLNT_STREAMFLAGS StreamFlags, long hnsBufferDuration, long hnsPeriodicity, WAVEFORMATEX pFormat, Guid AudioSessionGuid); 38 | [PreserveSig] 39 | AUDCLNT_RETURNFLAGS GetBufferSize(out UInt32 pNumBufferFrames); 40 | [PreserveSig] 41 | AUDCLNT_RETURNFLAGS GetStreamLatency(out long phnsLatency); 42 | [PreserveSig] 43 | AUDCLNT_RETURNFLAGS GetCurrentPadding(out long pNumPaddingFrames); 44 | [PreserveSig] 45 | AUDCLNT_RETURNFLAGS IsFormatSupported(AUDCLNT_SHAREMODE ShareMode, WAVEFORMATEX pFormat, out WAVEFORMATEX ppClosestMatch); 46 | [PreserveSig] 47 | AUDCLNT_RETURNFLAGS GetMixFormat(out WAVEFORMATEX ppDeviceFormat); 48 | [PreserveSig] 49 | AUDCLNT_RETURNFLAGS GetDevicePeriod(out long phnsDefaultDevicePeriod, out long phnsMinimumDevicePeriod); 50 | [PreserveSig] 51 | AUDCLNT_RETURNFLAGS Start(); 52 | [PreserveSig] 53 | AUDCLNT_RETURNFLAGS Stop(); 54 | [PreserveSig] 55 | AUDCLNT_RETURNFLAGS Reset(); 56 | [PreserveSig] 57 | AUDCLNT_RETURNFLAGS SetEventHandle(IntPtr eventHandle); 58 | [PreserveSig] 59 | AUDCLNT_RETURNFLAGS GetService(ref Guid riid, [Out, MarshalAs(UnmanagedType.IUnknown)] out object ppv); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("F4B1A599-7266-4319-A8CA-E70ACB11E8CD"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | public interface IAudioSessionControl 32 | { 33 | [PreserveSig] 34 | int GetState(out AudioSessionState state); 35 | [PreserveSig] 36 | int GetDisplayName([MarshalAs(UnmanagedType.LPWStr)] out string name); 37 | [PreserveSig] 38 | int SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string value, Guid EventContext); 39 | [PreserveSig] 40 | int GetIconPath([MarshalAs(UnmanagedType.LPWStr)] out string Path); 41 | [PreserveSig] 42 | int SetIconPath([MarshalAs(UnmanagedType.LPWStr)] string Value, Guid EventContext); 43 | [PreserveSig] 44 | int GetGroupingParam(out Guid GroupingParam); 45 | [PreserveSig] 46 | int SetGroupingParam(Guid Override, Guid Eventcontext); 47 | [PreserveSig] 48 | int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 49 | [PreserveSig] 50 | int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | public interface IAudioSessionControl2 32 | { 33 | [PreserveSig] 34 | int GetState(out AudioSessionState state); 35 | [PreserveSig] 36 | int GetDisplayName([Out(), MarshalAs(UnmanagedType.LPWStr)] out string name); 37 | [PreserveSig] 38 | int SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string value, Guid EventContext); 39 | [PreserveSig] 40 | int GetIconPath([Out(), MarshalAs(UnmanagedType.LPWStr)] out string Path); 41 | [PreserveSig] 42 | int SetIconPath([MarshalAs(UnmanagedType.LPWStr)] string Value, Guid EventContext); 43 | [PreserveSig] 44 | int GetGroupingParam(out Guid GroupingParam); 45 | [PreserveSig] 46 | int SetGroupingParam(Guid Override, Guid Eventcontext); 47 | [PreserveSig] 48 | int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 49 | [PreserveSig] 50 | int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications); 51 | [PreserveSig] 52 | int GetSessionIdentifier([Out(), MarshalAs(UnmanagedType.LPWStr)] out string retVal); 53 | [PreserveSig] 54 | int GetSessionInstanceIdentifier([Out(), MarshalAs(UnmanagedType.LPWStr)] out string retVal); 55 | [PreserveSig] 56 | int GetProcessId(out UInt32 retvVal); 57 | [PreserveSig] 58 | int IsSystemSoundsSession(); 59 | [PreserveSig] 60 | int SetDuckingPreference(bool optOut); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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 | using System; 25 | namespace CoreAudio.Interfaces 26 | { 27 | [Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"), 28 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 | internal interface IAudioSessionEnumerator 30 | { 31 | int GetCount(out int SessionCount); 32 | int GetSession(int SessionCount, out IAudioSessionControl2 Session); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | public interface IAudioSessionEvents 32 | { 33 | [PreserveSig] 34 | int OnDisplayNameChanged([MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext); 35 | [PreserveSig] 36 | int OnIconPathChanged([MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext); 37 | [PreserveSig] 38 | int OnSimpleVolumeChanged(float NewVolume,bool newMute, Guid EventContext); 39 | [PreserveSig] 40 | int OnChannelVolumeChanged(UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext); 41 | [PreserveSig] 42 | int OnGroupingParamChanged(Guid NewGroupingParam, Guid EventContext); 43 | [PreserveSig] 44 | int OnStateChanged(AudioSessionState NewState); 45 | [PreserveSig] 46 | int OnSessionDisconnected(AudioSessionDisconnectReason DisconnectReason); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Linq; 25 | using System.Text; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("BFA971F1-4D5E-40BB-935E-967039BFBEE4"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | interface IAudioSessionManager 33 | { 34 | [PreserveSig] 35 | int GetAudioSessionControl(ref Guid AudioSessionGuid, UInt32 StreamFlags, out IAudioSessionControl ISessionControl); 36 | [PreserveSig] 37 | int GetSimpleAudioVolume(ref Guid AudioSessionGuid, UInt32 StreamFlags, out ISimpleAudioVolume SimpleAudioVolume); 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | #if (NET40) 25 | using System.Linq; 26 | #endif 27 | using System.Text; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace CoreAudio.Interfaces 31 | { 32 | [Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"), 33 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 34 | interface IAudioSessionManager2 35 | { 36 | [PreserveSig] 37 | int GetAudioSessionControl(ref Guid AudioSessionGuid, UInt32 StreamFlags, out IAudioSessionControl2 ISessionControl); 38 | [PreserveSig] 39 | int GetSimpleAudioVolume(ref Guid AudioSessionGuid, UInt32 StreamFlags, out ISimpleAudioVolume SimpleAudioVolume); 40 | [PreserveSig] 41 | int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum); 42 | [PreserveSig] 43 | int RegisterSessionNotification(IAudioSessionNotification SessionNotification); 44 | [PreserveSig] 45 | int UnregisterSessionNotification(IAudioSessionNotification SessionNotification); 46 | [PreserveSig] 47 | int RegisterDuckNotification(string sessionID, IAudioSessionNotification IAudioVolumeDuckNotification); 48 | [PreserveSig] 49 | int UnregisterDuckNotification(IntPtr IAudioVolumeDuckNotification); 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | [Guid("641DD20B-4D41-49CC-ABA3-174B9477BB08"), 30 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 31 | public interface IAudioSessionNotification 32 | { 33 | [PreserveSig] 34 | int OnSessionCreated(Interfaces.IAudioSessionControl2 NewSession); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"), 31 | InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface ISimpleAudioVolume 33 | { 34 | [PreserveSig] 35 | int SetMasterVolume( float fLevel,ref Guid EventContext); 36 | [PreserveSig] 37 | int GetMasterVolume( out float pfLevel); 38 | [PreserveSig] 39 | int SetMute( bool bMute, ref Guid EventContext) ; 40 | [PreserveSig] 41 | int GetMute( out bool bMute); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio.Interfaces 27 | { 28 | internal enum EStgmAccess 29 | { 30 | STGM_READ = 0x00000000, 31 | STGM_WRITE = 0x00000001, 32 | STGM_READWRITE = 0x00000002 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio 29 | { 30 | public class MMDeviceCollection 31 | { 32 | private IMMDeviceCollection _MMDeviceCollection; 33 | 34 | public int Count 35 | { 36 | get 37 | { 38 | uint result; 39 | Marshal.ThrowExceptionForHR(_MMDeviceCollection.GetCount(out result)); 40 | return (int)result; 41 | } 42 | } 43 | 44 | public MMDevice this[int index] 45 | { 46 | get 47 | { 48 | IMMDevice result; 49 | _MMDeviceCollection.Item((uint)index, out result); 50 | return new MMDevice(result); 51 | } 52 | } 53 | 54 | internal MMDeviceCollection(IMMDeviceCollection parent) 55 | { 56 | _MMDeviceCollection = parent; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CoreAudio/MMDeviceEnumerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using System.Runtime.InteropServices; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio 29 | { 30 | //Marked as internal, since on its own its no good 31 | [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] 32 | internal class _MMDeviceEnumerator 33 | { 34 | } 35 | 36 | //Small wrapper class 37 | public class MMDeviceEnumerator 38 | { 39 | private IMMDeviceEnumerator _realEnumerator = new _MMDeviceEnumerator() as IMMDeviceEnumerator; 40 | 41 | public MMDeviceCollection EnumerateAudioEndPoints(EDataFlow dataFlow, DEVICE_STATE dwStateMask) 42 | { 43 | IMMDeviceCollection result; 44 | Marshal.ThrowExceptionForHR(_realEnumerator.EnumAudioEndpoints(dataFlow,dwStateMask,out result)); 45 | return new MMDeviceCollection(result); 46 | } 47 | 48 | public MMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role) 49 | { 50 | IMMDevice _Device = null; 51 | Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDefaultAudioEndpoint(dataFlow, role, out _Device)); 52 | return new MMDevice(_Device); 53 | } 54 | 55 | public void SetDefaultAudioEndpoint(MMDevice device) 56 | { 57 | //Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).SetDefaultAudioEndpoint(device.ReadDevice)); 58 | device.Selected = true; 59 | } 60 | 61 | public MMDevice GetDevice(string ID) 62 | { 63 | IMMDevice _Device = null; 64 | Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDevice(ID, out _Device)); 65 | return new MMDevice(_Device); 66 | } 67 | 68 | public MMDeviceEnumerator() 69 | { 70 | if (System.Environment.OSVersion.Version.Major < 6) 71 | { 72 | throw new NotSupportedException("This functionality is only supported on Windows Vista or newer."); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class PartsList 31 | { 32 | private IPartsList _PartsList; 33 | private Dictionary partsCache; 34 | 35 | internal PartsList(IPartsList partsList) 36 | { 37 | _PartsList = partsList; 38 | partsCache = new Dictionary(); 39 | } 40 | 41 | public int GetCount 42 | { 43 | get 44 | { 45 | int count = 0; 46 | Marshal.ThrowExceptionForHR(_PartsList.GetCount(out count)); 47 | return count; 48 | } 49 | } 50 | 51 | public Part GetPart(int index) 52 | { 53 | if (partsCache.ContainsKey(index)) 54 | { 55 | return partsCache[index]; 56 | } 57 | else 58 | { 59 | IPart ipart; 60 | Marshal.ThrowExceptionForHR(_PartsList.GetPart(index, out ipart)); 61 | Part part = new Part(ipart); 62 | partsCache.Add(index, part); 63 | return part; 64 | } 65 | 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CoreAudio/PerChannelDbLevel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class PerChannelDbLevel 31 | { 32 | public struct LevelRange 33 | { 34 | public float minLevel; 35 | public float maxLevel; 36 | public float stepping; 37 | 38 | public LevelRange(float minLevel, float maxLevel, float stepping) 39 | { 40 | this.minLevel = minLevel; 41 | this.maxLevel = maxLevel; 42 | this.stepping = stepping; 43 | } 44 | } 45 | 46 | private IPerChannelDbLevel _PerChannelDbLevel; 47 | 48 | internal PerChannelDbLevel(IPerChannelDbLevel perChannelDbLevel) 49 | { 50 | _PerChannelDbLevel = perChannelDbLevel; 51 | } 52 | 53 | public int GetChannelCount 54 | { 55 | get 56 | { 57 | uint count; 58 | Marshal.ThrowExceptionForHR(_PerChannelDbLevel.GetChannelCount(out count)); 59 | return (int)count; 60 | } 61 | } 62 | 63 | public float GetLevel(int channel) 64 | { 65 | System.Threading.Thread.Sleep(5); 66 | float level = 0; 67 | try { 68 | Marshal.ThrowExceptionForHR(_PerChannelDbLevel.GetLevel((uint)channel, out level)); 69 | } catch(Exception) { 70 | System.Threading.Thread.Sleep(100); 71 | } 72 | return level; 73 | } 74 | 75 | public LevelRange GetLevelRange(int channel) 76 | { 77 | float minLevel = 0; 78 | float maxLevel = 0; 79 | float stepping = 0; 80 | System.Threading.Thread.Sleep(5); 81 | try { 82 | Marshal.ThrowExceptionForHR(_PerChannelDbLevel.GetLevelRange((uint)channel, out minLevel, out maxLevel, out stepping)); 83 | } catch(Exception) { 84 | System.Threading.Thread.Sleep(100); 85 | } 86 | return new LevelRange(minLevel, maxLevel, stepping); 87 | } 88 | 89 | public void SetLevel(int channel, float level) 90 | { 91 | Guid eventContext; 92 | Marshal.ThrowExceptionForHR(_PerChannelDbLevel.SetLevel((uint)channel, level, out eventContext)); 93 | } 94 | 95 | public void SetLevelUniform(float level) 96 | { 97 | Guid eventContext; 98 | System.Threading.Thread.Sleep(5); 99 | try { 100 | Marshal.ThrowExceptionForHR(_PerChannelDbLevel.SetLevelUniform(level, out eventContext)); 101 | } catch(Exception) { 102 | System.Threading.Thread.Sleep(100); 103 | } 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /CoreAudio/PropVariant.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Runtime.InteropServices.ComTypes; 27 | using System.Runtime.InteropServices; 28 | using CoreAudio.Interfaces; 29 | 30 | namespace CoreAudio 31 | { 32 | [StructLayout(LayoutKind.Explicit)] 33 | public struct PropVariant 34 | { 35 | [FieldOffset(0)] short vt; 36 | [FieldOffset(2)] short wReserved1; 37 | [FieldOffset(4)] short wReserved2; 38 | [FieldOffset(6)] short wReserved3; 39 | [FieldOffset(8)] sbyte cVal; 40 | [FieldOffset(8)] byte bVal; 41 | [FieldOffset(8)] short iVal; 42 | [FieldOffset(8)] ushort uiVal; 43 | [FieldOffset(8)] int lVal; 44 | [FieldOffset(8)] uint ulVal; 45 | [FieldOffset(8)] long hVal; 46 | [FieldOffset(8)] ulong uhVal; 47 | [FieldOffset(8)] float fltVal; 48 | [FieldOffset(8)] double dblVal; 49 | [FieldOffset(8)] Blob blobVal; 50 | [FieldOffset(8)] DateTime date; 51 | [FieldOffset(8)] bool boolVal; 52 | [FieldOffset(8)] int scode; 53 | [FieldOffset(8)] System.Runtime.InteropServices.ComTypes.FILETIME filetime; 54 | [FieldOffset(8)] IntPtr everything_else; 55 | 56 | //I'm sure there is a more efficient way to do this but this works ..for now.. 57 | internal byte[] GetBlob() 58 | { 59 | byte[] Result = new byte[blobVal.Length]; 60 | for (int i = 0; i < blobVal.Length; i++) 61 | { 62 | Result[i] = Marshal.ReadByte((IntPtr) ((long)(blobVal.Data) + i)); 63 | } 64 | return Result; 65 | } 66 | 67 | public object Value 68 | { 69 | get 70 | { 71 | VarEnum ve = (VarEnum)vt; 72 | switch (ve) 73 | { 74 | case VarEnum.VT_I1: 75 | return bVal; 76 | case VarEnum.VT_I2: 77 | return iVal; 78 | case VarEnum.VT_I4: 79 | return lVal; 80 | case VarEnum.VT_I8: 81 | return hVal; 82 | case VarEnum.VT_INT: 83 | return iVal; 84 | case VarEnum.VT_UI4: 85 | return ulVal; 86 | case VarEnum.VT_LPWSTR: 87 | return Marshal.PtrToStringUni(everything_else); 88 | case VarEnum.VT_BLOB: 89 | return GetBlob(); 90 | } 91 | return "FIXME Type = " + ve.ToString(); 92 | } 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /CoreAudio/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CoreAudio")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CoreAudio")] 13 | [assembly: AssemblyCopyright("Copyright ©2007-2010 Ray Molenkamp")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("07999b05-adc1-4c8c-89e2-5d1f2a710e54")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("2.0.0.0")] 35 | [assembly: AssemblyFileVersion("2.0.0.0")] 36 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | /// 31 | /// Property Store class, only supports reading properties at the moment. 32 | /// 33 | public class PropertyStore 34 | { 35 | private IPropertyStore _Store; 36 | 37 | public int Count 38 | { 39 | get 40 | { 41 | int Result; 42 | Marshal.ThrowExceptionForHR(_Store.GetCount(out Result)); 43 | return Result; 44 | } 45 | } 46 | 47 | public PropertyStoreProperty this[int index] 48 | { 49 | get 50 | { 51 | PropVariant result; 52 | PROPERTYKEY key = Get(index); 53 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); 54 | return new PropertyStoreProperty(key, result); 55 | } 56 | } 57 | 58 | public bool Contains(PROPERTYKEY testKey) 59 | { 60 | for (int i = 0; i < Count; i++) 61 | { 62 | PROPERTYKEY key = Get(i); 63 | if (key.fmtid == testKey.fmtid && key.pid == testKey.pid) 64 | return true; 65 | } 66 | return false; 67 | } 68 | 69 | public PropertyStoreProperty this[PROPERTYKEY testKey] 70 | { 71 | get 72 | { 73 | PropVariant result; 74 | for (int i = 0; i < Count; i++) 75 | { 76 | PROPERTYKEY key = Get(i); 77 | if (key.fmtid == testKey.fmtid && key.pid == testKey.pid) 78 | { 79 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); 80 | return new PropertyStoreProperty(key, result); 81 | } 82 | } 83 | return null; 84 | } 85 | } 86 | 87 | public PROPERTYKEY Get(int index) 88 | { 89 | PROPERTYKEY key; 90 | Marshal.ThrowExceptionForHR( _Store.GetAt(index, out key)); 91 | return key; 92 | } 93 | 94 | public PropVariant GetValue(int index) 95 | { 96 | PropVariant result; 97 | PROPERTYKEY key = Get(index); 98 | Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result)); 99 | return result; 100 | } 101 | 102 | internal PropertyStore(IPropertyStore store) 103 | { 104 | _Store = store; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /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 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using CoreAudio.Interfaces; 27 | 28 | namespace CoreAudio 29 | { 30 | public class PropertyStoreProperty 31 | { 32 | private PROPERTYKEY _PropertyKey; 33 | private PropVariant _PropValue; 34 | 35 | internal PropertyStoreProperty(PROPERTYKEY key, PropVariant value) 36 | { 37 | _PropertyKey = key; 38 | _PropValue = value; 39 | } 40 | 41 | public PROPERTYKEY Key 42 | { 43 | get 44 | { 45 | return _PropertyKey; 46 | } 47 | } 48 | 49 | public object Value 50 | { 51 | get 52 | { 53 | return _PropValue.Value; 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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 | 23 | using System; 24 | using System.Collections.Generic; 25 | #if (NET40) 26 | using System.Linq; 27 | #endif 28 | using System.Text; 29 | using CoreAudio.Interfaces; 30 | using System.Runtime.InteropServices; 31 | 32 | namespace CoreAudio 33 | { 34 | public class SessionCollection 35 | { 36 | IAudioSessionEnumerator _AudioSessionEnumerator; 37 | internal SessionCollection(IAudioSessionEnumerator realEnumerator) 38 | { 39 | _AudioSessionEnumerator = realEnumerator; 40 | } 41 | 42 | public AudioSessionControl2 this[int index] 43 | { 44 | get 45 | { 46 | IAudioSessionControl2 _Result; 47 | Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetSession(index, out _Result)); 48 | return new AudioSessionControl2(_Result); 49 | } 50 | } 51 | 52 | public int Count 53 | { 54 | get 55 | { 56 | int result; 57 | Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetCount(out result)); 58 | return (int)result; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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.Collections.Generic; 25 | #if (NET40) 26 | using System.Linq; 27 | #endif 28 | using System.Text; 29 | using CoreAudio.Interfaces; 30 | using System.Runtime.InteropServices; 31 | 32 | namespace CoreAudio 33 | { 34 | public class SimpleAudioVolume 35 | { 36 | ISimpleAudioVolume _SimpleAudioVolume; 37 | internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume) 38 | { 39 | _SimpleAudioVolume = realSimpleVolume; 40 | } 41 | 42 | public float MasterVolume 43 | { 44 | get 45 | { 46 | float ret; 47 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMasterVolume(out ret)); 48 | return ret; 49 | } 50 | set 51 | { 52 | Guid Empty = Guid.Empty; 53 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMasterVolume(value, ref Empty)); 54 | } 55 | } 56 | 57 | public bool Mute 58 | { 59 | get 60 | { 61 | bool ret; 62 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMute(out ret)); 63 | return ret; 64 | } 65 | set 66 | { 67 | Guid Empty = Guid.Empty; 68 | Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMute(value, ref Empty)); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /CoreAudio/Structures/AUDIO_VOLUME_NOTIFICATION_DATA.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace CoreAudio.Interfaces 28 | { 29 | internal struct AUDIO_VOLUME_NOTIFICATION_DATA 30 | { 31 | public Guid guidEventContext; 32 | public bool bMuted; 33 | public float fMasterVolume; 34 | public uint nChannels; 35 | public float ChannelVolume; 36 | 37 | //Code Should Compile at warning level4 without any warnings, 38 | //However this struct will give us Warning CS0649: Field [Fieldname] 39 | //is never assigned to, and will always have its default value 40 | //You can disable CS0649 in the project options but that will disable 41 | //the warning for the whole project, it's a nice warning and we do want 42 | //it in other places so we make a nice dummy function to keep the compiler 43 | //happy. 44 | private void FixCS0649() 45 | { 46 | guidEventContext = Guid.Empty; 47 | bMuted = false; 48 | fMasterVolume = 0; 49 | nChannels = 0; 50 | ChannelVolume = 0; 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | 26 | namespace CoreAudio 27 | { 28 | public struct PROPERTYKEY 29 | { 30 | public Guid fmtid; 31 | public int pid; 32 | 33 | public PROPERTYKEY(Guid fmtid, int pid) 34 | { 35 | this.fmtid = fmtid; 36 | this.pid = pid; 37 | } 38 | 39 | public static bool operator ==(PROPERTYKEY pk1, PROPERTYKEY pk2) 40 | { 41 | return (pk1.fmtid == pk2.fmtid) && (pk1.pid == pk2.pid); 42 | } 43 | 44 | public static bool operator !=(PROPERTYKEY pk1, PROPERTYKEY pk2) 45 | { 46 | return !(pk1 == pk2); 47 | } 48 | 49 | public override bool Equals(object obj) 50 | { 51 | return base.Equals(obj); 52 | } 53 | 54 | public override int GetHashCode() 55 | { 56 | return base.GetHashCode(); 57 | } 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /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; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio.Interfaces 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct WAVEFORMATEX 32 | { 33 | ushort wFormatTag; // format type 34 | ushort nChannels; // number of channels (i.e. mono, stereo...) 35 | uint nSamplesPerSec; // sample rate 36 | uint nAvgBytesPerSec; // for buffer estimation 37 | ushort nBlockAlign; // block size of data 38 | ushort wBitsPerSample; // number of bits per sample of mono data 39 | ushort cbSize; // the count in bytes of 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /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 | using System; 23 | using System.Collections.Generic; 24 | using System.Text; 25 | using CoreAudio.Interfaces; 26 | using System.Runtime.InteropServices; 27 | 28 | namespace CoreAudio 29 | { 30 | public class Subunit 31 | { 32 | private ISubunit _Subunit; 33 | 34 | internal Subunit(ISubunit subunit) 35 | { 36 | _Subunit = subunit; 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioConsoleTest/CoreAudioConsoleTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357} 9 | Exe 10 | Properties 11 | CoreAudioConsoleTest 12 | CoreAudioConsoleTest 13 | v4.0 14 | 15 | 16 | 512 17 | 18 | 19 | x86 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | x86 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | true 39 | bin\Debug\ 40 | DEBUG;TRACE 41 | full 42 | AnyCPU 43 | bin\Debug\CoreAudioConsoleTest.exe.CodeAnalysisLog.xml 44 | true 45 | GlobalSuppressions.cs 46 | prompt 47 | MinimumRecommendedRules.ruleset 48 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets 49 | true 50 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules 51 | true 52 | 53 | 54 | bin\Release\ 55 | TRACE 56 | true 57 | pdbonly 58 | AnyCPU 59 | bin\Release\CoreAudioConsoleTest.exe.CodeAnalysisLog.xml 60 | true 61 | GlobalSuppressions.cs 62 | prompt 63 | MinimumRecommendedRules.ruleset 64 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets 65 | ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | {9F1076AA-63DF-4128-9C10-FD65E425C783} 86 | CoreAudio 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioConsoleTest/Program.cs: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 2007-2010 Ray Molenkamp 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | using CoreAudio; 28 | using System.Diagnostics; 29 | 30 | namespace CoreAudioConsoleTest 31 | { 32 | /// 33 | /// This will find an active audio session, print some information about it and dispay the value of the peak meter and allow simple volume control. 34 | /// 35 | class Program 36 | { 37 | static void Main(string[] args) 38 | { 39 | MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); 40 | MMDevice device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); 41 | // Note the AudioSession manager did not have a method to enumerate all sessions in windows Vista 42 | // this will only work on Win7 and newer. 43 | for (int i = 0; i < device.AudioSessionManager2.Sessions.Count; i++) 44 | { 45 | AudioSessionControl2 session = device.AudioSessionManager2.Sessions[i]; 46 | if (session.State == AudioSessionState.AudioSessionStateActive) 47 | { 48 | Console.WriteLine("Session :{0}", i); 49 | Console.WriteLine("DisplayName: {0}", session.DisplayName); 50 | Console.WriteLine("State: {0}", session.State); 51 | Console.WriteLine("IconPath: {0}", session.IconPath); 52 | Console.WriteLine("SessionIdentifier: {0}", session.GetSessionIdentifier); 53 | Console.WriteLine("SessionInstanceIdentifier: {0}", session.GetSessionInstanceIdentifier); 54 | Console.WriteLine("ProcessID: {0}", session.GetProcessID); 55 | Console.WriteLine("IsSystemIsSystemSoundsSession: {0}", session.IsSystemSoundsSession); 56 | Process p = Process.GetProcessById((int)session.GetProcessID); 57 | Console.WriteLine("ProcessName: {0}", p.ProcessName); 58 | Console.WriteLine("MainWindowTitle: {0}", p.MainWindowTitle); 59 | AudioMeterInformation mi = session.AudioMeterInformation; 60 | SimpleAudioVolume vol = session.SimpleAudioVolume; 61 | Console.WriteLine("---[Hotkeys]---"); 62 | Console.WriteLine("M Toggle Mute"); 63 | Console.WriteLine(", Lower volume"); 64 | Console.WriteLine(", Raise volume"); 65 | Console.WriteLine("Q Quit"); 66 | int start = Console.CursorTop; 67 | while (true) 68 | { 69 | //Draw a VU meter 70 | int len = (int) (mi.MasterPeakValue * 79); 71 | Console.SetCursorPosition(0, start); 72 | for (int j = 0; j < len; j++) 73 | Console.Write("*"); 74 | for (int j = 0; j < 79 - len; j++) 75 | Console.Write(" "); 76 | Console.SetCursorPosition(0, start+1); 77 | Console.WriteLine("Mute : {0} ",vol.Mute); 78 | Console.WriteLine("Master : {0:0.00} ", vol.MasterVolume*100); 79 | if (Console.KeyAvailable) 80 | { 81 | ConsoleKeyInfo key = Console.ReadKey(); 82 | switch (key.Key) 83 | { 84 | case ConsoleKey.M: 85 | vol.Mute = !vol.Mute; 86 | break; 87 | case ConsoleKey.Q: 88 | return; 89 | case ConsoleKey.OemComma: 90 | float curvol = vol.MasterVolume - 0.1f; 91 | if (curvol < 0) curvol = 0; 92 | vol.MasterVolume = curvol; 93 | break; 94 | case ConsoleKey.OemPeriod: 95 | float curvold = vol.MasterVolume + 0.1f; 96 | if (curvold > 1) curvold = 1; 97 | vol.MasterVolume = curvold; 98 | break; 99 | } 100 | 101 | } 102 | } 103 | } 104 | } 105 | //If we end up here there where no open audio sessions to monitor. 106 | Console.WriteLine("No Audio sessions found"); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioConsoleTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CoreAudioConsoleTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("CoreAudioConsoleTest")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("df9ed106-88cb-45d3-9e2c-acc8e4097fb1")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioConsoleTest/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioSample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreAudioSample", "CoreAudioSample\CoreAudioSample.csproj", "{EDCDE937-2C83-49A6-A9B8-332AED11EABE}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreAudio", "..\CoreAudio\CoreAudio.csproj", "{9F1076AA-63DF-4128-9C10-FD65E425C783}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreAudioConsoleTest", "CoreAudioConsoleTest\CoreAudioConsoleTest.csproj", "{F0850BEC-4AB3-45DE-9C47-4071CD66E357}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|Mixed Platforms = Debug|Mixed Platforms 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|Mixed Platforms = Release|Mixed Platforms 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 23 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 24 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|x86.ActiveCfg = Debug|x86 25 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Debug|x86.Build.0 = Debug|x86 26 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 29 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Release|Mixed Platforms.Build.0 = Release|Any CPU 30 | {EDCDE937-2C83-49A6-A9B8-332AED11EABE}.Release|x86.ActiveCfg = Release|Any CPU 31 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 34 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 35 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|x86.ActiveCfg = Debug|x86 36 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Debug|x86.Build.0 = Debug|x86 37 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 40 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|Mixed Platforms.Build.0 = Release|Any CPU 41 | {9F1076AA-63DF-4128-9C10-FD65E425C783}.Release|x86.ActiveCfg = Release|Any CPU 42 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 45 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|Mixed Platforms.Build.0 = Debug|x86 46 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|x86.ActiveCfg = Debug|x86 47 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Debug|x86.Build.0 = Debug|x86 48 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Release|Any CPU.ActiveCfg = Release|x86 49 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Release|Mixed Platforms.ActiveCfg = Release|x86 50 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Release|Mixed Platforms.Build.0 = Release|x86 51 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Release|x86.ActiveCfg = Release|x86 52 | {F0850BEC-4AB3-45DE-9C47-4071CD66E357}.Release|x86.Build.0 = Release|x86 53 | EndGlobalSection 54 | GlobalSection(SolutionProperties) = preSolution 55 | HideSolutionNode = FALSE 56 | EndGlobalSection 57 | EndGlobal 58 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioSample/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Windows.Forms; 5 | 6 | namespace CoreAudioSample 7 | { 8 | public class Class1 9 | { 10 | static void Main(string[] args) 11 | { 12 | Application.EnableVisualStyles(); 13 | Application.Run(new Form1()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioSample/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using CoreAudio; 9 | 10 | namespace CoreAudioSample 11 | { 12 | public partial class Form1 : Form 13 | { 14 | private MMDevice device; 15 | 16 | public Form1() 17 | { 18 | InitializeComponent(); 19 | MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); 20 | device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); 21 | tbMaster.Value = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); 22 | device.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); 23 | timer1.Enabled = true; 24 | } 25 | 26 | void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data) 27 | { 28 | if (this.InvokeRequired) 29 | { 30 | object[] Params = new object[1]; 31 | Params[0] = data; 32 | this.Invoke(new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification), Params); 33 | } 34 | else 35 | { 36 | tbMaster.Value = (int)(data.MasterVolume * 100); 37 | } 38 | } 39 | 40 | private void tbMaster_Scroll(object sender, EventArgs e) 41 | { 42 | device.AudioEndpointVolume.MasterVolumeLevelScalar = ((float)tbMaster.Value / 100.0f); 43 | } 44 | 45 | private void timer1_Tick(object sender, EventArgs e) 46 | { 47 | pkMaster.Value = (int)(device.AudioMeterInformation.MasterPeakValue * 100); 48 | pkLeft.Value = (int)(device.AudioMeterInformation.PeakValues[0]*100); 49 | pkRight.Value = (int)(device.AudioMeterInformation.PeakValues[1]* 100); 50 | } 51 | 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CoreAudioSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CoreAudioSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2007")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c0cc63b6-bf6e-4714-92a2-209429c57d44")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /CoreAudioSample/CoreAudioSample/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2007-2010 Ray Molenkamp 2 | 3 | This source code is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this source code or the software it produces. 6 | 7 | Permission is granted to anyone to use this source code for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this source code must not be misrepresented; you must not 12 | claim that you wrote the original source code. If you use this source code 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original source code. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoreAudio 2 | 3 | This is a Ray Molenkamp's CoreAudio library for .NET, downloaded from the [XFX blog][dl]. 4 | The purpose of this repo is to make it available via Git, mostly so I can include it as a submodule 5 | in another repository. 6 | 7 | Ray (or whoever is currently maintaining this library): If you'd like ownership of this repository, 8 | send me an e-mail. 9 | 10 | ## Modifications 11 | 12 | The code is unmodified; I only removed binary files that were included in the original ZIP file as 13 | they do not really belong into a source code repository. 14 | 15 | ## License 16 | 17 | The library is licensed under what appears to be the zlib license. The license text is included in 18 | all source files. For your convenience, I added a [LICENSE][license] file with a copy of it. 19 | 20 | [dl]: http://whenimbored.xfx.net/download-links/?did=5 21 | [license]: https://github.com/ThiefMaster/coreaudio-dotnet/blob/master/LICENSE 22 | -------------------------------------------------------------------------------- /Tester/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Tester/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.1 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | 'NOTE: This file is auto-generated; do not modify it directly. To make changes, 18 | ' or if you encounter build errors in this file, go to the Project Designer 19 | ' (go to Project Properties or double-click the My Project node in 20 | ' Solution Explorer), and make changes on the Application tab. 21 | ' 22 | Partial Friend Class MyApplication 23 | 24 | _ 25 | Public Sub New() 26 | MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) 27 | Me.IsSingleInstance = false 28 | Me.EnableVisualStyles = true 29 | Me.SaveMySettingsOnExit = true 30 | Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses 31 | End Sub 32 | 33 | _ 34 | Protected Overrides Sub OnCreateMainForm() 35 | Me.MainForm = Global.Tester.frmMain 36 | End Sub 37 | End Class 38 | End Namespace 39 | -------------------------------------------------------------------------------- /Tester/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | true 4 | frmMain 5 | false 6 | 0 7 | true 8 | 0 9 | true 10 | -------------------------------------------------------------------------------- /Tester/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Tester/My Project/Resources.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.1 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My.Resources 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 | ''' 22 | ''' A strongly-typed resource class, for looking up localized strings, etc. 23 | ''' 24 | _ 28 | Friend Module Resources 29 | 30 | Private resourceMan As Global.System.Resources.ResourceManager 31 | 32 | Private resourceCulture As Global.System.Globalization.CultureInfo 33 | 34 | ''' 35 | ''' Returns the cached ResourceManager instance used by this class. 36 | ''' 37 | _ 38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 39 | Get 40 | If Object.ReferenceEquals(resourceMan, Nothing) Then 41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Tester.Resources", GetType(Resources).Assembly) 42 | resourceMan = temp 43 | End If 44 | Return resourceMan 45 | End Get 46 | End Property 47 | 48 | ''' 49 | ''' Overrides the current thread's CurrentUICulture property for all 50 | ''' resource lookups using this strongly typed resource class. 51 | ''' 52 | _ 53 | Friend Property Culture() As Global.System.Globalization.CultureInfo 54 | Get 55 | Return resourceCulture 56 | End Get 57 | Set(ByVal value As Global.System.Globalization.CultureInfo) 58 | resourceCulture = value 59 | End Set 60 | End Property 61 | End Module 62 | End Namespace 63 | -------------------------------------------------------------------------------- /Tester/My Project/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Tester/My Project/Settings.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.1 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.Tester.My.MySettings 68 | Get 69 | Return Global.Tester.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /Tester/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------