Beep Sounds in C++

Started by
10 comments, last by XTAL256 14 years, 10 months ago
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.
Advertisement
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.
[Window Detective] - Windows UI spy utility for programmers
Why don't you just use the C++ bell alert escape code?
i.e. cout<<"\a"<<endl;
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
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.
[Window Detective] - Windows UI spy utility for programmers
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.
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?
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.
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.
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.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
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).

This topic is closed to new replies.

Advertisement