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

佐手、 提交于 2019-12-10 16:05:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10266599/why-dont-i-hear-any-sound-after-calling-the-beep-function-in-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!