Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Possible to monitor and pseudo-lock per-app volume?


  • Please log in to reply
12 replies to this topic
  • Guests
  • Last active:
  • Joined: --
Some apps seem to think they know better than me what volume they should be set at.

What I'm looking to do is to have a script that monitors the windows 7 per-app volume of these apps and when the app annoyingly sets them to full volume, my script resets them down to their proper level.

I did some searching but all I found were these enormous volume guis. I was hoping for something a bit smaller in scale with no need for a gui.

any thoughts?

nomissenrojb
  • Members
  • 67 posts
  • Last active: May 08 2014 11:56 AM
  • Joined: 08 Nov 2009
Sorry that is not possible at all.
The only thing applications in Windows have access to is the channels. Mic, Speaker, Line-in and so on.
I have searched google thin with no luck.
Maby in Windows 8.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
It is possible in Windows 7.
; Requirements:
;   VA 2.1 - http://www.autohotkey.com/forum/topic23792.html
;   Windows 7
;   AutoHotkey_L
;   Luck?

IID_IAudioSessionManager2 := "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}"
IID_ISimpleAudioVolume := "{87CE5498-68D6-44E5-9215-6DA47EF883D8}"

dev := VA_GetDevice()
if !dev
    throw "Can't get device"
if VA_IMMDevice_Activate(dev, IID_IAudioSessionManager2, 7, 0, mgr) != 0
    throw "Can't get session manager"
ObjRelease(dev)
if VA_IAudioSessionManager2_GetSessionEnumerator(mgr, enm) != 0
    throw "Can't get session enumerator"
ObjRelease(mgr)
VA_IAudioSessionEnumerator_GetCount(enm, count)
Loop % count
{
    ; IAudioSessionControl *session;
    VA_IAudioSessionEnumerator_GetSession(enm, A_Index-1, ssn)
    VA_IAudioSessionControl_GetDisplayName(ssn, name)
    VA_IAudioSessionControl2_GetProcessId(ssn, pid)
    sav := ComObjQuery(ssn, IID_ISimpleAudioVolume)
    ObjRelease(ssn)
    if !sav ; Unlikely?
        throw "Can't get volume control"
    VA_ISimpleAudioVolume_GetMasterVolume(sav, volume)
    MsgBox %name%`nPID: %pid%`nVolume: %volume%
    ObjRelease(sav)
}
ObjRelease(enm)


;
; ISimpleAudioVolume -- currently not included in VA.ahk
;
VA_ISimpleAudioVolume_SetMasterVolume(this, Level, EventContext) {
    return DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), "uint", this, "float", Level, "uint", VA_GUID(EventContext))
}
VA_ISimpleAudioVolume_GetMasterVolume(this, ByRef Level) {
    return DllCall(NumGet(NumGet(this+0)+4*A_PtrSize), "uint", this, "float*", Level)
}
VA_ISimpleAudioVolume_SetMute(this, Mute, EventContext) {
    return DllCall(NumGet(NumGet(this+0)+5*A_PtrSize), "uint", this, "int", Mute, "uint", VA_GUID(EventContext))
}
VA_ISimpleAudioVolume_GetMute(this, ByRef Mute) {
    return DllCall(NumGet(NumGet(this+0)+6*A_PtrSize), "uint", this, "int*", Mute)
}
If you have the requirements, it should show the name (or the location of a string resource containing the name), PID and volume of each audio session. Currently on my system, it shows:
@%SystemRoot%\System32\AudioSrv.Dll,-202
PID: 0
Volume: 0.207792
---------------------------
Mozilla Firefox
PID: 3624
Volume: 1.000000
The first one is System Sounds. It is set to "10%", but shows 0.2 because the values returned by ISimpleAudioVolume are on a different curve to what the Windows' audio mixer shows.

In theory, it is also possible to listen for volume changes, but I don't have enough interest to write an example or explain in detail. It involves manually constructing an IAudioSessionEvents interface and passing it to IAudioSessionControl::RegisterAudioSessionNotification.

Instead, you can probably just keep the ISimpleAudioVolume pointer (sav) and retrieve the volume every so often (depending on when your app changes its volume, I guess).

  • Guests
  • Last active:
  • Joined: --
Many thanks, usefull info.

EN1
  • Guests
  • Last active:
  • Joined: --
Thanks Lexikos. Tried you piece of code (have all the requirements, except luck). It successfully loops through the elements shown in the mixer, but encountered the following problems:

(i) the names are empty (except for the first)
(ii) the volumes are all 0.000, although they should not be
(iii) when I call the GetMute function, it practically reduces the volume of the particular sav to zero.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I have fixed the code to work on x64. If you have a 64-bit version of AutoHotkey_L, get the new VA_ISimpleAudioVolume_ functions and try again.

I also get some unnamed sessions. All of the programs I would expect to appear in the list are in the list and are named.

EN1
  • Guests
  • Last active:
  • Joined: --
works great, names are not an issue.
Thanks!

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

I have fixed the code to work on x64.

Not quite.
return DllCall(NumGet(NumGet(this+0)+3*A_PtrSize), [color=red]"uint"[/color], this, "float", Level, [color=#F0F]"uint"[/color], VA_GUID(EventContext))
The red part (and possibly the pink part too) should be "ptr".

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
It doesn't make any difference either way.

No_Speak_Eng
  • Members
  • 6 posts
  • Last active: Oct 25 2013 10:33 AM
  • Joined: 22 Apr 2013
Thank Lexikos!
Turned out very easy control:

Spoiler


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

Thank Lexikos!
Turned out very easy control:

Spoiler

 

 

Thanks, that code was useful for me!



Shandy
  • Members
  • 1 posts
  • Last active: Aug 20 2013 08:50 PM
  • Joined: 10 Aug 2013

Can someone make a tutorial for this, Im unskilled, but i just want to change individually change sound for skype and google chrome, please help :)



vsemken
  • Members
  • 7 posts
  • Last active: Oct 15 2014 06:41 PM
  • Joined: 19 Jul 2013

So here's my working code for the application volume control. It includes some corrections necessary for the correct parameters for the DLLCall. Please mind, this is part of one of my larger projects, so it uses a lot more "infrastructure" than might be required. On the other hand you can study this code or even better have a working application to start with. It requires the Vista Audio Control libary available here http://www.autohotke...rol-functions/.

 

It works by pressing the Shift-VolumeUp/Down or Shift-Win-PageUp/Down key while an application is active, that has a control in the mixer. So have the Chrome or Skype window active (both not tested) and press the key. If the Explorer is active, it controls the System Sounds. It also controls the master volume if you don't press the shift key.

 

One problem I faced was that the active application might not be the one, that has the control registered in the mixer. For example Firefox uses a sub process for the Flash plugin and if you control Firefox, the Flash process should be controlled as well. That is where the button Configure Apps comes in. It allows to define the master application and the associated sub processes. There are already examples for Firefox and Internet Explorer included and the list can be extended.

 

 

Spoiler