soundDetect3.au3 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #Include <string.au3> ; for _StringRepeat function
  2. #Include <GUIConstants.au3> ; GUI !
  3. Dim $lpszDevice ; Identifier of an MCI device or device driver.
  4. Dim $lpszDeviceID ; Identifier of an MCI device.
  5. ; This identifier or alias is assigned when the device is opened.
  6. Dim $lpszOpenFlags ; Flag that identifies what to initialize.
  7. Dim $lpszRequest ; Flag for requesting status information. See table on the web page mentioned above.
  8. ; Source: http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_the_wait_notify_and_test_flags.asp
  9. Dim $lpszFlags ; Can be "wait", "notify", or both.
  10. ; For digital-video and VCR devices, "test" can also be specified.
  11. Dim $lpszCommand ; mciCommand string to send.
  12. Dim $lpszReturnString ; information will be returned into this string. Reserve enough space!
  13. Dim $cchReturn ; Length of returnstring
  14. Dim $mciError ; mci error code
  15. ; STEP 1: Open the device we want to monitor
  16. ; Source: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_open.asp
  17. ;$lpszDevice = "waveaudio"
  18. $lpszDevice = "new type waveaudio"
  19. $lpszOpenFlags = "alias mywave" ; For all possible flags, see table on web page mentioned above.
  20. $lpszFlags = ""
  21. $lpszCommand = StringFormat( "open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags );
  22. $lpszReturnString = _StringRepeat( " ", 100 ) ; Information will return in this string
  23. $cchReturn = StringLen($lpszReturnString)
  24. ; Size, in characters, of the return buffer specified
  25. ; by the lpszReturnString parameter.
  26. $mciError = _mciSendString( $lpszCommand, $lpszReturnString, $cchReturn, 0);
  27. if $mciError[0] <> 0 then _mciShowError($mcierror[0])
  28. ; STEP 2: Obtain the audio levels
  29. ; Source: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_status_mm.asp
  30. $lpszDeviceID = "mywave"
  31. $lpszRequest = "level" ; Returns the current PCM audio sample value.
  32. ; See table on web page mentioned above.
  33. $lpszFlags = ""
  34. $lpszCommand= StringFormat( "status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags );
  35. ; Before we collect the information, first create a nice GUI.
  36. GUICreate("MCI wave level test",200,130) ; This will create a centered dialog box
  37. $VolumeLabel=GUICtrlCreateLabel ("Initializing..." , 14, 8, 200, 20)
  38. $ProgressBar = GUICtrlCreateProgress (14,25,180,20)
  39. $ExitButton =GUICtrlCreateButton (" Exit ",80,60)
  40. GUISetState () ; Display the dialog
  41. ; Run the GUI until the dialog is closed
  42. While 1
  43. $mciError = _mciSendString( $lpszCommand, $lpszReturnString, $cchReturn, 0);
  44. if $mciError[0] <> 0 then _mciShowError($mcierror[0])
  45. ; The average input signal level is returned.
  46. ; The left-channel value is in the high-order word and the right-
  47. ; or mono-channel value is in the low-order word.
  48. ; The input level is represented as an unsigned value.
  49. ; For 8-bit samples, this value is in the range 0 through 127 (0x7F).
  50. ; For 16-bit samples, it is in the range 0 through 32,767 (0x7FFF).
  51. GUICtrlSetData ($VolumeLabel, $mcierror[2])
  52. GUICtrlSetData ($ProgressBar,$mcierror[2])
  53. $msg = GUIGetMsg()
  54. Select
  55. case $msg = $Exitbutton
  56. Exit
  57. case $msg = $GUI_EVENT_CLOSE
  58. Exit
  59. EndSelect
  60. Wend
  61. GUIDelete()
  62. exit
  63. ; USER DEFINED FUNCTIONS
  64. Func _mciSendString( $lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
  65. ;VB-style declaration:
  66. ;
  67. ;Declare Function mciSendString
  68. ; Lib "winmm.dll"
  69. ; Alias "mciSendStringA"
  70. ; (ByVal lpstrCommand As String,
  71. ; ByVal lpstrReturnString As String,
  72. ; ByVal uReturnLength As Long,
  73. ; ByVal hwndCallback As Long)
  74. ; As Long
  75. ; mciSendString returns information in the lpszReturnString parameter of mciSendString.
  76. ; The information is dependent on the request type.
  77. Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
  78. EndFunc
  79. Func _mciShowError($mcierror)
  80. ; To show a "readable" mci error.
  81. ;
  82. ;VB-style declaration:
  83. ;
  84. ;Declare Function mciGetErrorString
  85. ; Lib "winmm.dll"
  86. ; Alias "mciGetErrorStringA"
  87. ; (ByVal dwError As Long,
  88. ; ByVal lpstrBuffer As String,
  89. ; ByVal uLength As Long)
  90. ; As Long
  91. Dim $errStr ; Error message
  92. $errStr=_StringRepeat( " ", 100 ) ; Reserve some space for the error message
  93. $Result=DllCall("winmm.dll","long", "mciGetErrorStringA", "long", $mcierror, "string", $errStr, "long", StringLen($errStr))
  94. MsgBox (0,"MCI test", "MCI Error Number " & $mcierror & ":" & $Result[2] )
  95. EndFunc