1- using NAudio . CoreAudioApi ;
2- using System ;
1+ using System ;
32using System . Collections . Generic ;
43using System . Diagnostics ;
54using System . Linq ;
65using System . Text ;
76using System . Threading . Tasks ;
7+ using AudioSwitcher . AudioApi ;
8+ using AudioSwitcher . AudioApi . CoreAudio ;
89
910namespace WinAudioAssistant . Models
1011{
@@ -25,7 +26,7 @@ public enum EndpointFormFactor
2526
2627 public struct AudioEndpointInfo
2728 {
28- public readonly DataFlow DataFlow { get ; }
29+ public readonly DeviceType DataFlow { get ; }
2930 public readonly Guid AudioEndpoint_GUID { get ; } // Globally unique to this endpoint
3031 public DeviceState ? DeviceState { get ; private set ; }
3132 public EndpointFormFactor ? AudioEndpoint_FormFactor { get ; private set ; } // Speakers, headphones, headset, SPDIF, etc.
@@ -34,15 +35,15 @@ public struct AudioEndpointInfo
3435 public string ? Device_DeviceDesc { get ; private set ; } // The endpoint's name, which can be changed in the control panel
3536 public string ? DeviceClass_IconPath { get ; private set ; }
3637 public string ? DeviceInterface_FriendlyName { get ; private set ; } // Set by the driver, but may have a different value if there are duplicate devices
37- public string ? HostDeviceDesc { get ; private set ; } // (Actual property name unkown) Appears to be the name of the host device. Usually same as DeviceInterface_FriendlyName.
38+ public string ? HostDeviceDesc { get ; private set ; } // (Actual property name unkown) Appears to be the name of the host device. Usually same as DeviceInterface_FriendlyName, but more consistent .
3839
39- public readonly string ID => ( DataFlow == DataFlow . Render ? "{0.0.0.00000000}.{" : "{0.0.1.00000000}.{" ) + AudioEndpoint_GUID . ToString ( ) + "}" ;
40+ public readonly string ID => ( DataFlow == DeviceType . Playback ? "{0.0.0.00000000}.{" : "{0.0.1.00000000}.{" ) + AudioEndpoint_GUID . ToString ( ) + "}" ;
4041
4142 /// <summary>
4243 /// Use named arguments for optional parameters. The order of arguments may change in the future.
4344 /// </summary>
4445 /// <remarks>Test remark.</remarks>
45- public AudioEndpointInfo ( DataFlow dataFlow ,
46+ public AudioEndpointInfo ( DeviceType dataFlow ,
4647 Guid audioEndpoint_GUID ,
4748 EndpointFormFactor ? audioEndpoint_FormFactor = null ,
4849 Guid ? audioEndpoint_JackSubType = null ,
@@ -52,7 +53,7 @@ public AudioEndpointInfo(DataFlow dataFlow,
5253 string ? deviceInterface_FriendlyName = null ,
5354 string ? hostDeviceDesc = null )
5455 {
55- Trace . Assert ( dataFlow != DataFlow . All , "AudioEndpointInfo created with DataFlow .All" ) ;
56+ Trace . Assert ( dataFlow != DeviceType . All , "AudioEndpointInfo created with DeviceType .All" ) ;
5657 DataFlow = dataFlow ;
5758 AudioEndpoint_GUID = audioEndpoint_GUID ;
5859 AudioEndpoint_FormFactor = audioEndpoint_FormFactor ;
@@ -63,18 +64,11 @@ public AudioEndpointInfo(DataFlow dataFlow,
6364 DeviceInterface_FriendlyName = deviceInterface_FriendlyName ;
6465 HostDeviceDesc = hostDeviceDesc ;
6566 }
66- public AudioEndpointInfo ( MMDevice device )
67+ public AudioEndpointInfo ( CoreAudioDevice device )
6768 {
68- Trace . Assert ( device . DataFlow != DataFlow . All , "AudioEndpointInfo created with DataFlow.All" ) ;
69- DataFlow = device . DataFlow ;
70- if ( Guid . TryParse ( device . Properties [ propertyKeys . AudioEndpoint_GUID ] ? . Value as string , out var guid ) )
71- {
72- AudioEndpoint_GUID = guid ;
73- }
74- else
75- {
76- AudioEndpoint_GUID = Guid . Empty ;
77- }
69+ Trace . Assert ( device . DeviceType != DeviceType . All , "AudioEndpointInfo created with DeviceType.All" ) ;
70+ DataFlow = device . DeviceType ;
71+ AudioEndpoint_GUID = device . Id ;
7872 Debug . Assert ( AudioEndpoint_GUID != Guid . Empty , "AudioEndpointInfo created with empty GUID" ) ;
7973 UpdateFromDevice ( device ) ;
8074 }
@@ -85,8 +79,8 @@ public AudioEndpointInfo(MMDevice device)
8579 /// <returns>True if a matching endpoint was found in the system.</returns>
8680 public bool UpdateFromSystem ( )
8781 {
88- var device = new MMDeviceEnumerator ( ) . GetDevice ( ID ) ;
89- if ( device ? . Properties [ propertyKeys . AudioEndpoint_GUID ] ? . Value is Guid guid && guid == AudioEndpoint_GUID )
82+ var device = App . CoreAudioController . GetDevice ( AudioEndpoint_GUID ) ;
83+ if ( device ? . Properties [ propertyKeys . AudioEndpoint_GUID ] is Guid guid && guid == AudioEndpoint_GUID )
9084 {
9185 UpdateFromDevice ( device ) ;
9286 return true ;
@@ -97,23 +91,23 @@ public bool UpdateFromSystem()
9791 }
9892 }
9993
100- public void UpdateFromDevice ( MMDevice device )
94+ public void UpdateFromDevice ( CoreAudioDevice device )
10195 {
10296 DeviceState = device . State ;
103- if ( device . Properties [ propertyKeys . AudioEndpoint_FormFactor ] ? . Value is uint formFactor )
97+ if ( device . Properties [ propertyKeys . AudioEndpoint_FormFactor ] is uint formFactor )
10498 AudioEndpoint_FormFactor = ( EndpointFormFactor ) formFactor ;
105- if ( Guid . TryParse ( device . Properties [ propertyKeys . AudioEndpoint_JackSubType ] ? . Value as string , out var jackSubType ) )
99+ if ( Guid . TryParse ( device . Properties [ propertyKeys . AudioEndpoint_JackSubType ] as string , out var jackSubType ) )
106100 AudioEndpoint_JackSubType = jackSubType ;
107- if ( device . Properties [ propertyKeys . Device_ContainerId ] ? . Value is Guid containerId &&
101+ if ( device . Properties [ propertyKeys . Device_ContainerId ] is Guid containerId &&
108102 containerId != new Guid ( 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ) )
109103 Device_ContainerId = containerId ;
110- if ( device . Properties [ propertyKeys . Device_DeviceDesc ] ? . Value is string deviceDesc )
104+ if ( device . Properties [ propertyKeys . Device_DeviceDesc ] is string deviceDesc )
111105 Device_DeviceDesc = deviceDesc ;
112- if ( device . Properties [ propertyKeys . DeviceClass_IconPath ] ? . Value is string iconPath )
106+ if ( device . Properties [ propertyKeys . DeviceClass_IconPath ] is string iconPath )
113107 DeviceClass_IconPath = iconPath ;
114- if ( device . Properties [ propertyKeys . DeviceInterface_FriendlyName ] ? . Value is string friendlyName )
108+ if ( device . Properties [ propertyKeys . DeviceInterface_FriendlyName ] is string friendlyName )
115109 DeviceInterface_FriendlyName = friendlyName ;
116- if ( device . Properties [ propertyKeys . Device_DeviceDesc ] ? . Value is string hostDeviceDesc )
110+ if ( device . Properties [ propertyKeys . Device_DeviceDesc ] is string hostDeviceDesc )
117111 HostDeviceDesc = hostDeviceDesc ;
118112 }
119113
0 commit comments