Jump to content

PC Speaker Beep Player


FifthLobe
 Share

Recommended Posts

I wanted to make a script that would read .midi files, decipher the notes, and play pc speaker beeps for the respective tone/duration of each note, but I didn't figure it out (at least yet-- I'm a relative newbie)

Instead, I made a program that reads text files which I cleverly renamed .bpf files, short for beep file. It's basically a .txt that's been renamed and contains information for a series of beeps.

Here's the little bit of code that I put together:

; Beep Reader 1.0
; -----------------
; *.bpf files are plain text files with a renamed extension.
; 
; The file is comprised of segments, or blocks of beep data.
; Place a # character inbetween each segment, or use a new line each time.
; Segments that result in a beep sound are formatted: FREQUENCY,DURATION
;       eg. 6000,10
;       (resulting in a beep of 6000 Hz, lastin 10 milliseconds)
; Segments that result in a pause (a sleep) are formatted: *DURATION
;       eg. *2500
;       (resulting in a 2.5 second period of silence)
; 
; Here is a sample of what a valid *.bpf file might look like:
;           500,100#99,1000#*100#500,100
; 
; -----------------
; I spent some time making this, so don't just copy/paste
; it and claim it's yours, or else you'll make me feel bad
; when I find out.
; 
; Enjoy;-)

#include <array.au3>

HotKeySet('{ESC}', 'die'); ESC to quit

$filename = FileOpenDialog('Beep Reader', @DesktopDir, 'Beep Files (*.bpf)', 1+2)
If @error Then die()

$filehandle = FileOpen($filename, 0); 0 = read mode
If $filehandle = -1 Then die('Error opening file.' & @LF & $filename)

$rawdata = FileRead($filehandle)
If @error = 1 Then die('Error reading file.' & @LF & $filename)

$rawdata = StringReplace( StringReplace( StringReplace($rawdata, @CR, '#'), @LF, '#'), ' ', ''); Clean up carriage returns, line feeds and spaces

$beepdata = StringSplit($rawdata, '#')

For $i=1 To UBound($beepdata)-1
    If StringLeft($beepdata[$i], 1) = '*' Then
        Sleep( StringRight($beepdata[$i],StringLen($beepdata[$i])-1) )
    Else
        $data = StringSplit($beepdata[$i], ',')
;~      If $data[0] > 2 Then die('Fault in .bpf data.' & @LF & 'File: ' & $filename & @LF & 'Data: ' & $beepdata); Syntax error reporting
        If $data[1] <> '' Then Beep($data[1], $data[2]); Beep, but ignore stray #'s with no data inbetween
    EndIf
Next


Func die($error='')
    If StringLen($error) > 0 Then MsgBox(16, 'Error', $error)
    Exit
EndFunc

I know there are a few places online which list what frequency corresponds to which note in MIDI files or in music. (I don't know much about musical notes and the like.) I think it'd be cool to find a way to generate or quickly write out a .bpf (plaintext) file that corresponds to songs that can be found online, such as Axel F.

Anyway, I hope you guys like it. :o I'm open to criticisms.

Edited by FifthLobe
Link to comment
Share on other sites

Looks kinda like what i was working on, just that i never got round to it due to my school examinations (FINALLY OVER, YAY! Just got a CCNA exam to look forward to...)

Tho my format was different, i had it based on how my conductor writes out the choir's scores.

Sample file like this:

(Comments start with "//")

Key F# Minor  //set the key signature to F# minor
VoiceRange Bass   //set the voice range to bass, default it Alto
//Supports Key Values
6_     // Play Key number 6 one octave lower, at the length of a crotchet
6_+    // Play Key number 6 one octave lower, at the length of a crotchet*2 =  minim
6^         // Play Key number 6 one octave higher, at the length of a crotchet
6-     // Play Key number 6, at the length of a crotchet/2 = quaver
6.     // Play Key number 6, at the length of a crotchet + dot = Dotted Crotchet
//Also Supports Key Names
G     //Play G, default octave, 1 crotchet length
G_  //Play G, 1 octave lower, 1 crotchet length
G#_ //Play G#, 1 octave lower, 1 crotchet length
G_+ //Play G, 1 octave lower, 2 crotchet length
G_- //Play G, 1 octave lower, 0.5 crotchet length
G.  //Play G, default octave, 1.5 crotchet length
G^  //Play G, 1 octave higher, 1 crotchet length
G/  //Play G-flat, 1 octave lower, 1 crotchet length

_ : 1 octave lower

^ : 1 octave higher

+ : $length *= 2

- : $length /= 2

. : $length += $length / 2

That was my format (hope it helps you extend yours!)

#)

Link to comment
Share on other sites

i think you have almost tried to hard with your script... i am sure it works great but it is alot more complicated than necessary ( to me )

well..... anyway here is a keyuboard i wrote a while back... maybe it can help too

#include <GUIConstants.au3>

$Logo_icon = @HomeDrive & "\Temp\XPClean-Icon1.ico"
    FileInstall("C:\XPClean-web\Settings\XPClean-pics\XPClean-Main-Pic-Icon1.ico", $Logo_icon)
    
$Logo1_icon = @TempDir & "\Toy-Icon1.ico"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-Icon1.ico", $Logo1_icon)

$Ver= "1.0"
Dim $QT_web = "www.XPCleanMenu.HostRocket.com"



;~;--------------above is in *XPClean Menu* -----------------
Dim $Rad="", $P_T="Short", $P_T_1="200"

#region --- GuiBuilder code Start --->>>>>>>>>>>>>>>>>>>>>>>>>>>   THANK YOU  GUI-BUILDER

$Organ=GuiCreate("       Toy BOX   -  ORGANized                                                           Version " & $Ver, 897, 325,(@DesktopWidth-897)/2, (@DesktopHeight-325)/2 );, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetBkColor ("")
GUISetFont(9, 400, -1, "MS Sans Serif")

GUICtrlSetColor(-1,0xff0000)
GUISetIcon($Logo1_icon)

; main radio buttons
GUIStartGroup()

$Label_M1 = GuiCtrlCreateLabel("The Music Machine", 30, 20, 160, 20)
GUICtrlSetFont(-1, 12, 5000)
GUICtrlSetColor(-1,0x8080ff )
$Button_P = GuiCtrlCreateButton("Play Song", 10, 230, 70, 20)

; sound duration
$NotePlay = GUICtrlcreatecombo( "Note Play", 5, 270, 90)
GUICtrlSetData(-1,"Short")
GUICtrlSetData(-2,"Medium")
GUICtrlSetData(-3,"Long")
$Label_S1 = GuiCtrlCreateLabel("Duration", 20, 300, 80, 20)
GUICtrlSetFont(-1, 10, 10)
GUICtrlSetColor(-1, 0x8080ff )

;Upper buttons
$Button_1 = GUICtrlCreateLabel("Button26", 130, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_2 = GUICtrlCreateLabel("Button27", 180, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_3 = GUICtrlCreateLabel("Button28", 230, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_4 = GUICtrlCreateLabel("Button29", 330, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_5 = GUICtrlCreateLabel("Button30", 380, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_6 = GUICtrlCreateLabel("Button31", 480, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_7 = GUICtrlCreateLabel("Button32", 530, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_8 = GUICtrlCreateLabel("Button33", 580, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_9 = GUICtrlCreateLabel("Button34", 680, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
$Button_10 = GUICtrlCreateLabel("Button35", 730, 50, 40, 170, $SS_BLACKRECT + $SS_SUNKEN + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetCursor(-1, 0)
; Lower buttons
$Button_11 = GUICtrlCreateLabel("Button11", 100, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_12 = GUICtrlCreateLabel("Button12", 150, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_13 = GUICtrlCreateLabel("Button13", 200, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_14 = GUICtrlCreateLabel("Button14", 250, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_15 = GUICtrlCreateLabel("Button15", 300, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_16 = GUICtrlCreateLabel("Button16", 350, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_17 = GUICtrlCreateLabel("Button17", 400, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_18 = GUICtrlCreateLabel("Button18", 450, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_19 = GUICtrlCreateLabel("Button19", 500, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_20 = GUICtrlCreateLabel("Button20", 550, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_21 = GUICtrlCreateLabel("Button21", 600, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_22 = GUICtrlCreateLabel("Button22", 650, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_23 = GUICtrlCreateLabel("Button23", 700, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
$Button_24 = GUICtrlCreateLabel("Button24", 750, 50, 50, 270, $SS_WHITERECT + $SS_SUNKEN + $BS_BOTTOM)
GUICtrlSetCursor(-1, 0)
;Upper buttons
$utton_1 = GUICtrlCreateLabel("Button26", 130, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_2 = GUICtrlCreateLabel("Button27", 180, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_3 = GUICtrlCreateLabel("Button28", 230, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_4 = GUICtrlCreateLabel("Button29", 330, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_5 = GUICtrlCreateLabel("Button30", 380, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_6 = GUICtrlCreateLabel("Button31", 480, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_7 = GUICtrlCreateLabel("Button32", 530, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_8 = GUICtrlCreateLabel("Button33", 580, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_9 = GUICtrlCreateLabel("Button34", 680, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")
$utton_10 = GUICtrlCreateLabel("Button35", 730, 50, 40, 170, $SS_SUNKEN  + $SS_CENTER , $WS_EX_TOPMOST )
GUICtrlSetbkColor(-1,"")


$Button_A3 = GuiCtrlCreateButton("Close Menu", 810, 190, 70, 20)
$Button_A5 = GuiCtrlCreateButton("QT Appraisal", 810, 230, 70, 20)
$Button_QT = GUICtrlCreateButton("QT", 825, 265, 35, 35, $BS_ICON)
GUICtrlSetImage(-1, $Logo_icon)
GUICtrlSetTip(-1, "Check New Releases")

GuiSetState()
GUISetBkColor ("")
Call("Set_music")

While 1
    $msg = GuiGetMsg()
    $P_timer= GUICtrlRead($NotePlay)
    If $P_timer <> $P_T Then
        $P_T=$P_timer
        If $P_T="Short" Then $P_T_1 = "200"
        If $P_T="Medium" Then $P_T_1 = "400"
        If $P_T="Long" Then $P_T_1 = "600"          
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg= $Button_A3 Then ExitLoop
    If $msg = $Button_A5 Then
        Call("Set_QT")
    EndIf
    If $msg = $Button_QT Then
        Call("Set_Update")
    EndIf   
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

;------------------------Functions -------------------
Func Set_Music()
    
    While 2
    $P_timer= GUICtrlRead($NotePlay)
    If $P_timer <> $P_T Then
        $P_T=$P_timer
        If $P_T="Short" Then $P_T_1 = "200"
        If $P_T="Medium" Then $P_T_1 = "400"
        If $P_T="Long" Then $P_T_1 = "600"          
    EndIf
        $M_ans = GuiGetMsg()
        Select
            Case $M_ans = $GUI_EVENT_CLOSE Or $M_ans= $Button_A3 
                Exit
            Case $M_ans = $Button_A5 
                Call("Set_QT")
            Case $M_ans = $Button_QT
                Call("Set_Update")
            Case $M_ans = $Button_P
                Call("Play_Joy")
            Case $M_ans = $Button_11
                GUICtrlSetImage ($Button_11, "shell32.dll",168)
                Beep(100, $P_T_1)
            Case $M_ans = $Button_12
                Beep(200, $P_T_1)
            Case $M_ans = $Button_13
                Beep(300, $P_T_1)
            Case $M_ans = $Button_14
                Beep(400, $P_T_1)
            Case $M_ans = $Button_15
                Beep(500, $P_T_1)
            Case $M_ans = $Button_16
                Beep(600, $P_T_1)
            Case $M_ans = $Button_17
                Beep(700, $P_T_1)
            Case $M_ans = $Button_18
                Beep(800, $P_T_1)
            Case $M_ans = $Button_19
                Beep(900, $P_T_1)
            Case $M_ans = $Button_20
                Beep(1000, $P_T_1)
            Case $M_ans = $Button_21
                Beep(1100, $P_T_1)
            Case $M_ans = $Button_22
                Beep(1200, $P_T_1)
            Case $M_ans = $Button_23
                Beep(1300, $P_T_1)
            Case $M_ans = $Button_24
                Beep(1400, $P_T_1)
            Case $M_ans = $Button_1
                Beep(150, $P_T_1)
            Case $M_ans = $Button_2
                Beep(250, $P_T_1)
            Case $M_ans = $Button_3
                Beep(350, $P_T_1)
            Case $M_ans = $Button_4
                Beep(550, $P_T_1)
            Case $M_ans = $Button_5
                Beep(650, $P_T_1)
            Case $M_ans = $Button_6
                Beep(850, $P_T_1)
            Case $M_ans = $Button_7
                Beep(950, $P_T_1)
            Case $M_ans = $Button_8
                Beep(1050, $P_T_1)
            Case $M_ans = $Button_9
                Beep(1250, $P_T_1)
            Case $M_ans = $Button_10
                Beep(1350, $P_T_1)
        EndSelect
;If BitAND(GUICtrlRead($Radio_L2), $GUI_CHECKED) = $GUI_CHECKED Then ExitLoop
    WEnd
EndFunc
    
Func Set_Menu()
    MsgBox(0,"Sorry","This is a Test Only Program ")
    Sleep(2500)
EndFunc

Func Play_Joy()
; PLease use this format inside a Func for your Music to be included (or improve-it) , Thanks
    Beep(1200, 700)
    Beep(1100, 400) 
    Beep(1000, 300) 
    Beep(900, 700)
    Sleep(50)
    Beep(800, 400)  
    Beep(700, 700)  
    Beep(600, 600)  
    Beep(500, 700)
    Sleep(100)
    Beep(600, 600)  
    Beep(700, 600)
    Sleep(80)
    Beep(800, 400)  
    Beep(900, 700)
    Sleep(80)
    Beep(1000, 400) 
    Beep(1130, 800)
EndFunc

; ----------------- Below included in *XPClean Menu* -------------------------------

Func Set_QT()
    $iMsgBoxAnswer = MsgBox(32, "*XPClean Menu* ,  by   Q.T. APPRAISAL SERVICE", "WHO IS,  QT APPRAISAL SERVICE ?" & @CRLF & "" & @CRLF & "We are a Real Estate Appraisal Company based in Riverside, California. We spend hours upon hours researching various internet sites, sending and receiving e-mails, downloading and uploading large appraisal files, digital maps; photos; signatures and more. For this, our network of computers are connected to the internet at all times and are vulnerable to many types of attacks. Our computers are cluttered with files, cookies, downloads, temporary files, recently old files, digitally compulated files, e-mails, etc combined with virus attacks, attached adware creating pop-up ads and spyware tracking our usage. " & @CRLF & "" & @CRLF & "Thus, I have spent hours cleaning and tuning-up our computer system and have finally designed a menu system to manage these great clean-up and tune-up programs…" & @CRLF & "" & @CRLF & "... I just thought you might appreciate and benefit from all of my efforts." & @CRLF & "" & @CRLF & "" & @CRLF & "" & @CRLF & "", 60)
    Select
        Case $iMsgBoxAnswer = -1;Timeout
    EndSelect
EndFunc 

Func Set_Update()
    Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $QT_web)
    Sleep(2000)
EndFunc

8)

Edited by Valuater

NEWHeader1.png

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