Playing beep in C++ (Linux)

user1351781 picture user1351781 · Oct 16, 2012 · Viewed 20.9k times · Source

Possible Duplicate:
Beep on Linux in C

I have been looking for a way to play a simple beep in Linux, but all what I found don't work.

I've tried the \a, \b \7 but anyone play the beep.

I would like to play it without the use of sound libraries, later I will change the beep for a real sound using any library, but right now I'm only interested in play a beep for testing purposes

As I said, I'm using Linux (exactly LMDE) so the easiest way of Windows (include windows.h and Beep()) can't be used.

So how could I implement this? A system call or something like that.

EDIT: I ended doing it in Java and I have it working already.

Answer

Amitd picture Amitd · Oct 16, 2012

Try including ncurses.h

#include <ncurses.h>

beep();

compile with the -lncurses flag

Reference : http://invisible-island.net/ncurses/man/curs_beep.3x.html

Also this question : make sounds (beep) with c++

Edit:

try this command line

sudo sh -c "echo -e '\a' > /dev/console"

Also try the code given at http://www.linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux

int ms = 5000;
int freq = 440;
ioctl(fd, KDMKTONE, (ms<<16 | 1193180/freq));