Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Vista Audio Control Functions


  • Please log in to reply
182 replies to this topic
Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Apparently I'm missing something ...

Create a Lib folder and put VA.ahk into it.

<!-- m -->http://www.autohotke...nctions.htm#lib<!-- m -->

stevenospam
  • Members
  • 8 posts
  • Last active: Dec 25 2010 11:06 PM
  • Joined: 23 Dec 2010
I created the Lib directory and moved VA.ahk into it. The error message is the same.
I am running Vista. AHK is installed in c:\program files\AutoHotkey. There are two subdirectories compile and Lib. topology.ahk is in \program files\autohotkey\. Autohotkey runs as a normal program e.g. not in XP compatibility mode. The topology script still fails at the
COM_CoInitialize() instruction.

stevenospam
  • Members
  • 8 posts
  • Last active: Dec 25 2010 11:06 PM
  • Joined: 23 Dec 2010
I got this working. In case someone else has the same problem:
I reinstalled AutoHotkey_L but selected ANSI instead of UNICODE. I also installed the ANSI version of COM.AHK into the Lib directory. Now it works!

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
FYI, the topology script is extremely outdated. It does not support the Unicode build. VA.ahk itself (v2.1) supports the Unicode build and does not require COM.ahk.

stevenospam
  • Members
  • 8 posts
  • Last active: Dec 25 2010 11:06 PM
  • Joined: 23 Dec 2010
Ah ha. I'll reinstall to support Unicode then.

kalia
  • Members
  • 2 posts
  • Last active: Dec 30 2010 08:49 AM
  • Joined: 30 Dec 2010
I am trying to change a mixer volume level in Windows 7 x64 and got stuck. I don't want to change the master volume, but the volume of a second sound card. I need help.

I am using Vista Audio Control Functions v2.1. If I run the following script:

While (dev := VA_GetDevice("playback:" A_Index)) 
{ 
    devlist .= A_Index ": " VA_GetDeviceName(dev) "`n"
} 
 
MsgBox %devlist%

I get the following result:

<!-- m -->http://img192.images...0/topologyq.jpg<!-- m -->

Now if i use the following script to get the master volume:

dev := VA_GetDevice("playback:7")
devname := VA_GetDeviceName(dev)
volume := VA_GetVolume("","",dev)
MsgBox %volume%

I get the master volume level. But if I try to get the volume level of any other playback device, no value is returned.

From reading the VA documentation, I understand that this probably has something to do with subunit's, but I cannot figure out how to go about finding those values.

Can anyone help? Thanks.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Please note that VA_GetVolume("") does not retrieve the master volume: it retrieves the volume of the first subunit. In some cases the effect is the same, but not all. My system has two "devices" for the digital outputs - these have no volume subunits whatsoever, so only VA_GetMasterVolume(device) will work for them.

Which device are you trying to control and how would you change the volume by hand? On the Levels tab of the audio device's Properties, the box at the top controls master volume and any boxes below it control subunits. In my experience, the controls shown on the Levels tab have been in the same order and had the same names as the volume subunits, but this might not always be the case.

Note that "volume of a second sound card" amounts to "the master volume of device 2". For instance, VA_GetMasterVolume("", 2).

If you need the subunit names, use the revised topology script which I just uploaded. You could use a numeric index instead, but then you'd either need to know the order they're in or experiment to figure out which is which.

kalia
  • Members
  • 2 posts
  • Last active: Dec 30 2010 08:49 AM
  • Joined: 30 Dec 2010
Thank you very much for the response Lexikos.

Please note that VA_GetVolume("") does not retrieve the master volume: it retrieves the volume of the first subunit. In some cases the effect is the same, but not all. My system has two "devices" for the digital outputs - these have no volume subunits whatsoever, so only VA_GetMasterVolume(device) will work for them.


VA_GetMasterVolume worked. I have 2 Audigy Z sound cards (plus the onboard sound). I am using kx drivers with the Audigy cards to separate each output as a stereo channel. I was able to control the separate channels (Wave 2/3, Wave 4/5,Wave 6/7,) through the windows mixer, but no other volume control programs would recognize these channels in Windows 7 (x64).

Also, thank you for uploading the revised topology script.

I wasted a lot of time with VA_GetVolume("") and subunits. I should have asked for help earlier. Now I can spend some time to compile an .exe with parameters to control the volume of the separate channels (from what I have read, it should be possible - I hope).

Thank you again.

Donls
  • Guests
  • Last active:
  • Joined: --
I am running Win 7 32, with all available updates , and need to be able to manipulate sound card settings. I have the latest download available of AutoHotKey(L).

I got Topology2 and the VA. When I run topology I get this error message:

---------------------------
topology2.ahk
---------------------------
Error in #include file "C:\Users\User\Documents\AutoHotkey\Lib\VA.ahk": Call to nonexistent function.

Specifically: ObjRelease(aev)

Line#
006: {
007: if ! aev := VA_GetAudioEndpointVolume(device_desc)
008: Return
009: if channel =
010: VA_IAudioEndpointVolume_GetMasterVolumeLevelScalar(aev, vol)
011: Else
012: VA_IAudioEndpointVolume_GetChannelVolumeLevelScalar(aev, channel-1, vol)
---> 013: ObjRelease(aev)
014: Return,Round(vol*100,3)
015: }
018: {
019: vol := vol>100 ? 100 : vol<0 ? 0 : vol
020: if ! aev := VA_GetAudioEndpointVolume(device_desc)
021: Return
022: if channel =

The program will exit.
---------------------------
OK
---------------------------

I swear I haven't messed with anything!!!

What do I do?

Donls
  • Guests
  • Last active:
  • Joined: --
I reinstalled AutoHotKey_L, I had installed an older copy of AutoHotKey after I had installed the L version.

Works fine now :)

Pio
  • Members
  • 19 posts
  • Last active: Feb 27 2011 07:32 PM
  • Joined: 13 Jan 2011
Hi I'm just starting with AHK but I like it a lot already! I tried to patch your script to my needs and partially it's working.
my goals are, beside the "basic" master volume control, a control of the subwoofer. i wanted to decrease the volume in 4 steps and then let it go back to 100%. it's not possible to mute the subwoofer (realtek soundchip), but 0% is fine, too. i got it working, but the gui is just grey with an empty windows under it, when i use the subwoofer, but no error message atm ;)
so thats the code, hope its not to messy...
;Volume Control v1.10 for Windows7
;by Filipe Novais

;====================================================================================================================
;Options ============================================================================================================
;====================================================================================================================
Volume_Increments_general = 2		;Volume increments for keyboard default "Vol+" "Vol-" keys
Volume_Increments_mouse = 3		;Volume increments for mouse wheel gestures "up" "down"
Visible_Duration = 1800			;Duration of Volume Control display (milliseconds)



;====================================================================================================================
;Startup ============================================================================================================
;====================================================================================================================
#Include *i VA.ahk
Volume_Increments = %Volume_Increments_general%
OnMessage(0x1001,"VC_ReceiveMessage")
	Gui 29: show, hide, Volume Control - message receiver
Menu, Tray, Icon, Shell32.dll, 169 				; Square Speaker Icon
;Menu, Tray, Icon, %SystemRoot%\system32\Mmsys.cpl,1   	 	; Standard Speaker Icon



;====================================================================================================================
;Volume OSD Background ==============================================================================================
;====================================================================================================================
Gui, 27: +AlwaysOnTop +ToolWindow -caption +LastFound
WinSet, Region, 0-0 W602 H59
Gui, 27: Color, FFFF00
Gui, 27: Add, Picture, w602 h59 x0 y0, %A_ScriptDir%\Pictures\Background.png
WinSet, TransColor, FFFF00 255



;====================================================================================================================
;Volume OSD Bars and Speakers =======================================================================================
;====================================================================================================================
Gui, 28: +AlwaysOnTop +ToolWindow -caption +LastFound
WinSet, Region, 0-0 W602 H59
Gui, 28: Color, FFFF00
WinSet, TransColor, FFFF00 255
Gui, 28: Add, Picture, w81 h59 x0 y0 gMute_On_Off vMuteOff, %A_ScriptDir%\Pictures\SpeakerSound.png
Gui, 28: Add, Picture, w81 h59 x0 y0 gMute_On_Off vMuteOn, %A_ScriptDir%\Pictures\SpeakerMute.png
startp = 83
Loop 100
	{
	Gui, 28: Add, Picture, vBF%A_Index% w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Full.png
	Gui, 28: Add, Picture, vBE%A_Index% w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Empty.png
	startp += 5
	}
return


Gui, 29: +AlwaysOnTop +ToolWindow -caption +LastFound
WinSet, Region, 0-0 W602 H59
Gui, 29: Color, FFFF00
WinSet, TransColor, FFFF00 255
Gui, 29: Add, Picture, w81 h59 x0 y0 gSub vSubOff, %A_ScriptDir%\Pictures\SpeakerSound_Sub.png
Gui, 29: Add, Picture, w81 h59 x0 y0 gSub vSubOn, %A_ScriptDir%\Pictures\SpeakerMute_Sub.png
startp = 83
Loop 100
	{
	Gui, 29: Add, Picture, vBF%A_Index% w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Full.png
	Gui, 29: Add, Picture, vBE%A_Index% w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Empty.png
	startp += 5
	}
return
;====================================================================================================================
;Hotkeys ============================================================================================================
;====================================================================================================================

						
$Volume_Up::					;Keyboard default "Vol+" key
Gosub, Up_Volume 
return

$Volume_down::					;Keyboard default "Vol-" key
Gosub, Down_Volume
return

$Volume_Mute::					;Keyboard default Mute/Unmute key
Gosub, Mute_On_Off
return

^R::						;Keyboard Sub key (red button)
;$Volume_Mute::					
Gosub, Sub
return

;====================================================================================================================
;Labels =============================================================================================================
;====================================================================================================================


Up_Volume:
volume_level := VA_GetMasterVolume()
volume_level += %Volume_Increments%
VA_SetMasterVolume(volume_level)
Gosub, Volume_Bar_Update
return


Down_Volume:
volume_level := VA_GetMasterVolume()
volume_level -= %Volume_Increments%
VA_SetMasterVolume(volume_level)
Gosub, Volume_Bar_Update
return

Sub:
volume_level_Sub := VA_GetVolume("Subwoofer")
volume_level_Sub -= 25
VA_SetVolume(volume_level_Sub, "Subwoofer")
if VA_GetVolume("Subwoofer") = 0
	{
	VA_SetVolume(100, "Subwoofer")
;	Gosub, Volume_Bar_Update2_Sub
	}
Gosub, Volume_Bar_Update_Sub
return

Volume_Bar_Update:
If WinActive("FullScreenBottomLayout")
fullscreen=1
volume_level := VA_GetMasterVolume()
SetTimer, Volume_Bar_Hide, off
Loop %volume_level%
	{
	GuiControl,28: Hide, BE%A_Index%
	GuiCOntrol,28: Show, BF%A_Index%
	}
volume_level2 := 100 - volume_level
Loop %volume_level2%
	{
	index := 101 - A_Index
	GuiCOntrol,28: Hide, BF%index%
	GuiControl,28: Show, BE%index%
	}
Volume_Bar_Update2:
if VA_GetMasterMute()
	{
	GuiControl,28: Show, MuteOn
	GuiCOntrol,28: Hide, MuteOff
	}
else
	{
	GuiControl,28: Show, MuteOff
	GuiCOntrol,28: Hide, MuteOn
	}
gosub, Show_Background
Gui, 28: Show, xCenter yCenter w602 h95
SetTimer, Volume_Bar_Hide, %Visible_Duration%
return


Volume_Bar_Update_Sub:
If WinActive("FullScreenBottomLayout")
fullscreen=1
volume_level_Sub := VA_GetVolume("Subwoofer")
SetTimer, Volume_Bar_Hide, off
Loop %volume_level_Sub%
	{
	GuiControl,29: Hide, BE%A_Index%
	GuiCOntrol,29: Show, BF%A_Index%
	}
volume_level2_Sub := 100 - volume_level_Sub
Loop %volume_level2_Sub%
	{
	index := 101 - A_Index
	GuiCOntrol,29: Hide, BF%index%
	GuiControl,29: Show, BE%index%
	}
Volume_Bar_Update2_Sub:
if VA_GetVolume("Subwoofer")
	{
	GuiControl,29: Show, MuteOn
	GuiCOntrol,29: Hide, MuteOff
	}
else
	{
	GuiControl,29: Show, MuteOff
	GuiCOntrol,29: Hide, MuteOn
	}
gosub, Show_Background
Gui, 29: Show, xCenter yCenter w602 h95
SetTimer, Volume_Bar_Hide, %Visible_Duration%
return

Volume_Bar_Hide:
SetTimer, Volume_Bar_Hide, off
Gui, 28: Hide
Gui, 29: Hide
Gui, 27: Hide
Background_Vis=0
if fullscreen=1
	{
	sleep 300
	fullscreen=0
	WinActivate, Windows Media Player
	send, !{ENTER}
	}
return


Show_Background:
If %Background_Vis%
return
Gui, 27: Show, xCenter yCenter w602 h95
Background_Vis=1
return


Volume_Bar_Click:
Gui_Bar_To_Volume=% A_GuiControl
StringTrimLeft, volume_level, Gui_Bar_To_Volume, 2
VA_SetMasterVolume(volume_level)
Gosub, Volume_Bar_Update
return


Mute_On_Off:
if VA_GetMasterMute()
	{
	VA_SetMasterMute(false)
	Gosub, Volume_Bar_Update2
	}
else
	{
	VA_SetMasterMute(true)
	Gosub, Volume_Bar_Update2
	}
return


Volume_Mouse_on:
Volume_Increments = %Volume_Increments_mouse%
return


Volume_Mouse_off:
Volume_Increments = %Volume_Increments_general%
return


;====================================================================================================================
;Messages ===========================================================================================================
;====================================================================================================================


VC_ReceiveMessage(Message) 
	{
	if Message = 01				; Volume increase with mouse wheel gesture
		{
		Gosub, Volume_Mouse_on
		Gosub, Up_Volume
		Gosub, Volume_Mouse_off
		return
		}

	else if Message = 02			; Volume decrease with mouse wheel gesture
		{
		Gosub, Volume_Mouse_on
		Gosub, Down_Volume
		Gosub, Volume_Mouse_off
		return
		}

	else if Message = 03    		; Mute/Unmute
		Gosub, Mute_On_Off

	else if Message = 04    		; show Volume Control
		Gosub, Volume_Bar_Update

	else if Message = 05     		; Volume Control Reload script   
		Reload
	}
return


;====================================================================================================================
;====================================================================================================================
;================================================== Control Example =================================================
;====================================================================================================================
;====================================================================================================================


MButton::
If WinActive("Volume Control.ahk")
	{
	PostMessage("Volume Control - message receiver",03)
	return
	}
StartTime := A_TickCount
KeyWait, MButton
if (A_TickCount - StartTime < 500)
	{
	MouseGetPos, xpos, ypos
	MouseClick, Middle,  xpos, ypos
	return
	}
else
	{
	PostMessage("Volume Control - message receiver",04)
	return
	}
return


wheelup::
If WinActive("Volume Control.ahk")
	{
	PostMessage("Volume Control - message receiver",01)
	return
	}
send {wheelup}
return 


wheeldown::  
If WinActive("Volume Control.ahk")
	{
	PostMessage("Volume Control - message receiver",02)
	return
	}
send {wheelDown}
return


PostMessage(Receiver,Message) {
	oldTMM := A_TitleMatchMode
	oldDHW := A_DetectHiddenWindows
	SetTitleMatchMode, 3
	DetectHiddenWindows, on
	PostMessage, 0x1001,%Message%,,,%Receiver% ahk_class AutoHotkeyGUI
	SetTitleMatchMode, %oldTMM%
	DetectHiddenWindows, %oldDHW%
}
return

the other thing: i would like to have the muted image of the subwoofer, but as i said, it cant be muted so the only way is to use a d-tour. i tried something with
Volume_Bar_Update2:
if VA_GetVolume(0, "Subwoofer")
	{
	GuiControl,28: Show, MuteOn
	GuiCOntrol,28: Hide, MuteOff
	}
but it didn't work. well, maybe its fixed when the "normal" subwoofer gui is fixed, but maybe you'll know the answer...

thanks a lot in advance and thanks for the great script!

pio

Pio
  • Members
  • 19 posts
  • Last active: Feb 27 2011 07:32 PM
  • Joined: 13 Jan 2011
Noone? I know, it's a lot to read, but most of it is just the original file...

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Did you have a specific problem you needed help with? If it's not specifically a function of VA, you should post in Ask for Help.

Pio
  • Members
  • 19 posts
  • Last active: Feb 27 2011 07:32 PM
  • Joined: 13 Jan 2011
Well, I thought its best to post here as this is directly related to va. I must say I'm not a prgrammer, so I just tried to adopt things from the Volume Control.ahk
My biggest problem is that the gui isn't working for the subwoofer. I tried to create a second gui similar to yours, just with another grphics (subwoofer icon instead the normal one, I can upload them if needed), named as shown in the code. the master volume is working, but the gui for the subwoofer doesn't show correctly. I tried a few things, but unfortunately I can't see the problem:
Posted Image
When this is solved (this is secondary and I can try on my own at first), I try to make the gui look like the subwoofer is muted when it's at 0% (as said, there is no such function to mute the sub).
Thanks, Pio

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Let me rephrase: If you are having a problem calling a VA_..() function, post here and say specifically what the problem is. Otherwise, your problem is not directly related to VA, so if I don't have an abundance of free time I'll just ignore your post. If you post in Ask for Help, it's likely that one or more of the many other users of this forum will help you.

As it happens, there are two basic errors in your script that have nothing to do with VA. The first I noticed is this:
Gui, 29: Add, Picture, v[color=red]BF%A_Index%[/color] w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Full.png
   Gui, 29: Add, Picture, v[color=red]BE%A_Index%[/color] w5 h29 x%startp% y15 gVolume_Bar_Click, %A_ScriptDir%\Pictures\Empty.png
These variables have already been used by the other GUI. You must use different variable names. This got me thinking "why isn't it throwing a great big warning sign in the author's face?" The answer is your second error:
...
return ; Nothing after this line will execute.


Gui, 29: +AlwaysOnTop +ToolWindow -caption +LastFound
...
See The Top of the Script (the Auto-execute Section).

If you need further help, please post in Ask for Help.