Jump to content
Sign in to follow this  
i2i8

Fix the microphone test software

Recommended Posts

i2i8

Here a script that is used to test the microphone:

#Include <string.au3>
#Include <GUIConstants.au3>
#include <misc.au3>
$dot = False
$bg = 0x222222
$graph = 0xFFFFFF
Opt( "GUIOnEventMode", 1 )
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError
$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat( "open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat( " ", 100)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat( "status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags);
$Form1 = GUICreate("Mic-Test", 281, 197, 193, 115)
$box = GuiCtrlCreateGraphic(0, 8, 281, 107)
GUICtrlSetBkColor(-1,$bg)
GUICtrlSetColor(-1,0)
GUICtrlSetGraphic( -1, $GUI_GR_MOVE, 0, 107/2)
GUICtrlSetGraphic( -1, $GUI_GR_LINE, 281, 107/2)
$marker = GuiCtrlCreateGraphic(0, 8, 1, 107)
GUICtrlSetBkColor(-1,0xFFFFFF)
$Button1 = GUICtrlCreateButton("Start", 0, 120, 89, 33, 0)
$Button2 = GUICtrlCreateButton("Stop", 96, 120, 89, 33, 0)
$Button3 = GUICtrlCreateButton("Clear", 192, 120, 89, 33, 0)
$Button4 = GUICtrlCreateButton("BG Color", 0, 160, 89, 33, 0)
$Button5 = GUICtrlCreateButton("Graph Color", 192, 160, 89, 33, 0)
$Button6 = GUICtrlCreateButton("Lines/Dots", 96, 160, 89, 33, 0)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent ( $Button1, "start" )
GUICtrlSetOnEvent ( $Button2, "stop" )
GUICtrlSetOnEvent ( $Button3, "clear" )
GUICtrlSetOnEvent ( $Button4, "graph_color" )
GUICtrlSetOnEvent ( $Button5, "bg_color" )
GUICtrlSetOnEvent ( $Button6, "toggle" )
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
$point = 0
$run = False
While 1
    If $run = True Then
        $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
        If $mciError[0] <> 0 Then _mciShowError($mciError[0])
        If $dot = True Then
            GUICtrlSetGraphic( $box, $GUI_GR_COLOR, $graph)
            GUICtrlSetGraphic( $box, $GUI_GR_DOT, $point, (107/2)+$mciError[2]/2 )
            GUICtrlSetGraphic( $box, $GUI_GR_DOT, $point, (107/2)-$mciError[2]/2 )
        Else
            GUICtrlSetGraphic( $box, $GUI_GR_MOVE, $point, 107/2)
            GUICtrlSetGraphic( $box, $GUI_GR_COLOR, $graph)
            GUICtrlSetGraphic( $box, $GUI_GR_LINE, $point, (107/2)+$mciError[2]/2 )
            GUICtrlSetGraphic( $box, $GUI_GR_LINE, $point, (107/2)-$mciError[2]/2 )
        EndIf
        $point = $point + 1
        If $point > 280 Then
            GUICtrlDelete( $box )
            GUICtrlDelete( $marker )
            $box = GuiCtrlCreateGraphic(0, 8, 281, 107)
            GUICtrlSetGraphic( -1, $GUI_GR_MOVE, 0, 107/2)
            GUICtrlSetGraphic( -1, $GUI_GR_COLOR, $graph)
            GUICtrlSetGraphic( -1, $GUI_GR_LINE, 281, 107/2)
            GUICtrlSetBkColor(-1,$bg)
            GUICtrlSetColor(-1,0)
            GUICtrlSetGraphic( -1, $GUI_GR_MOVE, 0, 107/2)
            GUICtrlSetGraphic( -1, $GUI_GR_COLOR, $graph)
            GUICtrlSetGraphic( -1, $GUI_GR_LINE, 281, 107/2)
            $marker = GuiCtrlCreateGraphic(0, 8, 3, 107)
            GUICtrlSetBkColor(-1,0xFFFFFF)
            $point = 0
            Sleep(10)
        EndIf
        GUICtrlSetPos ( $marker, $point, 8 )
    EndIf
    Sleep(10)
WEnd

Func bg_color()
    Global $bg = _ChooseColor(2, $bg, 2)
    GUICtrlSetBkColor($box,$bg)
EndFunc

Func graph_color()
    Global $graph = _ChooseColor(2, $graph, 2)
    GUICtrlSetBkColor($marker,$graph)
EndFunc

Func toggle()
    If $dot = False Then
        $dot = True
    Else
        $dot = False
    EndIf
EndFunc

Func start()
    $run = True
EndFunc

Func stop()
    $run = False
EndFunc

Func clear()
    GUICtrlDelete( $box )
    GUICtrlDelete( $marker )
    $box = GuiCtrlCreateGraphic(0, 8, 281, 107)
    GUICtrlSetBkColor(-1,$bg)
    GUICtrlSetColor(-1,0)
    GUICtrlSetGraphic( -1, $GUI_GR_MOVE, 0, 107/2)
    GUICtrlSetGraphic( -1, $GUI_GR_COLOR, $graph)
    GUICtrlSetGraphic( -1, $GUI_GR_LINE, 281, 107/2)
    $marker = GuiCtrlCreateGraphic(0, 8, 3, 107)
    GUICtrlSetBkColor(-1,$graph)
    $point = 0
EndFunc
    
Func SpecialEvents()
    Exit
EndFunc

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc   ;==>_mciSendString
Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat( " ", 100) ; Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
    MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc   ;==>_mciShowError

 

When I click on the Start button in the testing process, unplug the microphone, it will display this error:

Line 3019 (File "Mic-Test.exe");
Error:Subscript used on non-accessible variable.

When I did not plug in the microphone, mouse click the Start button, it will display this error:

Line 2980 (File "Mic-Test.exe");
Error:Variable used without being declared.

I am newer to learn AU3, please help me fix this script it, thank you very much

Share this post


Link to post
Share on other sites
TechCoder

 

When I click on the Start button in the testing process, unplug the microphone, it will display this error:

Line 3019 (File "Mic-Test.exe");
Error:Subscript used on non-accessible variable.

When I did not plug in the microphone, mouse click the Start button, it will display this error:

Line 2980 (File "Mic-Test.exe");
Error:Variable used without being declared.

I did not duplicate this error, though got it when clicking on the color-change buttons.

This is because you have your variables declared Global in the wrong place.  Try

; add Global to the TOP of the code
Global $bg = 0x222222
Global $graph = 0xFFFFFF


; REMOVE the Global from inside the functions
Func bg_color()
    $bg = _ChooseColor(2, $bg, 2)
    GUICtrlSetBkColor($box,$bg)
EndFunc

Func graph_color()
    $graph = _ChooseColor(2, $graph, 2)
    GUICtrlSetBkColor($marker,$graph)
EndFunc

That worked for me (btw, nice work - keep it up, you will get there!)

Share this post


Link to post
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
Sign in to follow this  

×