Play sound in C ++ (Linux)

Possible duplicate:
Beep on Linux in C

I was looking for a way to play a simple beep in Linux, but everything I found does not work.

I tried \ a, \ b \ 7, but someone was playing a beep.

I would like to play it without using sound libraries, later I will change the sound signal for real sound using any library, but now I'm only interested in the sound signal for testing

As I said, I use Linux (exactly LMDE), so the easiest way for Windows (including windows.h and beep ()) cannot be used.

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

EDIT: I ended up doing this in Java, and I already have a job.

+2
source share
2 answers

Try enabling ncurses.h

#include <ncurses.h> beep(); 

compile -lncurses flag

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

Also this question: make sounds (sound signals) using C ++

Edit

try this command line

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

Also try the code provided 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)); 
+2
source

Have you tried echo -e "\a" ?
You can also try: echo -ne '\007'

There is also a beep command-line tool that you can install using your distribution package management system.

This should cause the terminal to sound an alarm.
I tested it on several Linux distributions and it seems to work correctly.

-1
source

All Articles