Sign in to follow this  

making computer beep?

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is my favorite "scare the shit out of a newb" snippet:


#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout << "Warning: Proceeding will cause major system failure!\n";
for(int i = 0; i < 1500; i++)
Beep(i, 6);
MessageBox(NULL, "Your system is fried!", "KABLAM!", 0);
return 0;
}



hope you likey! HARHARHARHAR!

Share this post


Link to post
Share on other sites
A system beep is actually an ASCII character. I forget what the value is, but you can access it by using the escape character \a. So outputting a \a to cout will cause a system beep.

Share this post


Link to post
Share on other sites
That has really no application, i woudlnt waste any time figureing that one out, go use openAL or something, its an elegant API, and its something that will still be useful to you later on...

plus, i would bet money you need to do some major backflips in order to modulate the sound of the beeps

-Dan

Share this post


Link to post
Share on other sites
Quote:
I forget what the value is, but you can access it by using the escape character \a. So outputting a \a to cout will cause a system beep.

\07 -- it works in Java as well, unlike \a

Share this post


Link to post
Share on other sites
Quote:
Original post by Thunder_Hawk
Does anyone know of a way to play MIDI-esque music on the internal speaker similar to QBASIC's capabilities?
Man. That reminds me of that time the I wrote a MIDI player in QBASIC.

I miss my sound blaster 16. So easy to program. *hugs OPL3*

Share this post


Link to post
Share on other sites
Fruny, that article isn't asm, it's Pascal (with some tiny bits of asm). It's from PC-GPE.. I remember that disk mag from years ago! A rather large collection of code snippets related to game/graphic programming. Ahh.. fond memories.

cheers
sam

Share this post


Link to post
Share on other sites
Quote:
Original post by izzo
Fruny, that article isn't asm, it's Pascal (with some tiny bits of asm).


You're right (of course), I was thinking about those bits of ASM (which do the actual speaker controlling), not about the Pascal code surrounding them :)

Share this post


Link to post
Share on other sites
Quote:
Original post by wyrzy
Quote:
I forget what the value is, but you can access it by using the escape character \a. So outputting a \a to cout will cause a system beep.

\07 -- it works in Java as well, unlike \a


\7 will work too, as long as the next character is not in the range 0-7. Similarly, \07 will not work in that case; to be safe (e.g. if you are writing a preprocessor and combining stuff involving these escape sequences) you should use \007.

These escape sequences use octal (god only knows why they perserved the use of OCTAL in Java) and will let you encode up to Unicode code point 255 (although you can represent numbers up to 511 with three octal digits, AFAIK it won't work; the Java parser will look at \400 as octal sequence \40 followed by 0).

The reason this works is, of course, because the "beep character" - ASCII BEL - has value 7. (Just like 9 is tab, for example.)

Share this post


Link to post
Share on other sites

#include <iostream>
#include <windows.h>

using namespace std;

void Print(int Progression)
{
cout << endl << endl << "\t[";

for(int i = 0 ; i < Progression ; ++i)
cout << "*";

for(int i = Progression ; i < 10 ; ++i)
cout << " ";

cout << "]";
}

void main()
{
float Counter = 0;
float PrevCounter = 0;

int Progression = 0;
cout << endl << endl << "\t[ ]";

for(int i = 30 ; i < 2000 ; i += 10)
{
Beep(i, 100);
Counter = (float)i / 2000.0f;
Counter *= 10;

if((Counter - PrevCounter) > 0.9f)
{
Progression++;
PrevCounter = Counter;
system("CLS");
Print(Progression);
}
}

cout << endl << endl;
Beep(100, 1000);
cout << "\t Boom!" << endl << endl;
}



Fun stuff :)

Share this post


Link to post
Share on other sites
ok now working... heres what i got(this is for dll btw)

#define export extern "C" __declspec (dllexport)
#include <windows.h>
#include <iostream.h>
using namespace std;

//Message Boxes in GM
//C++ Source

//1
export float test1()
{
beep(3,1);
//MessageBox(NULL, "Your system is fried!", "KABLAM!", 0);
}


now if i try to use that it gives me an error but if i remove the keep and place the messagebox it works fine... i get an error while compileing if i use the beep


Compiler: Default compiler
Building Makefile: "C:\WINDOWS\Desktop\dll\Makefile.win"
Executing make...
make.exe -f "C:\WINDOWS\Desktop\dll\Makefile.win" all
g++.exe -c dllmain.cpp -o dllmain.o -I"C:/DEV-CPP/include/c++" -I"C:/DEV-CPP/include/c++/mingw32" -I"C:/DEV-CPP/include/c++/backward" -I"C:/DEV-CPP/include"

In file included from C:/DEV-CPP/include/c++/backward/iostream.h:31,
from dllmain.cpp:3:
C:/DEV-CPP/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
dllmain.cpp: In function `float test1()':
dllmain.cpp:12: `beep' undeclared (first use this function)
dllmain.cpp:12: (Each undeclared identifier is reported only once for each
function it appears in.)

dllwrap.exe --output-def libProject1.def --driver-name c++ --implib libProject1.a dllmain.o -L"C:/DEV-CPP/lib" --no-export-all-symbols --add-stdcall-alias -o Project1.dll

C:\DEV-CPP\BIN\DLLWRAP.EXE: no export definition file provided.
Creating one, but that may not be what you want

Execution terminated

Share this post


Link to post
Share on other sites
Just a scary note,
NOT all computers have the speaker connected inside of there box,

The lazy mother F*ckers at HP and a clone shop didn't connect the internal speakers.

i was using the computer beep as a alarm ( with a flashing screen ) and a sound effect
but because there speaker was not connected and the power safe mode turned off the monator, and they had no computer speakers, no one found out about the alarm until, it was too late, $2700 down the drain.

Be forwarned. !

Share this post


Link to post
Share on other sites

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this