I've been trying to get audio information using powershell 4.0, specifically the peak audio as sound plays. So I found a .Net wrapper for the core audio api (can be found here and the .dll is located in CoreAudio\bin) and have been trying to use that. However, for the life of me, I cannot figure out how to do so. The main problem is I have not been able to figure out the syntax for accessing and using the methods for the classes contained within the assembly. Specifically, I am trying to work with CoreAudio.AudioPeakMeter and CoreAudio.AudioMute.
CoreAudio.AudioPeakMeter, for example, should have two members, GetChannelCount and GetLevel.
I have tried using
[CoreAudio.AudioPeakMeter] | Get-Member -Static
but that only returns Equals and ReferenceEquals which is confirmed when I use
[CoreAudio.AudioPeakMeter]::
I even found a function someone had posted online for retrieving constructors. Again, this turned up nothing. As in literally nothing. No output is returned. I confirmed this works for others such as System.Windows.Thickness which was used an example on the post.
Here's the Get-Contstructor function I found if you are interested.
function get-Constructor ([type]$type, [Switch]$FullName)
{
foreach ($c in $type.GetConstructors())
{
$type.Name + "("
foreach ($p in $c.GetParameters())
{
if ($fullName)
{
"`t{0} {1}," -f $p.ParameterType.FullName, $p.Name
}else
{
"`t{0} {1}," -f $p.ParameterType.Name, $p.Name
}
}
")"
}
}
HOWEVER, I know GetChannelCount and GetLevel exist and can be found in ISE via
(New-Object CoreAudio.AudioPeakMeter).GetChannelCount
as well as using the command
[CoreAudio.AudioPeakMeter].GetMethods()
For ISE, after entering the period both GetChannelCount and GetLevel populate in the ISE list. But of course, since the initial issue is New-Object re an error on CoreAudio.AudioPeakMeter, powershell doesn't even attempt to access the two members.
The latter command returns this which I've posted to pastebin.
The method property IsSecurityCritical made me think I need to run powershell with elevated privileges. However, that does not seem to be the case as it made no difference.
I've confirmed that these results are the same for all of the classes in the assembly. I can access the enumerators though. Here's an example:
[enum]::GetNames([CoreAudio.DEVICE_STATE])
This will properly return all possible values of CoreAudio.DEVICE_STATE.
Is there something I'm missing? As far as I can tell the assembly is properly loaded (I used Add-Type) but powershell says the class methods do not exist even though they do.