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
kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

@nugged

I realize this may be what you described you already saw, but this is the script I use after reading many of the same forum posts you have an I came to the conclusion this was the only way. It changes the tray icon to indicate which audio device you have enabled (You have to make your own icons or disable the icon switching lines of the code). I keep it in my startup folder so it is always on.

;runs at startup:
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
ControlClick,OK
if (!isEnabled)
    Menu, Tray, Icon, Headphones.ico
else
    Menu, Tray, Icon, Speakers.ico
return

#h::        ;Toggle headphones / speakers
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if (!isEnabled)
{
    ControlSend,SysListView321,{Down 1}
    Menu, Tray, Icon, Speakers.ico
}
else
    Menu, Tray, Icon, Headphones.ico
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
return


nugged
  • Members
  • 7 posts
  • Last active: Jun 19 2013 06:16 AM
  • Joined: 17 May 2012

But some tools like nircmd easily switches default sound output device, I doing now this from AHK by running nircmd.exe as external helper,

(like ....\nircmd.exe" setdefaultsounddevice "SPDIF Interface" )

I just thought make it more elegant, so AHK will do all itself through Windows API, so why I asked.


AHK_L / Windows 7 user.
Creator and maintainer of ladoshki.com / patent.km.ua

nugged
  • Members
  • 7 posts
  • Last active: Jun 19 2013 06:16 AM
  • Joined: 17 May 2012

2 Kon: thanks for example, anyway, currently I am on nircmd.exe setdefaultsounddevice "deviceName".

nircmd works well from command line.

I just need to name device by it's to-user-shown-name (flaw in nircmd if few devices with same names), okay for me, works well.


AHK_L / Windows 7 user.
Creator and maintainer of ladoshki.com / patent.km.ua

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I'm not aware of any documented Windows API to do it; my point was that Microsoft didn't make it easy, i.e. by documenting it the way they documented all of the APIs that VA.ahk uses.  Of course it can be done, since the Sound control panel does it.  Maybe there is a well documented API that I've overlooked; in that case, I'd like to know about it.

 

Edit: Here's the official word from Microsoft:

 

Applications cannot change the roles that are assigned to audio endpoint devices. The operating system allows only the user to assign device roles.
Source: Working with Device Roles


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I found an undocumented interface (thanks to Dave Amenta) which allows us to set the default audio endpoint, so I've updated VA.  Version 2.3 includes an additional function, VA_SetDefaultEndpoint, which accepts a device pointer or description and role to set the default for.  Example usage:

; Set the second playback device as the default for general use.
VA_SetDefaultEndpoint("playback:2", 0)

; Set the default communications devices to Microphone + Speakers.
VA_SetDefaultEndpoint("Microphone", 2)
VA_SetDefaultEndpoint("Speakers", 2)


nugged
  • Members
  • 7 posts
  • Last active: Jun 19 2013 06:16 AM
  • Joined: 17 May 2012

Wow great. Let's test...

Working. I need in my case name them:

 

VA_SetDefaultEndpoint("SPDIF Interface", 0)
or
VA_SetDefaultEndpoint("Speakers", 0)
 
as they named in my system  in "Endpoint" column of "Sound Card Analyzer v1.0" script window for VA lib.
 
THANK YOU for such quick reaction.
 
I hope now many users can switch from key-pressing emulation (as Kon posted above) to more straight way.
Despite that microsoft lazy to document that features :).

AHK_L / Windows 7 user.
Creator and maintainer of ladoshki.com / patent.km.ua

doveman
  • Members
  • 40 posts
  • Last active: Apr 09 2014 02:15 AM
  • Joined: 06 Dec 2011

Can anyone help me please?

 

I need to adjust my mic input volume, as for voice comms with TS3 I need it at 100% with boost +20db but Microsoft Speech Recognition (which I use for Voice Assisted Commands) reduces it to 14% at that boost. I can get it to leave it at 100% with boost +10db but then it's too quiet for TS3.

 

I've already got a script which sends F13 to trigger VAC when I press a mouse button, so I need to reduce the mic input volume to 14% when that's pressed and set it back to 100% when it's released.

 

I've tried the following but it returns "Mixer doesn't support this component type" which isn't very promising. I wouldn't mind having to use AHK to trigger another application if AHK can't adjust the mic level by itself.

SoundGet, MicVol, MICROPHONE, VOLUME, 1
if ErrorLevel
    MsgBox, Error Description: %ErrorLevel%
else
MsgBox, Microphone is currently %MicVol%.

EDIT: I've had better luck with

SoundSet, -82, Microphone, VOLUME, 6
if ErrorLevel
    MsgBox, Error Description: %ErrorLevel%

SoundGet, micvol, Microphone, VOLUME, 6
if ErrorLevel
    MsgBox, Error Description: %ErrorLevel%
else
MsgBox, Microphone is currently %micvol%

which returns "Microphone is currently 17.99" and no errors but it doesn't make any difference to the mic volume. The identify scripts clearly identify my Realtek Mic channels as mixer/device 6.



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

doveman, try changing the Master component of device 6 instead of the Microphone component (just omit "Microphone").



doveman
  • Members
  • 40 posts
  • Last active: Apr 09 2014 02:15 AM
  • Joined: 06 Dec 2011

doveman, try changing the Master component of device 6 instead of the Microphone component (just omit "Microphone").

 

Thanks but I tried

SoundSet, -82,, VOLUME, 6
if ErrorLevel
    MsgBox, Error Description: %ErrorLevel%

SoundGet, micvol,, VOLUME, 6
if ErrorLevel
MsgBox, Error Description: %ErrorLevel%
else
MsgBox, Microphone is currently %micvol%

and just get "Mixer doesn't support this component type" twice.



eugenevorld
  • Members
  • 47 posts
  • Last active: Nov 11 2014 09:09 AM
  • Joined: 28 Jul 2013

I tried having a tweak at the script so that I could get the PKEY_AudioEndpoint_FormFactor of the device but I didn't have much luck. I think it might have something to do with the vt member being VT_U14. I was able to change the functions slightly to get PKEY_DeviceInterface_FriendlyName and PKEY_Device_DeviceDesc since, I'm guessing, they had the vt member being VT_LPWSTR which was the same to the function I slightly edited which was GetDeviceName(). Could someone help me find a way to get it to work with getting the PKEY_AudioEndpoint_FormFactor?



GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009

Mute other apps in Win7+

 

Maybe Lexikos should have looked harder?

 

I got this working by emailing Nir Sofer (Owner of NirSoft and author of NirCMD). He linked me to a stackoverflow page in C# saying how to do it, but the vital piece I lacked was typecasting (The stackoverflow page used "as" to typecast the IAudioSessionControl to an ISimpleAudioVolume instance). After a bit more searching and trying all sorts of things, I found another stackoverflow page that said you needed to call QueryInterface on the IASC to get the ISAV. It worked, and now I am blissfully muting individual apps (as well as being able to control their values).

 

Spoiler


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

 

What's with the attitude?  At the time I posted, I hadn't yet perfected my ability to see into the future.

 

I posted on 17 July 2010.  The stackoverflow questions you linked to were posted on 13 Jan 2013 and 20 May 2011.



GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009

What's with the attitude?  At the time I posted, I hadn't yet perfected my ability to see into the future.

 

I posted on 17 July 2010.  The stackoverflow questions you linked to were posted on 13 Jan 2013 and 20 May 2011.

 

Sorry if I came across with attitude, because that's not really how I meant it (The internet does strange things to tone of voice and whatnot).  Your ability to predict the future *is* pretty good, however, probably not good enough to predict those particular pages.  Perhaps you should go to a psychic tutor?

 

The reason I said that (although I do see how badly it could be misinterpreted) was because I had spent the last 3 days working on it, and was ecstatic when I got it working, despite the supposed impossibility.

 

When I later googled "Mute IAudioSessionControl" in your time frame, it came up with only one page that actually had the answer on it (it tells how to mute an IAudioSessionControl in a similar method to SndVol). I see that your resources 3 years ago were not as plentiful or helpful as the ones floating around now.

 

I greatly respect you and your work, and was excited when I accomplished something that you had not; it in no way diminishes the value your work has in my code.

 

Should I/how would I properly notify the user(s) who have asked about adjusting individual application volume?



Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

...

Should I/how would I properly notify the user(s) who have asked about adjusting individual application volume?

I am interested in this, and would gladly help to test it, if required. I recommend you make a post regarding it within the scripts subforum.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


Iceman93
  • Members
  • 4 posts
  • Last active: Oct 22 2014 09:08 AM
  • Joined: 07 Aug 2014

Can anyone help with memory usage of the Vista Audio functions?

 

Each successive call to a VA function seems to allocate more memory to the process, rather than reusing the memory already allocated.

 

I have a long running script that ends up using more than a gigabyte of RAM when left to it's own devices.

 

How can I free the memory used?