Solved

Beep sound

Posted on 1997-04-21
6
5,238 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

763 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