; adapted from DanyFirex and xMatz code #include <GuiConstants.au3> #include <Constants.au3> Global Const $S_OK = 0 Global Enum $eRender, $eCapture 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 $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _ "GetMeteringChannelCount hresult(dword*);" & _ "GetChannelsPeakValues hresult(dword;float*);" & _ "QueryHardwareSupport hresult(dword*);" Global $oAudioMeterInformation = _MicVolObject() If Not IsObj($oAudioMeterInformation) Then Exit MsgBox ($MB_SYSTEMMODAL,"Error","Unable to mic audio meter") Global $hGUI = GUICreate("", 80, 300, -1, -1, $WS_BORDER + $WS_POPUP) Global $hControl = GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL) AdlibRegister("_LevelMeter", 45) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd AdlibUnRegister() Func _LevelMeter() Local $iPeak If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then $iCurrentRead = 100 * $iPeak GUICtrlSetData($hControl, $iCurrentRead) If $iCurrentRead Then ConsoleWrite($iCurrentRead & @CRLF) EndIf EndFunc ;==>_LevelMeter Func _MicVolObject() Local Const $CLSCTX_INPROC_SERVER = 0x1 Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then Return SetError(1, 0, 0) Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eCapture, $eConsole, $pDefaultDevice) If Not $pDefaultDevice Then Return SetError(2, 0, 0) Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice) If Not IsObj($oDefaultDevice) Then Return SetError(3, 0, 0) Local $pAudioMeterInformation $oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation) If Not $pAudioMeterInformation Then Return SetError(4, 0, 0) Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation) EndFunc ;==>_MicVolObject; adapted from DanyFirex and xMatz code #include <GuiConstants.au3> #include <Constants.au3> Global Const $S_OK = 0 Global Enum $eRender, $eCapture 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 $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _ "GetMeteringChannelCount hresult(dword*);" & _ "GetChannelsPeakValues hresult(dword;float*);" & _ "QueryHardwareSupport hresult(dword*);" Global $oAudioMeterInformation = _MicVolObject() If Not IsObj($oAudioMeterInformation) Then Exit MsgBox ($MB_SYSTEMMODAL,"Error","Unable to mic audio meter") Global $hGUI = GUICreate("", 80, 300, -1, -1, $WS_BORDER + $WS_POPUP) Global $hControl = GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL) AdlibRegister("_LevelMeter", 45) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd AdlibUnRegister() Func _LevelMeter() Local $iPeak If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then $iCurrentRead = 100 * $iPeak GUICtrlSetData($hControl, $iCurrentRead) If $iCurrentRead Then ConsoleWrite($iCurrentRead & @CRLF) EndIf EndFunc ;==>_LevelMeter Func _MicVolObject() Local Const $CLSCTX_INPROC_SERVER = 0x1 Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then Return SetError(1, 0, 0) Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eCapture, $eConsole, $pDefaultDevice) If Not $pDefaultDevice Then Return SetError(2, 0, 0) Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice) If Not IsObj($oDefaultDevice) Then Return SetError(3, 0, 0) Local $pAudioMeterInformation $oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation) If Not $pAudioMeterInformation Then Return SetError(4, 0, 0) Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation) EndFunc ;==>_MicVolObject; adapted from DanyFirex and xMatz code #include <GuiConstants.au3> #include <Constants.au3> Global Const $S_OK = 0 Global Enum $eRender, $eCapture 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 $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _ "GetMeteringChannelCount hresult(dword*);" & _ "GetChannelsPeakValues hresult(dword;float*);" & _ "QueryHardwareSupport hresult(dword*);" Global $oAudioMeterInformation = _MicVolObject() If Not IsObj($oAudioMeterInformation) Then Exit MsgBox ($MB_SYSTEMMODAL,"Error","Unable to mic audio meter") Global $hGUI = GUICreate("", 80, 300, -1, -1, $WS_BORDER + $WS_POPUP) Global $hControl = GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL) AdlibRegister("_LevelMeter", 45) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd AdlibUnRegister() Func _LevelMeter() Local $iPeak If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then $iCurrentRead = 100 * $iPeak GUICtrlSetData($hControl, $iCurrentRead) If $iCurrentRead Then ConsoleWrite($iCurrentRead & @CRLF) EndIf EndFunc ;==>_LevelMeter Func _MicVolObject() Local Const $CLSCTX_INPROC_SERVER = 0x1 Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then Return SetError(1, 0, 0) Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eCapture, $eConsole, $pDefaultDevice) If Not $pDefaultDevice Then Return SetError(2, 0, 0) Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice) If Not IsObj($oDefaultDevice) Then Return SetError(3, 0, 0) Local $pAudioMeterInformation $oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation) If Not $pAudioMeterInformation Then Return SetError(4, 0, 0) Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation) EndFunc ;==>_MicVolObject |