Solved

Beep sound

Posted on 1997-04-21
6
5,211 Views
Last Modified: 2008-02-26
I know how to do beeps with various frequencies and durations in Visual Basic and the code was working on windows 3.1 and 95.

However, I feel it is more difficult in Delphi (should
be better than Visual Basic):

People said we may use Windows.Beep(frequency, duration)
in Windows NT (but not in Windows 3.1, I think), I have
tried to use it in Windows 95. It was working anyway but
was only a simple beep. When I change the frequency from
99 to 999999999 and change the duration from 99 to
999999999, the sounds remained the same!

Can you give me the right code for that (better for both
NT and 95)?
0
Comment
Question by:zhuhail
  • 3
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
StevenB earned 50 total points
ID: 1335555
 You cannot generate different beeps in win95, as you can in NT, with the Beep call. As the Delphi help puts it:

Windows 95:
The Beep function ignores the dwFreq and dwDuration parameters. On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.

  i.e. Win95 ignores all parameters you enter into the Beep Command and just plays a simple beep. You might try MessageBeep instead, since this allows you to play several of the sounds in the windows registry such as SystemAsterisk and SystemExclamation. The info for this is in Delphi help, or I'll mail it to you if you want/require.

Hope this helps, Steven.
0
 

Author Comment

by:zhuhail
ID: 1335556
Thank you for your help.

You are right...that may not wrok in Win95 and I want you give me a right code :-)
Perhaps we can do beeps with designed frequency and duration in Win95 by calling API functions. That is what I did in Visual Basic....Or, do you think Win95 not supports the API functions for beep sound anymore? Can we still call such API functions of 16 bit from Win95?

Cheers.
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335557
OK I've just had a bit of a play with Beeps and this is the score:

There is a Delphi Beep Command Defined in SysUtils. If you have SysUtils in your Uses clause then Calling Beep will call this function. This function takes no parameters and if you try and put any in the call you will get an error. This function makes a simple beep sound using the internal speaker.

There is also an API call Beep. This call takes two parameters and can only be called directly if you remove SysUtils from the Uses clause, (otherwise you are calling the Delphi Beep function). The previous comments about this Beep command in win95 still stand. I don't have NT so I can't test what happens, but in 95 the API Beep function plays the Default Sound Wave, or a simple beep if no sound card is installed.

  I'm afraid I can't help you concerning 16 bit technology, it's out of my scope of knowledge, however I can tell you with some certainty that using the beep command in Win95 will never produce more than the one simple boring beep.

  Why do you need this functionality?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:zhuhail
ID: 1335558
Hi,

I am so sad when I reading your comment :-(
This is the first thing I found that Win3.1 better then Win95.

Why I need such beeps? In Visual Basic, using such beeps, I made some very simple, but nice music in a game which is written under Win3.1 (without the sound card) but stil works under Win95.

Cheers.
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1335559
 The thing about the Beep command is that it is only really intended for use as a warning sound (It is included as part of the Error processing functions). I don't know what sort of code was generated by Visual Basic such that your Application ported from 3.1 to 95 but I can only presume that it doesn't use the API Beep function. I havn't come accross a call that will allow the sort of wave generation that you are looking for in Win95, if it is possible then I suspect that it will require a lot of fiddly code and I don't know how it's done I'm afraid. I would stick to using sampled sounds for your games applications (Investigate the PlaySound API Call).
  Sorry to be so negative, feel free to reject this answer if you feel someone else might have a more satisfying answer for you.

  Steven.
0
 

Expert Comment

by:keksperte
ID: 1335560
Hi zhuhail here is keksperte

don't beleave them if they say impossible.

here is my solution:

   This is a workaround to create some tones other than the BEEP in Delphi
   (and other IDE's).  It's not DELPHI but it works, is flexible and it's free.

1. Create a link from the good old QBASIC.EXE and move it to the C:\tmp DIR
    and name it BEEPER
   (You will find QB in the C:\WIN95\Command or C:\WINNT\System32 Dir.)

   Enter on the programtab the comandline
     C:\WIN\COMMAND\QBASIC.EXE /RUN C:\tmp\MoreBeep.bas
   and
     C:\WIN\COMMAND
   for the workingdir
   Also you can use a very small font (see fonttab, Sysfont 2x4)
   On screentab select standard window with restore params on restart so that the last
   windowposition will be saved

2. Create with the NOTEPAD or directly in QBASIC the following BasicCode:

   PLAY "MBT180o2P2P8L16CEGL8>CP64"
   WHILE PLAY(0) > 0: WEND
   SYSTEM
   rem 4 more help on PLAY press F1-Button or ALT+H in QB

   Save this code as 'MoreBeep.bas'

3. Create a new delphi project with a button.

4. Define in the ButtonClick procedure the following command:

   procedure TForm1.Button1Click(Sender: TObject);
   begin
     ShellExecute(Application.Handle, nil, 'Beeper', '', 'C:\tmp', SW_SHOW);
   end;

5. Compile the project and run. On Click you will hear the hevently sound on the speaker.

6. To hide the QB-Window you can use on WINNT the SW_SHOWMINIMIZED command     in the above ClickProcedure. On WIN95 it seams that the only way is to put the window
   near the border or under the TASK-BAR so that you can't see it at runtime.

So, that's it. I hope you'll become a great musican.

keksperte
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now