Results 1 to 4 of 4

Thread: Using an internal speaker

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Hi!
    I need to use my computer speaker /no sound card/. Like PLAY or SOUND in QBasic, sending wav files to it too. I think it can be done trough OUT commands, but I don't know how.



    ------------------
    Thanks,
    John, 14 years old

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    Post

    Your correct! You can access the speaker of your PC through an address and play various frequency notes. In fact, I believe its address is 61H, but I could be wrong.

    Problem: VB does not ship with any direct Out commands.

    You can download an I/O port library from www.lvr.com/parport.htm. There are many free utilities there that will allow you to use in and out.


    ------------------
    HTH,
    Philip
    [email protected]

  3. #3
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    Better yet, here's some code

    In the module, put this:

    Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
    Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

    note: you need to get this file from the address PhilipG gave you.

    In the form, put a two command buttons and a horizontal scroll bar. Command1 is Stop, and command two is Go. The scroll bar changes the frequency, and is limited to >37. The code:

    Private Sub Sounds(Freq)
    Dim LoByte As Integer
    Dim HiByte As Integer
    Dim Clicks As Integer
    Dim SpkrOn As Integer
    Clicks = CInt(1193280 / Freq)
    LoByte = Clicks And &HFF
    HiByte = Clicks \ 256
    vbOut 67, 182
    vbOut 66, LoByte
    vbOut 66, HiByte
    SpkrOn = vbInp(97) Or &H3
    vbOut 97, SpkrOn
    End Sub

    Private Sub Command1_Click()
    vbOut 97, 0
    End Sub

    Private Sub Command2_Click()
    Freq = HScroll1.Value
    Sounds Freq
    End Sub

    Private Sub HScroll1_Change()
    Freq = HScroll1.Value
    Sounds Freq
    End Sub

    Private Sub HScroll1_Scroll()
    Freq = HScroll1.Value
    Sounds Freq
    End Sub

    I believe that should do it for you. If it doesn't work, post.

    bob

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Hey!
    Thank you very much, it works perfect. Now, is possible to send a wave file to the speaker? [Square signal isn't the best way to reproduce the sound].

    PS: Note, .txt wave files (from GoldWave) are good way to start, aren't?



    ------------------
    Thanks,
    John, 14 years old

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width