Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't I hear any sound after calling the Beep function in Windows 7?

I have the following code:

#include <windows.h>
#include <stdio.h>

int main(void)
{
        Beep(523, 500);
        Sleep(1000);
        return 0;
}

I am compiling it using MinGW with Dev-C++. My problem is that I can't hear anything, although I don't get an error. I have Windows 7. Any ideas?

like image 415
Thanos Papastathopoulos Avatar asked Apr 22 '12 08:04

Thanos Papastathopoulos


1 Answers

Turn your speakers on. If they're already on, turn up the volume. If you don't have speakers and a sound card installed on your computer, then get some and install them, then try running the program again.

All of these things are required to hear anything from the Beep function on Windows 7. It no longer plays sound from the built-in hardware system speaker. Instead, the sound is passed to the default sound device for your user session. In a standard local user session, that would be your sound card. The documentation explains this important detail in the "Remarks" section:

A long time ago, all PC computers shared a common 8254 programable interval timer chip for the generation of primitive sounds. The Beep function was written specifically to emit a beep on that piece of hardware.

On these older systems, muting and volume controls have no effect on Beep; you would still hear the tone. To silence the tone, you used the following commands:

net stop beep  
sc config beep start= disabled

Since then, sound cards have become standard equipment on almost all PC computers. As sound cards became more common, manufacturers began to remove the old timer chip from computers. The chips were also excluded from the design of server computers. The result is that Beep did not work on all computers without the chip. This was okay because most developers had moved on to calling the MessageBeep function that uses whatever is the default sound device instead of the 8254 chip.

Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.

In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.

like image 154
Cody Gray Avatar answered Oct 04 '22 18:10

Cody Gray