VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Window

by Jorge Loubet (2 Submissions)
Category: Sound/MP3
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 14th October 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Windows98

API Declarations


Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

Rate Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Window



'Hola amigos !
'Do you remember the sound example "OUT_EX.BAS"
'for QuickBasic 4.5 from Microsoft ?
'Here is what I did to make the PC speaker to sound.
'I just modified an added some lines to make my speaker
'beep at the frequency and length of time I want.
'1. Put two text boxes and name the first as txtFreq, the second as txtLength.
'2. Put a command button named as cmdStartSound.
'3. Put a timer and name it as TimerSound
'
'The real hero is SoftCircuits with his library WIN95IO.DLL
'Download the library from their site:
'http://www.softcircuits.com and...
'*** Please read the annotations of this library before use it. ***
'Copy win95io.dll to your WindowsSys folder.
'Have a nice sound...
'If you think it is good for you, let me know that.
'[email protected]

'Durango, Dgo. Mexico.

Option Explicit
Dim SoundEnd As Boolean

Private Sub cmdStartSound_Click()
Dim Freq As Single
Dim Length As Single
    
    Freq = Val(txtFreq.Text)     'In Hertz
    Length = Val(txtLength.Text) 'In miliseconds
    
    'This is all you have to do
    Sounds Freq, Length

End Sub

Private Sub Sounds(Freq, Length)

Dim LoByte As Integer
Dim HiByte As Integer
Dim Clicks As Integer
Dim SpkrOn As Integer
Dim SpkrOff As Integer

'Ports 66, 67, and 97 control timer and speaker
'
'Divide clock frequency by sound frequency
'to get number of "clicks" clock must produce.
    '"I didn't tested if this is exactly the frequency,
    'but it's ok to start here. I think we may use
    'a piano or other reference to adjust the clicks.
    'For example, "A" has a frequency of 880 Hz. If you have
    'some musical sense, it can be adjusted very close."
    Clicks = CInt(1193280 / Freq)
    LoByte = Clicks And &HFF
    HiByte = Clicks \ 256
'Tell timer that data is coming
    vbOut 67, 182
'Send count to timer
    vbOut 66, LoByte
    vbOut 66, HiByte
'Turn speaker on by setting bits 0 and 1 of PPI chip.
    SpkrOn = vbInp(97) Or &H3
    vbOut 97, SpkrOn

'Leave speaker on (while timer runs)
    SoundEnd = False
    TimerSound.Interval = Length
    TimerSound.Enabled = True
    Do While Not SoundEnd
        'Let processor do other tasks
        DoEvents
    Loop
'Turn speaker off.
    SpkrOff = vbInp(97) And &HFC
    vbOut 97, SpkrOff
End Sub

Private Sub TimerSound_Timer()
    'Time to sound is over
    SoundEnd = True
    TimerSound.Enabled = False
End Sub


Download this snippet    Add to My Saved Code

Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Window Comments

No comments have been posted about Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Window. Why not be the first to post a comment about Make your PC speaker beep at the frequency and time you want. It works fine in Windows95 and Window.

Post your comment

Subject:
Message:
0/1000 characters