Skip to content

Commit

Permalink
Implemented classes for some missing interfaces needed to navigate de…
Browse files Browse the repository at this point in the history
…vice topology
  • Loading branch information
gribunin committed Mar 30, 2023
1 parent fdaf3c7 commit 76dc69e
Show file tree
Hide file tree
Showing 19 changed files with 893 additions and 19 deletions.
31 changes: 31 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/AudioMute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NAudio.CoreAudioApi.Interfaces;
using NAudio.Wasapi.CoreAudioApi.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.CoreAudioApi
{
public class AudioMute
{
private IAudioMute audioMuteInterface;
internal AudioMute(IAudioMute audioMute)
{
audioMuteInterface = audioMute;
}

public bool IsMuted
{
get
{
audioMuteInterface.GetMute(out var result);
return result;
}
set
{
var guid = Guid.Empty;
audioMuteInterface.SetMute(value, guid);
}
}
}
}
58 changes: 58 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/AudioVolumeLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using NAudio.CoreAudioApi.Interfaces;
using NAudio.Wasapi.CoreAudioApi.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.Wasapi.CoreAudioApi
{
public class AudioVolumeLevel
{
private readonly IAudioVolumeLevel audioVolumeLevelInterface;
private bool isLevelRangeRead = false;
private float minLevelDb, maxLevelDb, stepping;

internal AudioVolumeLevel(IAudioVolumeLevel audioVolumeLevel)
{
audioVolumeLevelInterface = audioVolumeLevel;
}

public uint ChannelCount
{
get
{
audioVolumeLevelInterface.GetChannelCount(out uint result);
return result;
}
}

public void GetLevelRange(uint channel, out float minLevelDb, out float maxLevelDb, out float stepping)
{
audioVolumeLevelInterface.GetLevelRange(channel, out minLevelDb, out maxLevelDb, out stepping);
}

public float GetLevel(uint channel)
{
audioVolumeLevelInterface.GetLevel(channel, out float result);
return result;
}

public void SetLevel(uint channel, float value)
{
var guid = Guid.Empty;
audioVolumeLevelInterface.SetLevel(channel, value, ref guid);
}

public void SetLevelUniform(float value)
{
var guid = Guid.Empty;
audioVolumeLevelInterface.SetLevelUniform(value, ref guid);
}

public void SetLevelAllChannel(float[] values, uint channels)
{
var guid = Guid.Empty;
audioVolumeLevelInterface.SetLevelAllChannel(values, channels, ref guid);
}
}
}
8 changes: 8 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public string ConnectedToDeviceId
connectorInterface.GetDeviceIdConnectedTo(out var result);
return result;
}
}

public Part Part
{
get
{
return new Part(connectorInterface as IPart);
}
}
}
}
21 changes: 21 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IAudioAutoGainControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("85401FD4-6DE4-4b9d-9869-2D6753A82F3C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IAudioAutoGainControl
{
[PreserveSig]
int GetEnabled(
[Out, MarshalAs(UnmanagedType.Bool)] out bool enabled);

[PreserveSig]
int SetEnabled(
[In, MarshalAs(UnmanagedType.Bool)] bool enabled);
}
}
22 changes: 22 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IAudioMute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IAudioMute
{
[PreserveSig]
int GetMute(
[Out, MarshalAs(UnmanagedType.Bool)] out bool mute);

[PreserveSig]
int SetMute(
[In, MarshalAs(UnmanagedType.Bool)] bool mute,
[In] ref Guid eventContext);
}
}
15 changes: 15 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IAudioVolumeLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IAudioVolumeLevel : IPerChannelDbLevel
{

}
}
18 changes: 18 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IControlChangeNotify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.Wasapi.CoreAudioApi.Interfaces
{
[Guid("9c2c4058-23f5-41de-877a-df3af236a09e"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
interface IControlChangeNotify
{
[PreserveSig]
int OnNotify(
[In] uint controlId,
[In] IntPtr context);
}
}
14 changes: 14 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IControlInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("45d37c3f-5140-444a-ae24-400789f3cbf3"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
public interface IControlInterface
{
}
}
17 changes: 17 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IKsJackDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NAudio.Utils;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("4509F757-2D46-4637-8E62-CE7DB944F57B"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IKsJackDescription
{
int GetJackCount([Out] out uint jacks);
int GetJackDescription([In] uint jack, [Out, MarshalAs(UnmanagedType.LPWStr)] out string description);
};
}
83 changes: 64 additions & 19 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IPart.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
/// <summary>
/// Windows CoreAudio IPart interface
/// Defined in devicetopology.h
/// </summary>
[Guid("AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IPart
{
// Stub, Not implemented
}
}
using NAudio.Wasapi.CoreAudioApi.Interfaces;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
/// <summary>
/// Windows CoreAudio IPart interface
/// Defined in devicetopology.h
/// </summary>
[Guid("AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IPart
{
int GetName(
[Out, MarshalAs(UnmanagedType.LPWStr)] out string name);

int GetLocalId(
[Out] out uint id);

int GetGlobalId(
[Out, MarshalAs(UnmanagedType.LPWStr)] out string id);

int GetPartType(
[Out] out PartTypeEnum partType);

int GetSubType(
out Guid subType);

int GetControlInterfaceCount(
[Out] out uint count);

int GetControlInterface(
[In] uint index,
[Out, MarshalAs(UnmanagedType.IUnknown)] out IControlInterface controlInterface);

[PreserveSig]
int EnumPartsIncoming(
[Out] out IPartsList parts);

[PreserveSig]
int EnumPartsOutgoing(
[Out] out IPartsList parts);

int GetTopologyObject(
[Out] out object topologyObject);

[PreserveSig]
int Activate(
[In] ClsCtx dwClsContext,
[In] ref Guid refiid,
[MarshalAs(UnmanagedType.IUnknown)] out object interfacePointer);

int RegisterControlChangeCallback(
[In] ref Guid refiid,
[In] IControlChangeNotify notify);

int UnregisterControlChangeCallback(
[In] IControlChangeNotify notify);
}
}
20 changes: 20 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/IPerChannelDbLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
[Guid("7FB7B48F-531D-44A2-BCB3-5AD5A134B3DC"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
ComImport]
internal interface IPerChannelDbLevel
{
int GetChannelCount(out uint channels);
int GetLevelRange(uint channel, out float minLevelDb, out float maxLevelDb, out float stepping);
int GetLevel(uint channel, out float levelDb);
int SetLevel(uint channel, float levelDb, ref Guid eventGuidContext);
int SetLevelUniform(float levelDb, ref Guid eventGuidContext);
int SetLevelAllChannel(float[] levelsDb, uint channels, ref Guid eventGuidContext);
}
}
17 changes: 17 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/Interfaces/PartType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.CoreAudioApi.Interfaces
{
public enum PartTypeEnum
{
Connector = 0,
Subunit = 1,
HardwarePeriphery = 2,
SoftwareDriver = 3,
Splitter = 4,
Category = 5,
Other = 6
}
}
35 changes: 35 additions & 0 deletions NAudio.Wasapi/CoreAudioApi/KsJackDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using NAudio.CoreAudioApi.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;

namespace NAudio.CoreAudioApi
{
public class KsJackDescription
{
private readonly IKsJackDescription ksJackDescriptionInterface;

internal KsJackDescription(IKsJackDescription ksJackDescription)
{
ksJackDescriptionInterface = ksJackDescription;
}

public uint Count
{
get
{
ksJackDescriptionInterface.GetJackCount(out var result);
return result;
}
}

public string this[uint index]
{
get
{
ksJackDescriptionInterface.GetJackDescription(index, out var result);
return result;
}
}
}
}
Loading

0 comments on commit 76dc69e

Please sign in to comment.