Jump to content

Master Loudness/Volume via Peak Meter (Windows 7, 64-bit)


Recommended Posts

Can anyone give me a clue on how to read the "Master loudness" of Windows 7 as shown in SndVol.exe's horizontal progressbars?

Posted Image(Small green / darkgrey progress value, not the sliders value!)

I tried to read the SndVol.exe's memory with success, but the values address seems to be changed everytime SndVol is started. (even pointer-scanning was useless, as the pointer seems to switch around to many other pointers...)

I've just found this (with some hints of our german forum): http://msdn.microsoft.com/en-us/library/dd316561%28VS.85%29.aspx

But i still can't translate the source to AutoIt.

Thanks for answers in advance,

Daniel

Edited by Nerdworld
Link to comment
Share on other sites

Its easy to understand, but i have limited experience with coding and stuff, im not the right guy to help.

You just gotta wait and do progress on your own, post progress and hope someone gets interested in your progress.

That usually works.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

I've made this, but $olist won't get an object.

Maybe someone can write the parameter for WrapperCreate (function list)?

#include <AutoItObject.au3>
Global $clsid = _AutoItObject_CLSIDFromString("{BCDE0395-E52F-467C-8E3D-C4579291692E}")
Global $iid = _AutoItObject_CLSIDFromString("{A95664D2-9614-4F35-A746-DE8DB63617E6}")
Global $plist
_AutoItObject_CoCreateInstance(DllStructGetPtr($clsid), 0, 1, DllStructGetPtr($iid), $plist)
Global $olist = _AutoItObject_WrapperCreate($plist, "GetPeakValue hresult();")
MsgBox(0, @error, $olist.GetPeakValue())
$olist = 0
Edited by Nerdworld
Link to comment
Share on other sites

You don't need AutoItObject for that.

#include <GuiConstants.au3>
#include <ProgressConstants.au3>
Global Const $S_OK = 0
;===============================================================================
#interface "IMMDeviceEnumerator"
Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
; Definition
Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
     "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
     "GetDevice hresult(wstr;ptr*);" & _
     "RegisterEndpointNotificationCallback hresult(ptr);" & _
     "UnregisterEndpointNotificationCallback hresult(ptr);"
;===============================================================================
;===============================================================================
#interface "IMMDevice"
Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
; Definition
Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _
     "OpenPropertyStore hresult(dword;ptr*);" & _
     "GetId hresult(ptr*);" & _
     "GetState hresult(dword*);"
;===============================================================================
;===============================================================================
#interface "IAudioMeterInformation"
Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}"
; Definition
Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _
     "GetMeteringChannelCount hresult(dword*);" & _
     "GetChannelsPeakValues hresult(dword;float*);" & _
     "QueryHardwareSupport hresult(dword*);"
;===============================================================================

Global $oAudioMeterInformation = _AudioVolObject()
If Not IsObj($oAudioMeterInformation) Then Exit -1 ; Will happen on non-supported systems
Global $hGUI
Global $hControl = _MakePeakMeterInWindow($hGUI)
; Register function to periodically update the progress control
AdlibRegister("_LevelMeter", 45)

GUISetState()
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
AdlibUnRegister()
; Bye, bye...

Func _MakePeakMeterInWindow($hWindow)
$hWindow = GUICreate("ABC", 150, 400)
Return GUICtrlCreateProgress(20, 70, 15, 200, $PBS_VERTICAL)
EndFunc
Func _LevelMeter()
Local $iPeak
If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then
     $iCurrentRead = 100 * $iPeak
     GUICtrlSetData($hControl, $iCurrentRead + 1)
     GUICtrlSetData($hControl, $iCurrentRead)
EndIf
EndFunc
Func _AudioVolObject()
; Sequences of code below are taken from the source of plugin written for AutoIt for setting master volume on Vista and above systems.
; Code was written by wraithdu in C++.
; MMDeviceEnumerator
Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then Return SetError(1, 0, 0)
Local Const $eRender = 0
Local Const $eConsole = 0
; DefaultAudioEndpoint
Local $pDefaultDevice
$oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice)
If Not $pDefaultDevice Then Return SetError(2, 0, 0)
; Turn that pointer into object
Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice)
Local Const $CLSCTX_INPROC_SERVER = 0x1
; AudioMeterInformation
Local $pAudioMeterInformation
$oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation)
If Not $pAudioMeterInformation Then Return SetError(3, 0, 0)
Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation)
EndFunc
Link to comment
Share on other sites

  • 2 months later...

I have been doing allot of searching on the forum lately, most in the example sections where i have gone though 150 pages ^^.

I came across many "Automatic sound" applications but they are outdated or only work for xp / vista (I have W7).

I ran your code and it does work very well but i was wondering if you could help me tweak it a little.

Could your code could show the "greyed" values ? My goal *Incase i have grabbed the wrong-end of the stick*. Is to read the volume and if its above a set amount "ie 0.80" then lower the system volume. If its below a set amount "ie 0.60" then raise it.

but when i run your current code if i increase or decrease the system volume it has no effect on the peak effect.

I do hope this would be possible, as i do like the idea of a automated sound script that stops music / videos playing too loudly or quietly.

Edited by IanN1990
Link to comment
Share on other sites

The gray bar is not a real sound level. It displays what the level would be if the channel volume slider were 100% of the Master volume slider. The green bar in the channel is the volume level based on the ratio of the channel slider to the master slider. That is why the master slider has no gray bar. So you need a bit more info, and that is the channel volume level (the slider level) so you can determine the ratio of that to the master volume level. Then it's just math. I'm not sure how you get access to that volume slider info though...

Edited by wraithdu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...