Jump to content

audio volume info from an app


Moi
 Share

Recommended Posts

Then you'll have to give more information on what 'app' this is. "player.exe" is not very helpful. Have you tried anything? Do you have any code that you've written already to try and change or get the volume? Are looking just to get what it's currently set to, or set it as well? Are you looking to get it without interaction, or do you care if things are 'clicked' on the program? There's a lot of questions and you haven't given too much information yet.

Also, just to be clear for the post that I linked, it's not the overall Windows system sound that it's changing, it's changing the sounds levels for a specific program, like you would in the Volume Mixer manually per program.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Do you want to read the application sound control, or the real sound level produced by the application ?

All answers you got so far is about the first case.  If you want to achieve the second case, there is a number of threads discussing sound level (interface approach).

Link to comment
Share on other sites

i find this but i'ts windows sound and i want just an app

#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", 80, 300)
    Return GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL)
EndFunc   ;==>_MakePeakMeterInWindow

Func AudioValueRetrieve()
    Do
    Local $iPeak2
    $oAudioMeterInformation.GetPeakValue($iPeak2)
    $iCurrentRead2 = 100 * $iPeak2
    Until $iCurrentRead2 = 1
    If $iCurrentRead2 = 1 Then
    MsgBox("0","Oversound","Oversound",0)
    EndIf
EndFunc

Func _LevelMeter()
    Local $iPeak
    If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then
        $iCurrentRead = 100 * $iPeak
        GUICtrlSetData($hControl, $iCurrentRead + 1)
        GUICtrlSetData($hControl, $iCurrentRead)
    EndIf
EndFunc   ;==>_LevelMeter

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   ;==>_AudioVolObject

 

Link to comment
Share on other sites

I have this code where it gets peak value from all processes :

#include <WinAPICom.au3>
#include <Process.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)

Global Const $CLSCTX_INPROC_SERVER = 0x01 + 0x02 + 0x04 + 0x10 ; equals to $CLSCTX_ALL
Global Enum $eRender, $eCapture, $eAll
Global Enum $AudioSessionStateInactive, $AudioSessionStateActive, $AudioSessionStateExpired
Global Enum $eConsole, $eMultimedia, $eCommunications

Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $sTagIMMDeviceEnumerator = _
    "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
    "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
    "GetDevice hresult(wstr;ptr*);" & _
    "RegisterEndpointNotificationCallback hresult(ptr);" & _
    "UnregisterEndpointNotificationCallback hresult(ptr)"

Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}"
Global Const $sTagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _
    "GetMeteringChannelCount hresult(dword*);" & _
    "GetChannelsPeakValues hresult(dword;float*);" & _
    "QueryHardwareSupport hresult(dword*);"

Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $sTagIMMDevice = _
    "Activate hresult(clsid;dword;ptr;ptr*);" & _
    "OpenPropertyStore hresult(dword;ptr*);" & _
    "GetId hresult(wstr*);" & _
    "GetState hresult(dword*)"

Global Const $sIID_IAudioSessionManager2 = "{77aa99a0-1bd6-484f-8bc7-2c654c9a9b6f}"
Global Const $sTagIAudioSessionManager = "GetAudioSessionControl hresult(ptr;dword;ptr*);" & _
    "GetSimpleAudioVolume hresult(ptr;dword;ptr*);"
Global Const $sTagIAudioSessionManager2 = $sTagIAudioSessionManager & "GetSessionEnumerator hresult(ptr*);" & _
    "RegisterSessionNotification hresult(ptr);" & _
    "UnregisterSessionNotification hresult(ptr);" & _
    "RegisterDuckNotification hresult(wstr;ptr);" & _
    "UnregisterDuckNotification hresult(ptr)"

Global Const $sIID_IAudioSessionEnumerator = "{e2f5bb11-0570-40ca-acdd-3aa01277dee8}"
Global Const $sTagIAudioSessionEnumerator = "GetCount hresult(int*);GetSession hresult(int;ptr*)"

Global Const $sIID_IAudioSessionControl = "{f4b1a599-7266-4319-a8ca-e70acb11e8cd}"
Global Const $sTagIAudioSessionControl = "GetState hresult(int*);GetDisplayName hresult(wstr*);" & _
    "SetDisplayName hresult(wstr);GetIconPath hresult(wstr*);" & _
    "SetIconPath hresult(wstr;ptr);GetGroupingParam hresult(ptr*);" & _
    "SetGroupingParam hresult(ptr;ptr);RegisterAudioSessionNotification hresult(ptr);" & _
    "UnregisterAudioSessionNotification hresult(ptr);"

Global Const $sIID_IAudioSessionControl2 = "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
Global Const $sTagIAudioSessionControl2 = $sTagIAudioSessionControl & "GetSessionIdentifier hresult(wstr*);" & _
    "GetSessionInstanceIdentifier hresult(wstr*);" & _
    "GetProcessId hresult(dword*);IsSystemSoundsSession hresult();" & _
    "SetDuckingPreferences hresult(bool);"

HotKeySet("{ESC}", "_Exit")

Local $aApp = 0
While True
  $aApp = _GetAppsPlayingSound()
  If IsArray($aApp) Then
    For $i = 0 To UBound($aApp) - 1
      ConsoleWrite($aApp[$i][0] & "/" & $aApp[$i][1] & @CRLF)
    Next
  EndIf
  Sleep(100)
WEnd

Func _Exit()
  Exit
EndFunc   ;==>_Exit

Func _GetAppsPlayingSound()
  Local $oErrorHandler = 0
  $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

  Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $sTagIMMDeviceEnumerator)
  If Not IsObj($oMMDeviceEnumerator) Then Exit MsgBox ($MB_SYSTEMMODAL, "Error", "MMDeviceEnumerator")

  Local $pIMMDevice, $oMMDevice
  $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eMultimedia, $pIMMDevice)
  $oMMDevice = ObjCreateInterface($pIMMDevice, $sIID_IMMDevice, $sTagIMMDevice)
  If Not IsObj($oMMDevice) Then Exit MsgBox ($MB_SYSTEMMODAL, "Error", "MMDevice")

  Local $pIAudioSessionManager2, $oIAudioSessionManager2
  $oMMDevice.Activate($sIID_IAudioSessionManager2, $CLSCTX_INPROC_SERVER, 0, $pIAudioSessionManager2)
  $oIAudioSessionManager2 = ObjCreateInterface($pIAudioSessionManager2, $sIID_IAudioSessionManager2, $sTagIAudioSessionManager2)
  If Not IsObj($oMMDevice) Then Exit MsgBox ($MB_SYSTEMMODAL, "Error", "AudioSessionManager2")

  Local $pIAudioSessionEnumerator, $oIAudioSessionEnumerator, $nSessions
  $oIAudioSessionManager2.GetSessionEnumerator($pIAudioSessionEnumerator)
  $oIAudioSessionEnumerator = ObjCreateInterface($pIAudioSessionEnumerator, $sIID_IAudioSessionEnumerator, $sTagIAudioSessionEnumerator)
  If Not IsObj($oMMDevice) Then Exit MsgBox ($MB_SYSTEMMODAL, "Error", "AudioSessionEnumerator")
  $oIAudioSessionEnumerator.GetCount($nSessions)

  Local $aApp[0], $pIAudioSessionControl2, $oIAudioSessionControl2, $oIAudioMeterInformation
  Local $ProcessID, $fPeakValue, $iState, $iVolume
  For $i = 0 To $nSessions - 1
    $oIAudioSessionEnumerator.GetSession($i, $pIAudioSessionControl2)
    $oIAudioSessionControl2 = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioSessionControl2, $sTagIAudioSessionControl2)
    $oIAudioSessionControl2.GetState($iState)
    If $iState = $AudioSessionStateActive Then
      $oIAudioSessionControl2.GetProcessId($ProcessID)
      $oIAudioMeterInformation = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioMeterInformation, $sTagIAudioMeterInformation)
      $oIAudioSessionControl2.AddRef()
      $oIAudioMeterInformation.GetPeakValue($fPeakValue)
      ConsoleWrite($fPeakValue & @CRLF)

      If Int($fPeakValue*100) > 0 Then
        ReDim $aApp[UBound($aApp) + 1][2]
        $aApp[UBound($aApp) - 1][0] = _ProcessGetName($ProcessID)
        ConsoleWrite($ProcessID & @CRLF)

        $aApp[UBound($aApp) - 1][1] = Round($fPeakValue*100, 1)
      EndIf
    EndIf
  Next

  If UBound($aApp) = 0 Then $aApp = 0
  Return $aApp
EndFunc   ;==>_GetAppsPlayingSound

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
  ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
      @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
      @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
      @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
      @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
      @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
      @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
      @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
      @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
      @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

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...