Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I use to replace the WinAPI Beep() function?

I've got a Visual C++/CLI app which uses beeps to signify good and bad results (used when the user can't see the screen).

Currently I use low pitched beeps for bad results and high pitched beeps for good results:

if( goodResult == true )
{
    Beep(1000, 40);
}
else
{
    Beep(2000, 20);
}

This works okay on my Vista laptop, but I've tried it on other laptops and some seem to play the sounds for less time (they sound more like clicks than beeps) or the sound doesn't play at all.

So I have two questions here:

  1. Is there a more reliable beep function?
  2. Is there a (simple) way I can play a short .wav file or something similar instead (preferred solution).
like image 358
Jon Cage Avatar asked Jun 25 '26 16:06

Jon Cage


1 Answers

The Beep function traditionally used the PC speaker, and I guess it is more or less obsolete nowadays. I guess the functionality is handled by the Laptop's BIOS, and thus is hardware dependant. I suggest that you use the PC:s soundcard to play the sound instead.

Create two tones as WAV files in e.g. Audacity, then play them using e.g. PlaySound.

like image 200
Krumelur Avatar answered Jun 27 '26 08:06

Krumelur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!