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
Pio
  • Members
  • 19 posts
  • Last active: Feb 27 2011 07:32 PM
  • Joined: 13 Jan 2011
Thanks you were able to get me nearer to a working script! I'll post the rest in the help section ;)
Pio

  • Guests
  • Last active:
  • Joined: --
Posted Image
(I reckon you can guess my name)

I've been working with VA.ahk, and now I've gone and changed something to make this pop up everytime I run my script. Any thoughts?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
A block somewhere in your script, perhaps near the end, is missing its ending brace (}). For example:
Func1() {
; } <-- missing
Func2() {  ; "Functions cannot contain functions."
}


  • Guests
  • Last active:
  • Joined: --

A block somewhere in your script, perhaps near the end, is missing its ending brace (}). For example:

Func1() {
; } <-- missing
Func2() {  ; "Functions cannot contain functions."
}

ah, so it was!
Thanks! With a reply that fast, I'd think this were instant messaging website :)

mario1776
  • Members
  • 18 posts
  • Last active: Nov 08 2015 08:45 PM
  • Joined: 27 Feb 2011
I am trying to run a script that would check if my Windows 7 laptop microphone is muted, and then mute the microphone if it is not already. I am getting Error: Call to nonexistent function. Specifically: VA_GetMasterMute("Microphone"). I am using AutoHotKey_L. The version I downloaded is AutoHotkey110000.zip. Is there something I need to do with AutoHotKeySC.bin?? Is there additional files that I need to install on my laptop? Am I using VA_GetMasterMute incorrectly? Do other particular files need to be running already for VA functions to work???
{
micMute := VA_GetMasterMute("Microphone")
if  micMute = false
    VA_SetMasterMute(true, "Microphone")
else
    VA_SetMasterMute(false, "Microphone")
}
return

EDIT: D'oh.
Reading the documentation on Libraries of Functions I found the line "path-to-the-currently-running-AutoHotkey.exe\Lib\ ; Standard library." After I put VA.ahk in to the appropriate Lib directory I stopped receiving the nonexistent function error. I also modified the code and got it working exactly as I wanted.
{
if VA_GetMasterMute("Microphone") = 0
    VA_SetMasterMute(1, "Microphone")
else
    VA_SetMasterMute(0, "Microphone")
}
return


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

I am trying to run a script that would check if my Windows 7 laptop microphone is muted, and then mute the microphone if it is not already. I am getting Error: Call to nonexistent function. Specifically: VA_GetMasterMute("Microphone"). I am using AutoHotKey_L. The version I downloaded is AutoHotkey110000.zip. Is there something I need to do with AutoHotKeySC.bin?? Is there additional files that I need to install on my laptop? Am I using VA_GetMasterMute incorrectly? Do other particular files need to be running already for VA functions to work???

{
micMute := VA_GetMasterMute("Microphone")
if  micMute = false
    VA_SetMasterMute(true, "Microphone")
else
    VA_SetMasterMute(false, "Microphone")
}
return


You might want to install the library linked in the first post of this topic. The library that has the actual function VA_GetMasterMute(). Include the function in your script, or get it working as a library (named VA.ahk, fex).

ULTRA
  • Members
  • 19 posts
  • Last active: Mar 11 2012 09:39 PM
  • Joined: 15 Feb 2005
Hi,

since Windows Vista/7 one can setup an audio output channel for each application separately. In software like Winamp, Skype, Teamspeak you can select to which audio device the sound should be sent. Is there a possibility to do the same for AHK?

What I try to achieve concretely is to set the AHK script's audio render device to either "Realtek Digital Output" or "AMD HDMI Output" and then have the "SoundPlay" function output music/sounds to the specified render device.

Does anybody see a chance on how to achieve that? Thank you very much in advance.
In a world without walls and fences who needs windows and gates?

dxcqcv
  • Members
  • 1 posts
  • Last active: Sep 04 2011 10:02 PM
  • Joined: 29 Aug 2011

hi!
sorry if this is to basic
but I just want to have a script that when you press "win"+"v" mute the sound of my computer running windows 7
I try with this script:

#v::
VA_SetMasterVolume(0)
return

the error I get is that VA doesn't exit
I copied the VA.ahk to the /lib/ directory under autohokey main path
any help wil be really appreciated
thanks!

I have the same problem
Would you tell me how to fix it
thanks

mhe
  • Members
  • 40 posts
  • Last active: Dec 04 2015 10:29 PM
  • Joined: 18 Oct 2007

Is it possible with application specific sound control in windows 7 with this script?

Lets say if you only want to mute the sound in a specific program, but let others stay the same volume.


It can be done with nircmd
setappvolume [Process] [volume level] {Device Name/Index}
changeappvolume [Process] [volume level] {Device Name/Index}
muteappvolume [Process] [mute mode] {Device Name/Index}

So maybe there is a chance it could get implemented in ahk in the future.

Lexikos, any news on this?

himanshu
  • Members
  • 95 posts
  • Last active: Jan 04 2013 03:35 PM
  • Joined: 18 Jul 2011
Awesome stuff Lexikos, thanks a ton, I had been banging against the wall with trying to get SoundGet to work correctly!

PEG
  • Members
  • 4 posts
  • Last active: Jan 27 2012 12:10 AM
  • Joined: 08 Jan 2012
So there is a new Audio WinAPI Vista-Core-Audio-API

Here's a tutorial on how to use them. With some help I think we can make this work for AHK too.

<!-- m -->http://www.codeproje... ... me-Control<!-- m -->

<!-- m -->http://whenimbored.x...-audio-for-net/<!-- m -->

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The script which is the topic of this thread is based entirely around the Vista Core Audio API... :roll:

PEG
  • Members
  • 4 posts
  • Last active: Jan 27 2012 12:10 AM
  • Joined: 08 Jan 2012

The script which is the topic of this thread is based entirely around the Vista Core Audio API... :roll:


Yeah, just me being a bit high from reading the API from msdn. I rly hadn't looked through VA properly yet. Still trying to wrap my brain around it all.

Trying to call IAudioSessionManager::GetSimpleAudioVolume. I want to get the guid for a session too. Not sure if I have to go through an IAudioClient::Initialize to get it.

also keeping tabs of every new audio session created, than keeping track of the Peak meters. Then I'd like to listen to events.

Just trying to find some samples to get the hang of things. Just isn't that much samples to go from. Only found your topology2.ahk for now.

Posted Image
It could be more informative, Overall. Hey at least there's something to work from. Some more examples (samples) would be great, if you got any.

Thanks for putting in the time.

LARK2355
  • Members
  • 9 posts
  • Last active: Sep 28 2013 06:59 AM
  • Joined: 02 Feb 2012
Thanks For the Sound Control Code.
It solved a Problem i had.
Here is a replacement for the 'Sound' in Control Panel using your Code:-
(i am sure it can be improved)
#include va.ahk

gosub main

return
GuiClose:
ExitApp
CPAudio:
Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`, ; use a number at end to select option 
Return
CPMixer:
Run ,sndvol
Return
main:

meter_display :="playback"
Gui,1:Default
gui,1:destroy
Menu, ShowMenu, Add, S&ound(windows), CPAudio
Menu, ShowMenu, Add, Volume M&ixer(windows), CPmixer
Menu, MyMenuBar, Add, &Show, :ShowMenu
Gui, Menu, MyMenuBar
Gui, Add, Text, x500 y1 w400 h340 hwndParent         
Gui, Add, Text, x1 y200 w300 h250 hwndParent2        
Gui,Add,Button,x5 y310 gGuiClose,EXIT
Gui,Add,Button,x330 y310 gMeterMain,Show Meter

Gui, Add, Tab2,x5 y5 w450 h170 bold cblue, Playback|Capture
inout1=playback
inout2=capture
index:=1
loop 2
	{
	inout:=inout%A_index%
if A_index=1
{
Gui, Tab,Playback  
}
if A_index=2
{
Gui, Tab,Capture 
}

inoutsav:=A_index
	loop 
		{

		deviceid := VA_GetDevice(inout  ":" A_index)
		if deviceid>0
			{
			devicename:=VA_GetDeviceName(deviceid)
			volume := VA_GetMasterVolume(A_index,devicename)
			label:=inout%inoutsav%
			muted := VA_GetMasterMute(label)
			mutes := VA_GetMasterMute(devicename)
			channels:=VA_GetChannelCount( "1",devicename)
			ObjRelease(deviceid)
s%index%:=A_index
l%index%:=label
c%index%:=channels
n%index%:=devicename
Gui,Add,Button,y+10 gDetails v%index%, %devicename% Channels (%channels%)
index+=1
			}
		else
			{
			break
			}
		}
	}
Gui,Tab
Gui, Color, 0xF5e2A0

Gui, Show,w480 h350,Audio
return
Details:
Gui,2:destroy
Gui,1:Default
index :=A_GuiControl
Dev_seq:=s%index%
Dev_type:=l%index%
no_of_channels:=c%index%
Dev_clicked:=n%index%
meter_display :=Dev_clicked
msg :=
loop 8
{
Vol_n%A_index%:=A_index
}
;default values
vol_n1=L 
vol_n2=R
if SubStr(Dev_clicked, 1 , 8) ="Speakers" ; AC97 Speakers names
{
vol_n1=L
vol_n2=R
vol_n3=C
vol_n4=Sub
vol_n5=RL
vol_n6=RR
vol_n7=SL
vol_n8=SR
}
if Dev_type = 2
{
vol_n1=Boost 
vol_n2=Reserved
}
label:=inout%Dev_type%
meter_inout:=inout%Dev_type%
Dev_mute:=VA_GetMasterMute(label)
if Dev_mute= 0
{
Gui, 2:Add,Button,x10 y10 w200 gmmute vDev_mute,  Mute %label% Default Device
}
else
{
Gui, 2:Add,Button,x10 y10 w200 gmmute vDev_mute,  unMute %label% Default Device
}
Mvol:= VA_GetMasterVolume(,inout%Dev_type%)
Gui, 2:Add, text,x10 y40 cblue,1
Gui, 2:Add, Slider,x+1 w100 y40 h30 vMvol Range1-100  ToolTip gSliderMove cblue, %Mvol%
Gui, 2:Add, text,x+1 y40 cblue,100 
label:=inout%Dev_type%
Seq_mute :=VA_GetMasterMute(Dev_clicked)
if Seq_mute  = 0
{
Gui, 2:Add,Button,x10 y65 gmmute vSeq_mute,  Mute %Dev_clicked%
}
else
{
if Seq_mute <>
{
Gui, 2:Add,Button,x10 y65 gmmute vSeq_mute,  unMute %Dev_clicked%
}
}
if no_of_channels >0
{
Dvol := VA_GetMasterVolume(, Dev_clicked) 
Gui, 2:Add, text,x10 y95 cblue,1
Gui, 2:Add, Slider,x+1 y95 w100 h30 vDvol Range1-100  ToolTip gSliderMove, %Dvol%
Gui, 2:Add, text,x+1 y95 cblue,100 
Gui, 2:Add, text, x10 y190 cblue,100
Gui, 2:Add, text, x10 y230 cblue,50
Gui, 2:Add, text,x10 y270 cblue,1
loop %no_of_channels%
{
xx:=A_index* 50
sp_dev:=vol_n%A_index%
Gui, 2:Add, text,x%xx% y160 cgreen,%sp_dev%
line_volume := VA_GetVolume(Dev_type,A_index, Dev_clicked)
Gui, 2:Add, Slider, x%xx% y180 w40 h100 invert  vertical vline_volume%A_index% Range1-100   gSliderMove, %line_volume%
}
}
Gui, 2:Add,Button,x10 y310  g2close, Close Volume Control
Gui,2:Add,Button,x200 y310 gMeter,Show Meter
Gui, 2:Color, 0xF5e2A0
Gui, 2:+Lastfound -Resize -caption -border
Gui,2:show,x1 y1 ,Child1
child1:= WinExist()

DllCall("SetParent", "UInt", child1, "Uint", parent)      ; set parent for child window 1
Gui, Show,w980 h350,Audio
return
SliderMove:
Gui, Submit, nohide
GuiControlGet, slid, FocusV 
slidval :=%slid%
StringRight, slidindex, slid, 1
StringLeft, slidwhich, slid, 1
if slidwhich=M
{
;msgbox adjust master
VA_SetMasterVolume(slidval,,inout%Dev_type%) 
}
if slidwhich=D 
{
;msgbox adjust master with sequence
VA_SetMasterVolume(slidval,, Dev_clicked) 
}
if slidwhich=l 
{
;msgbox adjust sub
VA_SetVolume(slidval,Dev_type,slidindex, Dev_clicked)
}
; need to refresh as one can afect others
Gui,2:destroy
gosub Details
return
mmute:
GuiControlGet, mute_this, FocusV 
; msgbox %mute_this% %Dev_type% ,%Dev_clicked%
label:=inout%Dev_type%
if mute_this=Dev_mute
{
if VA_GetMasterMute(label)
{
VA_SetMasterMute(0,label)
}
Else
{
VA_SetMasterMute(1,label)
}
}
else
{
if VA_GetMasterMute(Dev_clicked)
{
VA_SetMasterMute(0,Dev_clicked)
}
Else
{
VA_SetMasterMute(1,Dev_clicked)
}
}
Gui,2:destroy
gosub Details
return
2close:
Gui,2:destroy
gosub main
return
3close:
Gui,3:destroy
gosub main
return
MeterMain:
meter_display:="playback"
meter_inout:=inout1
Gui,2:destroy
Gui, Show,w480
Meter:
Gui,3:destroy
MeterLength = 30
audioMeter := VA_GetAudioMeter(meter_display)
VA_IAudioMeterInformation_GetMeteringChannelCount(audioMeter, channelCount)
Gui, 3:Add,Text,x10 y10, %meter_display% has %channelCount% Channels
if channelCount>0
{
loop %channelCount%
{
Gui,3:Add, Progress, w350 h10 cBlue vMyProgress%A_index%
}
Gui 3: -Caption -border
Gui, 3:Color, 0xF5e2A0
Gui, 3:+Lastfound -Resize -caption -border
Gui,3:show,x1 y1 ,Child2
child2:= WinExist()

DllCall("SetParent", "UInt", child2, "Uint", parent2)     
Gui, Show

VA_GetDevicePeriod(meter_display, devicePeriod)
Loop
{
VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue)    
meter := MakeMeter(peakValue, MeterLength)
VarSetCapacity(peakValues, channelCount*4)
VA_IAudioMeterInformation_GetChannelsPeakValues(audioMeter, channelCount, &peakValues)
Loop %channelCount%
{
which=MyProgress%A_index%
valmeter:=MakeMeter(NumGet(peakValues, A_Index*4-4, "float"), MeterLength) * 100
GuiControl,3:, %which%, %valmeter%
gui ,3:show,NoActivate,Audio Meter
sleep 50
}
}
MakeMeter(fraction, size)
{
return fraction
}
}
return



Skrollster
  • Guests
  • Last active:
  • Joined: --
I'v been looking quite much today after a script that can mute / unmute my microphone but not found one, but this thread atleast got me on the way

my code here utilize the volume up / down / mute keys in conjunction with ctrl, it only works for the second set of microphone (witch i wanted it to work for)
if VA_GetMasterMute("Microphone:2")
{
	menu, tray, icon, OFF.ico,,1
	}
else
{
	menu, tray, icon, ON.ico,,1
	}

^Volume_Mute::
;msgbox % VA_GetMute("2","Microphone:2")
;VA_SetMute(!VA_GetMute("1","Microphone:2"),"1","Microphone:2")
VA_SetMasterMute(!VA_GetMasterMute("Microphone:2"),"Microphone:2")
;msgbox % VA_GetMasterMute("Microphone:2")
CoordMode, ToolTip, Screen
if VA_GetMasterMute("Microphone:2")
{
	TrayTip, Microphone state changed, Microphone muted, 10, 1
	menu, tray, icon, OFF.ico,,1
	}
else
{
	TrayTip, Microphone state changed, Microphone unmuted, 10, 1
	menu, tray, icon, ON.ico,,1
	}
	return

^Volume_Up::	
vol_tmp := VA_GetVolume("1","","Microphone:2")
vol_Master := (vol_tmp + 5)
VA_SetVolume(vol_Master, "1" , "", "Microphone:2")
vol_new := VA_GetVolume("","","Microphone:2")
	TrayTip, Microphone state changed, "Microphone volume set to" %vol_new%, 10, 1
if VA_GetMasterMute("Microphone:2")
{
	menu, tray, icon, OFF.ico,,1
	}
else
{
	menu, tray, icon, ON.ico,,1
	}
return

^Volume_Down::
vol_tmp := VA_GetVolume("","","Microphone:2")
vol_Master := (vol_tmp - 5)
VA_SetVolume(vol_Master, "" , "", "Microphone:2")
vol_new := VA_GetVolume("","","Microphone:2")
	TrayTip, Microphone state changed, "Microphone volume set to" %vol_new%, 10, 1
if VA_GetMasterMute("Microphone:2")
{
	menu, tray, icon, OFF.ico,,1
	}
else
{
	menu, tray, icon, ON.ico,,1
	}
return
it might help someone else in the future.