I want to make a beep sound using PC speaker in C#. When using the following code:
[DllImport("kernel32.dll", EntryPoint = "Beep", SetLastError = true,
ExactSpelling = true)]
public static extern bool Beep(uint frequency, uint duration);
static void Main()
{
while (true)
{
Beep(1000, 500);
Thread.Sleep(2000);
}
}
instead of beeping through the PC speaker, it simply outputs a sound of a given frequency and duration to the default sound device (as a headset for example). The same thing happens when using Console.Beep()
.
Why?
Notes:
The PC speaker is on. When I start the PC, it beeps.
The OS is Windows 8.
(Go to a windows computer and in "RUN" type in command prompt. Then a black screen will pop up. In that type in CTRL+G, then it will make a a "^G", however many times you press it is how many times it will BEEP. Press enter and have fun!
Under normal circumstances, you should be able to use it just by typing ' beep ', with no options. The traditional method of producing a beep in a shell script is to write an ASCII BEL ( \007 ) character to standard output, by means of a shell command such as ' echo -ne '\007' '.
A very short beep is indicative of a problem with your motherboard. It can also mean that you have a problem with your system memory (BIOS AWARD). A long beep followed by three sequential short beeps signals an issue linked to your graphics card configurations.
From Windows 7 onwards, you can no longer easily make sound via the internal speaker.
For Windows 7, we resolved the issue completely – we moved all the functionality that used to be contained in Beep.Sys into the user mode system sounds agent – now when you call the Beep() API instead of manipulating the 8254 chip the call is re-routed into a user mode agent which actually plays the sounds.
[…]
There were also some unexpected consequences. The biggest was that people started noticing when applications called Beep(). They had placed their PCs far enough away (or there was enough ambient noise) that they had never noticed when their PC was beeping at them until the sounds started coming out their speakers.
See here for details:
https://docs.microsoft.com/en-us/archive/blogs/larryosterman/whats-up-with-the-beep-driver-in-windows-7
Do you have any 32 bit Windows machines lying around? Try Console.Beep();
on one of those, the PC speaker will beep.
On 64 bit Windows (XP, Vista, 7 or 8) the driver to do this isn't present so it will come out of the speaker plugged into the machine instead.
Also, correct me if I'm wrong but I would hazard a guess that the beep you hear whenever your PC turns on is from your BIOS, before you actually hit Windows 8.
You can use SystemSounds.Beep
for example: SystemSounds.Beep.Play();
See also: SystemSounds.Beep Property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With