Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Beep sound

Posted on 1997-04-21
Medium Priority
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)?
Question by:zhuhail
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

StevenB earned 100 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.

Author Comment

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?


Expert Comment

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?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 1335558

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.


Expert Comment

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.


Expert Comment

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
   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
   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);
     ShellExecute(Application.Handle, nil, 'Beeper', '', 'C:\tmp', SW_SHOW);

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.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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