473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Making the computer speaker beep

Hi everyone,

Let's see, now. This question is about the capabilities of ANSI C++. I
want to write and compile code in ANSI C++ that, when compiled, will
make the computer speaker beep; or, at least, SHOULD make the computer
speaker beep. I know that whether the computer speaker actually beeps
or not is largely dependent on the OS I'm using. But I'm not so much
concerned about that (at this stage). I just want to know if ANSI C++
provides for this functionality. I'm only interested in ANSI C++, and
not C++ prior to standardization or non-standard C++. I don't want to
know about workarounds in Assembly or another programming language -
this is strictly an ANSI C++ question.

Any help greatly appreciated.

Cheers,

Deets
Jul 22 '05 #1
19 56528
Anon Email wrote:
Hi everyone,

Let's see, now. This question is about the capabilities of ANSI C++. I
want to write and compile code in ANSI C++ that, when compiled, will
make the computer speaker beep; or, at least, SHOULD make the computer
speaker beep. I know that whether the computer speaker actually beeps
or not is largely dependent on the OS I'm using. But I'm not so much
concerned about that (at this stage). I just want to know if ANSI C++
provides for this functionality. I'm only interested in ANSI C++, and
not C++ prior to standardization or non-standard C++. I don't want to
know about workarounds in Assembly or another programming language -
this is strictly an ANSI C++ question.

Any help greatly appreciated.

There is NO strictly C++ standard API to make and audible beep.

This is platform specific and you may need to use or create a
compatability library to perform this "portably" across all platforms.

Hint - GUI's usually have somw way of doing this.

Jul 22 '05 #2
>Hi everyone,

Let's see, now. This question is about the capabilities of ANSI C++. I
want to write and compile code in ANSI C++ that, when compiled, will
make the computer speaker beep; or, at least, SHOULD make the computer
speaker beep. I know that whether the computer speaker actually beeps
or not is largely dependent on the OS I'm using. But I'm not so much
concerned about that (at this stage). I just want to know if ANSI C++
provides for this functionality. I'm only interested in ANSI C++, and
not C++ prior to standardization or non-standard C++. I don't want to
know about workarounds in Assembly or another programming language -
this is strictly an ANSI C++ question.

Any help greatly appreciated.

Cheers,

Deets



I don't know which compiler you're using but with my Borland 5.5 Standard
Edition compiler, From the tools drop down menu, I select 'Environment
Options', Preferences tab, and I can select the compiler option to "Beep on
completion".

JB
Jul 22 '05 #3
On 22 Nov 2003 19:44:49 -0800, an********@fastmail.fm (Anon Email)
wrote in comp.lang.c++:
Hi everyone,

Let's see, now. This question is about the capabilities of ANSI C++. I
want to write and compile code in ANSI C++ that, when compiled, will
make the computer speaker beep; or, at least, SHOULD make the computer
speaker beep. I know that whether the computer speaker actually beeps
or not is largely dependent on the OS I'm using. But I'm not so much
concerned about that (at this stage). I just want to know if ANSI C++
provides for this functionality. I'm only interested in ANSI C++, and
not C++ prior to standardization or non-standard C++. I don't want to
know about workarounds in Assembly or another programming language -
this is strictly an ANSI C++ question.

Any help greatly appreciated.

Cheers,

Deets


The closest you can get in standard C++, or standard C either for that
matter, is to send the '\a' escape sequence to the standard output,
either the stdout stream or the cout object.

The C++ standard inherits this from C, and since it does not supply a
different definition it inherits the one from the C standard:

"\a (alert) Produces an audible or visible alert without changing the
active position."

On most common desktop systems, it produces a beep from the speaker,
assuming the computer has one.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 22 '05 #4
cout << '\a';
Jul 22 '05 #5
Anon Email escribió:
Let's see, now. This question is about the capabilities of ANSI C++. I
want to write and compile code in ANSI C++ that, when compiled, will
make the computer speaker beep; or, at least, SHOULD make the computer


cout << '\a' << flush;

Regards.
Jul 22 '05 #6
Thanks guys,

So it IS possible, by coding for the specific OS in question? I'm not
concerned about portability (yet), I just want to know if it's
possible using ANSI C++ only. Also, I should have added that I didn't
want to do it via escape sequences - that I wanted to produce an
audible beep at a particular frequency and for a given length (sorry
about that). I know it's possible with non-standard C++, but my
question relates to ANSI C++.

Actually, now I have another question: are the beeps that result from
escape sequences a result of code designated in the C++ standard
header files/ library or are they generated by the IDE? Or perhaps
they're a response of the OS to the code? Basically, I want to know if
"/a", for example, calls some sort of beep routine inherent in
standard C++, and where this routine is stored? Help much appreciated.

Cheers,

Deets
Jul 22 '05 #7
Anon Email wrote:

Actually, now I have another question: are the beeps that result from
escape sequences a result of code designated in the C++ standard
header files/ library or are they generated by the IDE? Or perhaps
they're a response of the OS to the code? Basically, I want to know if
"/a", for example, calls some sort of beep routine inherent in
standard C++, and where this routine is stored? Help much appreciated.


Its a system response and whether that response relies in
the device driver, shell, or somewhere else is defined in
your system documents.

Jul 22 '05 #8
Anon Email wrote:
Thanks guys,

So it IS possible, by coding for the specific OS in question? I'm not
concerned about portability (yet), I just want to know if it's
possible using ANSI C++ only.

Well, the proposed way is quite likely to produce a beep if possible.
You don't get more than that.
Also, I should have added that I didn't
want to do it via escape sequences - that I wanted to produce an
audible beep at a particular frequency and for a given length (sorry
about that). I know it's possible with non-standard C++, but my
question relates to ANSI C++.
Then the answer is "no". The C++ standard doesn't even say that it has
to be a beep, and so it doesn't let you set a frequency or length.
The C++ standard actually doens't say anything except that \a mean
alert. I don't know if it inherits the definition from C, and I don't
have the C89 standard, but C99 only says:

\a (alert) Produces an audible or visible alert without changing the
active position.
Actually, now I have another question: are the beeps that result from
escape sequences a result of code designated in the C++ standard
header files/ library or are they generated by the IDE?
The IDE doesn't generate anything at your program's run time. An IDE is
an environment for editing, debugging and compiling your source code.
Or perhaps they're a response of the OS to the code?
It's not defined by the standard where the alert signal comes from or
how it is generated. It's totally up to the implementation. It might
even be a flashing screen (which most Un*x terminals support to
compensate for a possibly missint speaker) instead of a beep.
Basically, I want to know if
"/a", for example, calls some sort of beep routine inherent in
standard C++, and where this routine is stored? Help much appreciated.


No.

Jul 22 '05 #9
> > Basically, I want to know if
"/a", for example, calls some sort of beep routine inherent in
standard C++, and where this routine is stored? Help much appreciated.


No.


Great answers guys. Sorry for all the questions, but I'm rather
inquisitive. I have another one.

Behind this "/a" escape sequence there has to exist some code, right?
Let's forget the results for the moment - whether or not it produces a
speaker beep, a soundcard beep, a flashing screen etc.. Somewhere in
the ANSI C++ libraries (or whatever) there must exist a directive
(code) that replaces "/a" when the code gets compiled. This directive
must include in it code that tells the OS to produce a beep, etc.. The
directive has to exist, or the operating system wouldn't produce the
response!

Is there a way to "view" this directive (code)? Where does this code
lie? Also, Rolf, would you mind telling me where you got this
information?:

C99 only says:

\a (alert) Produces an audible or visible alert without changing the
active position.

Thanks once again for all your help.

Deets
Jul 22 '05 #10
Anon Email wrote:
> Basically, I want to know if
> "/a", for example, calls some sort of beep routine inherent in
> standard C++, and where this routine is stored? Help much
> appreciated.
No.


Great answers guys. Sorry for all the questions, but I'm rather
inquisitive. I have another one.

Behind this "/a" escape sequence there has to exist some code, right?
Let's forget the results for the moment - whether or not it produces a
speaker beep, a soundcard beep, a flashing screen etc.. Somewhere in
the ANSI C++ libraries (or whatever) there must exist a directive
(code) that replaces "/a" when the code gets compiled. This directive
must include in it code that tells the OS to produce a beep, etc.. The
directive has to exist, or the operating system wouldn't produce the
response!


Right.
Is there a way to "view" this directive (code)? Where does this code
lie?
Well, again that depends on your implementation. The code that does that
may lie somewhere within the standard library. Some implementations of
the standard library come with source code, in which case you could
look how they did it. OTOH, there are implementations that don't do the
beep themselves, but rather just send them to the terminal (or terminal
emulation), which will then do the beep. Then you would have to look
into the source code of that terminal emulation. Note however that this
all will look different for different OSs.
The best you can do is look through API documentations for your target
OS. Most systems will have some function for doing beeps (after all,
that's what usually gets used for \a, too). There might even be a
relatively portable library somewhere that encapsulates the system
specifics for you, but I don't know any, so you would have to search
for that yourself.
Also, Rolf, would you mind telling me where you got this information?:

C99 only says:

\a (alert) Produces an audible or visible alert without changing the
active position.


From ISO/IEC 9899-1999, often simply called the C99 Standard. You can
buy it from the iso or ansi webstore. The pdf version is affordable.
You can also get the C++ Standard ISO/IEC 14882 from there.

Jul 22 '05 #11
Thanks very much for your help.

I don't want to sound like I'm harping on about this. It may sound
like a very trivial question, but it's actually rather important to
me. I'm a semi-beginner programmer trying to decide which programming
language is right for me, and the answer to this question/ these
questions will govern which one I choose.

I want to completely clarify something here. I'll refer to a couple of
quotes:

Start quote 1 (from Rolf Magnus and me):
"
Also, I should have added that I didn't
want to do it via escape sequences - that I wanted to produce an
audible beep at a particular frequency and for a given length (sorry
about that). I know it's possible with non-standard C++, but my
question relates to ANSI C++.


Then the answer is "no". The C++ standard doesn't even say that it has
to be a beep, and so it doesn't let you set a frequency or length.
"
End quote 1

Does this mean to say that there is absolutely NO way of making ANSI
C++ code which, when compiled, will make the PC speaker beep at a user
defined frequency for a user-defined period of time?

Start quote 2 from Gianni Mariani:
"
There is NO strictly C++ standard API to make and audible beep.

This is platform specific...
"
End quote 2

So, in summing up, this cannot be done in ANSI C++. But it can be done
by using non-standard code, right? Am I right in saying that by
"platform specific", Gianni Mariani means using non-standard C++?

Cheers, and many thanks.

Deets
Jul 22 '05 #12


Anon Email wrote:

Does this mean to say that there is absolutely NO way of making ANSI
C++ code which, when compiled, will make the PC speaker beep at a user
defined frequency for a user-defined period of time?


You will be suprised of what is not possible using only Standard C++
In short: everything that has to do with hardware is out of scope
for Standard C++. That eg includes: the keyboard, the monitor, the
screen, USB devices, the printer, the network and among other things
any sound hardware, be it a simple beeper or a sound card.

That doesn't mean that the job in question cannot be done in C++. It
just means it cannot be done with plain vanilla standard C++. You have
to use extensions provided by your compiler vendor for this.

Other things not possible in standard C++ and not related to hardware
includes eg. the file system. C++ doesn't assume a file system, so it
is completely outside Standard C++ if there are functions to manipulate
eg. a directory structure.

In a nutshell: Standard C++ concentrates on things you most likely will
find on every computer. So if you want to know if something is in Standard
C++ make a simple test: Imagine your microwave ofen. There is a microprocessor
in it controlling that whole device. Is it likely that this 'computer
system' does have the capability you want a function for? If the
answer is 'yes' (this computer eg. has some memory. It also has ways
to communicate with the user in the form of some keys and a display)
then it is likely that the function you are seeking for is in Standard C++.
For a cross check you can imagine another computer: The computer controlling
the cross lights down the street. Same question. If the answer is still yes ...

Most computers worldwide don't reside on a desktop. They are built into
devices like: cars, video records, TV-sets, washing machines etc...
C++ in it's Standard form addresses the common subset of functionality
of all those computers.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #13
Thanks, Karl. That's a really good answer! It makes complete sense.

Quote:
"
That doesn't mean that the job in question cannot be done in C++. It
just means it cannot be done with plain vanilla standard C++. You have
to use extensions provided by your compiler vendor for this.
"

Doesn't it sort of defeat the purpose to use extensions when coding in
C++? I mean, what's the point of having an ANSI standard if you're
going to use extensions?

Cheers,

Dietrich
Jul 22 '05 #14

"Anon Email" <an********@fastmail.fm> wrote in message
news:83*************************@posting.google.co m...
Thanks, Karl. That's a really good answer! It makes complete sense.

Quote:
"
That doesn't mean that the job in question cannot be done in C++. It
just means it cannot be done with plain vanilla standard C++. You have
to use extensions provided by your compiler vendor for this.
"

Doesn't it sort of defeat the purpose to use extensions when coding in
C++? I mean, what's the point of having an ANSI standard if you're
going to use extensions?


Because typically the bulk of an application can be done
with standard code. This is the 'common denominator' which
has an international standard defining it, by which a
program's behavior is specifically defined, regardless
of target platform. IMO a Good Thing(tm).

It's usually advised here to clearly identify and isolate
those parts of a program which are platform-specific, so
that porting is as straightforward and easy as possible.

-Mike
Jul 22 '05 #15
Anon Email wrote:

Thanks, Karl. That's a really good answer! It makes complete sense.

Quote:
"
That doesn't mean that the job in question cannot be done in C++. It
just means it cannot be done with plain vanilla standard C++. You have
to use extensions provided by your compiler vendor for this.
"

Doesn't it sort of defeat the purpose to use extensions when coding in
C++? I mean, what's the point of having an ANSI standard if you're
going to use extensions?


The point is, that large parts of most programs aren't tied in any way
to any platform. Eg. I have worked on a library doing solid modelling
(in short it means: applying logical operations such as union or
difference on geometric objects). It's pure math and data structures
with nothing platform specific in it. Therefore it can be done in
plain vanilla standard C++.
But using this library in a program which does eg. graphical output
would mean: I need to use platform specific extensions to bring
the results of the solid engine on the screen. I don't have
a problem with that, since such an application would have a very
different look and feel depending on the platform I target it to.
It looks and operates differently on Windows then it would do
on VAX/VMS or on Unix using an X11 output device. That's OK
for me, since every platform has a different user interface paradigma
and I would taylor the application to it to make it easy for my users
to use it. But the core, the solid engine, will be the same on every
platform.

And this is typical for many programs. The core is relatively independent
of any platform specifics. It's mostly in the area where your program has
to interact with the outside world that extensions are used.

If you are looking for a 'crate once - run anywhere' solution then C
or C++ might not be what you are looking for. Granted, there are
input/output facilities built into standard C++, but IMHO for defining
an interactive program (not to mention a GUI) they are much to limited
and you will reach the border very quickly. For some programs this is
not a problem, but if you target your program to the broad masses this
is often unacceptable.
Java takes a different approach. In overcoming the limitations and differences
of different platforms it simply defines it's own computer. There needs
to be a layer which emulates that artifically defined computer on the real
hardware/operating system. But once that emulation is done, all Java programs
will run on that hardware/OS combination identical to how they run on
a different hardware/OS. Of course they have to! Since from the point of
view of the Java program it is always the same computer it is running
on. The Java program doesn't notice that this computer is emulated :-)
(That is: theoretically. Rumour says that the Java paradigm 'create once
run everywhere' is not to be taken literally :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #16
Thanks, Karl and Mike.

To Karl: I have done some Java programming - in fact, I probably know
more Java than C++. I liked the feel of programming in Java, but I
found the results somewhat...clunky. It seems that Java is even
further removed from the hardware layer. The type of programming I
eventually want to do will involve accessing hardware...OK, I want to
do audio programming! I don't want restrictions; I want to be able to
produce code that makes the speaker beep at a defined frequency for a
period of time! (Actually, as an aside, I managed to code the tune to
"Princes Waltz" for my PC speaker using...QBasic!)

I know this is probably outside the scope of this forum (sorry), but
can someone tell me if, in terms of programming audio, C++ is the
right choice for me? I want to write audio applications. I just spent
about $70 on a Bjarne Stroustrup guide to C++...will this turn out to
be a waste of money?

Cheers,

Deets
Jul 22 '05 #17
Anon Email wrote:

Thanks, Karl and Mike.

To Karl: I have done some Java programming - in fact, I probably know
more Java than C++.
I though so :-)
I liked the feel of programming in Java, but I
found the results somewhat...clunky. It seems that Java is even
further removed from the hardware layer.
Now you know why.
The type of programming I
eventually want to do will involve accessing hardware...OK, I want to
do audio programming! I don't want restrictions; I want to be able to
produce code that makes the speaker beep at a defined frequency for a
period of time! (Actually, as an aside, I managed to code the tune to
"Princes Waltz" for my PC speaker using...QBasic!)

I know this is probably outside the scope of this forum (sorry), but
can someone tell me if, in terms of programming audio, C++ is the
right choice for me?
Sure. Why not?
It's just that not anything can be done with Standard C++ facilities.
But there is nothing wrong with using system specific extensions if:
* they are the only means to do the job
* there is no Standard alternative available.
So I think you are in good company, if you make your PC beep and
use extensions for that.
I want to write audio applications. I just spent
about $70 on a Bjarne Stroustrup guide to C++...will this turn out to
be a waste of money?


Don't think so.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #18
an********@fastmail.fm (Anon Email) wrote:
To Karl: I have done some Java programming - in fact, I probably know
more Java than C++. I liked the feel of programming in Java, but I
found the results somewhat...clunky. It seems that Java is even
further removed from the hardware layer. The type of programming I
eventually want to do will involve accessing hardware...OK, I want to
do audio programming! I don't want restrictions; I want to be able to
produce code that makes the speaker beep at a defined frequency for a
period of time! (Actually, as an aside, I managed to code the tune to
"Princes Waltz" for my PC speaker using...QBasic!)
Unless you are writing device drivers for audio cards, you are always
going to be accessing an API somewhere, not hardware. Windows has an
API called DirectSound, and you can access it in many languages, not
just C++. You should choose the platform and API you will be using
first (i.e. Windows and DirectSound), and then choose the language you
want.
I know this is probably outside the scope of this forum (sorry), but
can someone tell me if, in terms of programming audio, C++ is the
right choice for me? I want to write audio applications. I just spent
about $70 on a Bjarne Stroustrup guide to C++...will this turn out to
be a waste of money?


If you have special algorithms you need written to process sounds, you
might want to use C++ because it lets you compile native code. C++
will not give you a "lower level" access to any APIs, though, just
(probably) more control over program structure and execution, and
better performance if you do a lot of computation.

--
Dave O'Hearn
Jul 22 '05 #19
Thanks heaps, guys. I actually don't have any more questions (for the
moment)! Now to go and check out DirectSound! (Yes, I'm on Windows...)
Looking forward to receiving "The C++ Programming Language," by Byarne
Stroustrup, in the mail.

Cheers,

Dietrich
Jul 22 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jgcrawford | last post by:
G'day, I'm writing a ringtone manager for nokia ringtones and I'd like to be able to play the ringtone on the PC speaker. I've had some success in DOS with turbo C and its sound(), delay() and...
1
by: Hai Ly Hoang | last post by:
Hi, I want to make a beep (like MS-DOS beep, not a beep from sound-card). How to do that ? Thanks
2
by: John S. Ford, MD | last post by:
I'm familiar with the beep function but is there any function that enables you to determine the pitch and duration of a tone produced by the computer's speaker? John
1
by: strancho | last post by:
hi guys: i am rather new to C++. By using beep(hz, duration), I figured out a way to drive computer speaker. However, my project requires me to create sound from the sound card. Do you happen...
14
by: v4vijayakumar | last post by:
In computer based, two player, board games, how to make computer play? Are there any formal ways to _teach_ computer, to choose best possible move? I know this is kind of off-topic here. Please...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.