Playing beep in C++ (Linux) [duplicate]

天涯浪子 提交于 2019-12-01 08:57:00

问题


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.


回答1:


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));



回答2:


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

Also there is a beep command-line tool that you should be able to install using your distributions package management system.

It should cause the terminal to emit a beep.
I've tested it on a few Linux distributions and seems to work correctly.



来源:https://stackoverflow.com/questions/12919378/playing-beep-in-c-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!