How to play a specific frequency of wave sound out ?

BarryTang
BarryTang used Ask the Experts™
on
I would like to play specific frequency of sound wave out.
The frequency of the sound is specific by me ( e.g. 445Hz ). I would also like to know how to control the duration of the playback
( i.e. how long it will play ) ?

Would anybody suggest an answer for me, thank you !!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You can use the Beep API call:

Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

Private Sub Command1_Click()
Beep 445, 3000 'this will beep at 445hz for 3 seconds
End Sub

Author

Commented:
Hi dennislw :

Thanks for information

However, this is a method for Win NT/2000 only.

Since my environment need to be at Win 98, do you know
if there is any method to do the same thing at this
environment ?

Thank you

Commented:
This can be done with a direct port manipulation, I am searching to found the correct port...

or
You can use the Python library..
http://www.python.org/doc/current/lib/module-winsound.html

I haven't time to try this lib, but they can do that.


Sorry by the grammatical error, I speak spanish. I can talk in English but like Tarzan. Corrections are welcome.
Good Luck.
Déjà-vu
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
'This code use a dll called NTPort but work fine with Win9X and can be used to send anything to any port on your PC including the Speaker at port addresses $42 through $43.
You can found the dll ver 2.4 at and buy or crack it(your choice):
http://www.zealsoftstudio.com/ntport/download.html

If you want I can email you a "free" version.

If you have some BASM or C+ knowledge you can do it sending the data to this ports...


'Here are the code:

Option Explicit

Declare Sub Outport Lib "ntport.dll" (ByVal portID As Integer, ByVal nByte As Integer)
Declare Sub OutportW Lib "ntport.dll" (ByVal portID As Integer, ByVal nWord As Integer)
Declare Sub OutportD Lib "ntport.dll" (ByVal portID As Integer, ByVal dwDWord As Long)
Declare Function Inport Lib "ntport.dll" (ByVal portID As Integer) As Integer
Declare Function InportW Lib "ntport.dll" (ByVal portID As Integer) As Integer
Declare Function InportD Lib "ntport.dll" (ByVal portID As Integer) As Long

Declare Sub Outp Lib "ntport.dll" (ByVal portID As Integer, ByVal nByte As Integer)
Declare Sub Outpw Lib "ntport.dll" (ByVal portID As Integer, ByVal nWord As Integer)
Declare Sub Outpd Lib "ntport.dll" (ByVal portID As Integer, ByVal dwDWord As Long)
Declare Function Inp Lib "ntport.dll" (ByVal portID As Integer) As Integer
Declare Function Inpw Lib "ntport.dll" (ByVal portID As Integer) As Integer
Declare Function Inpd Lib "ntport.dll" (ByVal portID As Integer) As Long

Declare Function IsWinNT Lib "ntport.dll" () As Boolean
Declare Function GetLastState Lib "ntport.dll" (ByVal sStatus As String) As Long
Declare Function GetNTPortVersion Lib "ntport.dll" () As Integer

Declare Sub LicenseInfo Lib "ntport.dll" (ByVal sUser As String, ByVal lKey As Long)

Declare Sub EnablePorts Lib "ntport.dll" (ByVal portStart As Integer, ByVal portEnd As Integer)
Declare Sub DisablePorts Lib "ntport.dll" (ByVal portStart As Integer, ByVal portEnd As Integer)

Public Const ERROR_NONE = 0
Public Const ERROR_DRIVER = 6

Public Sub Speaker(bOn As Boolean)
    Dim portVal As Integer
   
    portVal = Inport(&H61)
    If bOn Then
        portVal = portVal Or 3
        portVal = &H2F
    Else
        portVal = portVal And (Not 3)
    End If
    Outport &H61, portVal
End Sub

' Speaker freq is set by setting divider in Intel
' 8253/8254 timer chip at port addresses $42 through $43
Public Sub SetFreq(hertz As Integer)
    Dim s As String
     
    If hertz Then
        Dim divisor As Long
        divisor = 1193180 / hertz
       
        Outport &H43, &HB6
   
        Outport &H42, divisor Mod 256
        Outport &H42, divisor \ 256
       
        Speaker True
    Else
        Speaker False
    End If
End Sub

Author

Commented:
Dear Deja-vu :

Thank very much for your information.

Just two more question I want to ask :

 1. Does your VB code provided also control the duration
    up to 1 millisecond ( as the Beep API )

 2. Can I make the sound card to output instead of using
    computer speaker

Also, it is better for me to have your version of NTPort dll for my testing purpose

Regards


Commented:
1. Sorry but I don't know that. I don't think so
2. If you want to use a soundcard you can use DirecX. You can create a sound for a specific frequency too.
To learn ALL about DirectX use this tutorial

http://www.freevbcode.com/ShowCode.Asp?ID=1082#Main

Dounload the NTPort v2.4 from the web is more fast than v1.0 only show a splash window when start...

http://www.zealsoftstudio.com/ntport/download.html

If that don't work for you, tomorrow I will find the old version and email you, but tellme where...

Déjà-vu

Author

Commented:
Dear Deja-vu :

Actually it is better for me to use a soundcard ( instead
of using speaker ), so I would like to do program by DirectX.

Some of the DirectX command I already understand,
can you show me the DirectX code for generating a sound with specific frequency and control its duration.

Thank you

Commented:
I will try (I don't understand all) but I haven't enough time right now.. waitme a few days. it's urgent?

Author

Commented:
Dear Deja-vu :

It is not so urgent, just work on it at your convenience.

But I must say thank you very much for help for the work
you did before and after.

Best Regards from Barry

Author

Commented:
Dear Deja-vu :

I find some code from the following links for your
reference

http://www.exhedra.com/DirectX4VB/Tutorials/DirectX7/DM_Modify.asp

It use DirectMusic to play single note of specific frequency and duration. But it still cannot play the sound under my Win 98 environment.

Can you figure out the reason ?

Barry

Commented:
Dear Deja-vu :

Please !!!  Can you send me free version of NTport ??
I think some version without splash window (i hate it.. grrr) .. or license info

Thank you very very much !!!!

<Edited by SpideyMod>

(Sorry for my English .. I am Czech)

Segeer (from WMWMasters)
BarryTang,
You have 17 opened questions as of this date.  
I will be posting in each of these questions.  
Please take care of your opened questions older than 30 days by clicking on your logon name link and looking for UnlockedQ or using the links I am providing below.  
Please finalize these within 72 hours or I will ask administration to look into your account at that point.  If you have questions, please ask and I will provide assistance.  

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20187331.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20133725.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20088012.html
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20083509.html
http://www.experts-exchange.com/Miscellaneous/Games/Q_20382035.html
http://www.experts-exchange.com/Programming/Game_Development/Q_20382294.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20534626.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20521771.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20515842.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20513575.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20493221.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20436510.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20399960.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20395868.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20375410.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20373966.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20372811.html

Thank you.
BarryTang,
No comment has been added lately (47 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: PAQ/No Refund

Please leave any comments here within 7 days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

Dabas
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post a request in Community support (with a link to this page) to refund your points. http://www.experts-exchange.com/Community_Support/
Personally, I believe Deja-vu should get the points on this one.  2 Methods were given, lots of links with information.  It is likely that these links would have solved the problem.

The moderators might want to take a look at the comment by Segeer as well.
Administrative Action - Force Accepted.

SpideyMod
Community Support Moderator @Experts Exchange
Segeer,
Asking for a hack/crack, or means to remove demo versions, Keys, etc is a severe violation of the membership agreement.  I need you to re-read the membership agreement and indicate your understanding and future compliance within 72 hours or I have an obligation to turn your account to site administration for review.

The Membership agreement can be found at:
http://www.experts-exchange.com/jsp/infoMemberAgreement.jsp 


Additionally, I have removed your email address from your coment as off-site handling of questions is not allowed.

twalgrave, thanks for the heads-up on this.

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial