New to Using Libraries, Not Understanding How Vista Audio Control Functions works
Posted: 07 Jun 2019, 22:30
Hey guys, I am pretty new to making scripts and programs, this is the first time I have imported a library of functions before and i'm pretty sure i'm understanding what the various functions are supposed to be doing, but i'm not getting the values I expect when testing some out, even basic ones.
I'm using the code from this Github archive of the library, https://github.com/Masonjar13/AHK-Library/blob/master/Required-Libraries/VA.ahk
So something simple I would try would be something like this:
With that I figured it would return the name of my Head-phones that are plugged in or something, maybe a number, but it is only returning a blank message box. I looked at the function that had a lot of commands I did not understand and the use of a lot of registry and addresses and such, but I can't really see why it would return nothing at all.
I also tried this function:
Which is returning 0, which if I am looking at the function correctly, means something is wrong and it got caught before running the rest.
No clue what:
means, i'm guessing the numbers are addresses in Windows memory? It seems like i'm not giving the right values though, since it's not running the rest, but I don't really know what to give it.
The only functions that made sense to me and gave me a number I expected were under "Master Controls" and just for finding audio volume, muting, setting audio volume, and giving amount of channels.
My current project i'm trying to get the audio levels that are coming to my audio output device, so I can make decisions in my program based on if there is sound coming through the head-phones, but i'm not really understanding what these functions are asking for exactly and how to interpret the addresses and such. I have also not done much object oriented stuff thus far just fyi. Thanks a lot for any help.
I'm using the code from this Github archive of the library, https://github.com/Masonjar13/AHK-Library/blob/master/Required-Libraries/VA.ahk
So something simple I would try would be something like this:
Code: Select all
device := VA_GetDeviceName("Speakers")
MsgBox % device
I also tried this function:
Code: Select all
Device := VA_GetDevice(device_desc="playback")
MsgBox % Device
Code: Select all
; device_desc = device_id
; | ( friendly_name | 'playback' | 'capture' ) [ ':' index ]
VA_GetDevice(device_desc="playback")
{
static CLSID_MMDeviceEnumerator := "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
, IID_IMMDeviceEnumerator := "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
if !(deviceEnumerator := ComObjCreate(CLSID_MMDeviceEnumerator, IID_IMMDeviceEnumerator))
return 0
device := 0
if VA_IMMDeviceEnumerator_GetDevice(deviceEnumerator, device_desc, device) = 0
goto VA_GetDevice_Return
if device_desc is integer
{
m2 := device_desc
if m2 >= 4096 ; Probably a device pointer, passed here indirectly via VA_GetAudioMeter or such.
{
ObjAddRef(device := m2)
goto VA_GetDevice_Return
}
}
else
RegExMatch(device_desc, "(.*?)\s*(?::(\d+))?$", m)
if m1 in playback,p
m1 := "", flow := 0 ; eRender
else if m1 in capture,c
m1 := "", flow := 1 ; eCapture
else if (m1 . m2) = "" ; no name or number specified
m1 := "", flow := 0 ; eRender (default)
else
flow := 2 ; eAll
if (m1 . m2) = "" ; no name or number (maybe "playback" or "capture")
{
VA_IMMDeviceEnumerator_GetDefaultAudioEndpoint(deviceEnumerator, flow, 0, device)
goto VA_GetDevice_Return
}
VA_IMMDeviceEnumerator_EnumAudioEndpoints(deviceEnumerator, flow, 1, devices)
if m1 =
{
VA_IMMDeviceCollection_Item(devices, m2-1, device)
goto VA_GetDevice_Return
}
VA_IMMDeviceCollection_GetCount(devices, count)
index := 0
Loop % count
if VA_IMMDeviceCollection_Item(devices, A_Index-1, device) = 0
if InStr(VA_GetDeviceName(device), m1) && (m2 = "" || ++index = m2)
goto VA_GetDevice_Return
else
ObjRelease(device), device:=0
VA_GetDevice_Return:
ObjRelease(deviceEnumerator)
if devices
ObjRelease(devices)
return device ; may be 0
}
Code: Select all
CLSID_MMDeviceEnumerator := "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
, IID_IMMDeviceEnumerator := "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
The only functions that made sense to me and gave me a number I expected were under "Master Controls" and just for finding audio volume, muting, setting audio volume, and giving amount of channels.
My current project i'm trying to get the audio levels that are coming to my audio output device, so I can make decisions in my program based on if there is sound coming through the head-phones, but i'm not really understanding what these functions are asking for exactly and how to interpret the addresses and such. I have also not done much object oriented stuff thus far just fyi. Thanks a lot for any help.