Sign in to follow this  
Luonnos

Beep Sounds in C++

Recommended Posts

I read somewhere that the Beep() command is not supported in C++ in Vista 64. If this is the case, is there any way to activate it? If not, is it possible to play and change the pitch of a sound file? How would one play a sound file in MFC? Answers to any of these questions would be appreciated.

Share this post


Link to post
Share on other sites
The beep command is most likely from back in the old days where computers didn't necessarily come with built-in speakers or a sound card. The beep command would beep the internal speaker, computers these days don't have such a speaker so the command is re-routed to the normal sound output device.

But you probably don't want to use that anyway (i doubt there are any games today that generate sound using the system beep [smile]). There are Windows API functions to play sound files, as always MSDN is a good reference.

Share this post


Link to post
Share on other sites
Quote:
Original post by daviangel
Why don't you just use the C++ bell alert escape code?
i.e. cout<<"\a"<<endl;

Yes, but when he said beep is not supported in Vista 64 i assumed that meant all implementations of it. So if '\a' internally called the beep command then it too would not work (and probably just do nothing). This is all just speculation, to prove me wrong all one would have to do is try it themselves. But right or wrong the fact still remains that there is no real reason to use the beep command because Windows has proper audio functions.

The only time i have seen beep used is to indicate an invalid user action, e.g. when the user tries to type more text in a textbox with a maximum character length. But even then, you can use PlaySound and pass the beep sound effect.

Share this post


Link to post
Share on other sites
Quote:
Original post by daviangel
Why don't you just use the C++ bell alert escape code?
i.e. cout<<"\a"<<endl;


The bell is not necessarily a beep (it might as well be a notification wave sound as configured in Windows settings), plus you can't control frequency, duration. The OP probably needs something like this, but there is no portable (read standard C++) beep.

On *nixen, you could (assuming beep is installed) do a simple 'system("beep");', on Windows I don't know.

Share this post


Link to post
Share on other sites
I must be really old and disconnected. Don't computers still beep after they complete their POST test? If not, how are we supposed alerted about hardware failures during startup these days?

Share this post


Link to post
Share on other sites
What's the purpose of using Beep, are you playing a tune or something with it?
If it's just for a beep, try MessageBeep: http://msdn.microsoft.com/en-us/library/ms680356(VS.85).aspx.

A good way of gaining more control, if you are willing to do some more work, is to use windows waveOut functions: http://msdn.microsoft.com/en-us/library/ms713499(VS.85).aspx.

There's an article about it here on Gamedev, with sample sourcecode, playing a sound you can easily change the pitch of: http://www.gamedev.net/reference/articles/article1348.asp.

Share this post


Link to post
Share on other sites
Beep can be useful for testing, I used it a few months back for testing the synchronicity of two clocks on two computers, then mic recorded the speaker output to calculate their accuracy using the frequency-space view in Adobe Audition.

Anywho, I had this exact problem with Vista64, and solved it using this - a DirectSound implementation of Beep.

Hope that helps,
Ed.

Share this post


Link to post
Share on other sites
Quote:
Original post by kseh
I must be really old and disconnected. Don't computers still beep after they complete their POST test? If not, how are we supposed alerted about hardware failures during startup these days?

Not all.
I actually have a couple of EVGA motherboards and they all come with diagnostic LED's on the motherboard instead of beeping to tell you what's wrong since not all cases come with built-in speakers anymore.

Share this post


Link to post
Share on other sites
Quote:
Original post by daviangel
Quote:
Original post by kseh
I must be really old and disconnected. Don't computers still beep after they complete their POST test? If not, how are we supposed alerted about hardware failures during startup these days?

Not all.
I actually have a couple of EVGA motherboards and they all come with diagnostic LED's on the motherboard instead of beeping to tell you what's wrong since not all cases come with built-in speakers anymore.


I think my new mainboard (so new that I haven't checked every detail yet) doesn't have a beeper either, which is a real pity, especially when you have some display-free boxes which tell their status via a beep. There was also a Linux distro which told you about successfull boot by morsing its name (don't remember which distro that was).

Share this post


Link to post
Share on other sites
Quote:
Original post by kseh
I must be really old and disconnected. Don't computers still beep after they complete their POST test? If not, how are we supposed alerted about hardware failures during startup these days?

My Asus motherboard used to just tell you what the problem was.

Seriously, it would output a synthesized voice through the speakers. "System failed due to CPU overclocking" is a message that I got pretty frequently. [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by Sc4Freak
My Asus motherboard used to just tell you what the problem was.

Seriously, it would output a synthesized voice through the speakers. "System failed due to CPU overclocking" is a message that I got pretty frequently. [grin]

Wow, really? That is so cool!

I don't think any motherboards come with a built-in speaker (i.e. beeper) anymore. They just don't bother because it's very rare to get a hardware failure these days. If something does go wrong, people will just take their PC to the shop to get fixed, or throw it out and get a new one. That's just what i heard anyway, some mobo manufacturers might still put a beeper in.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this