在C ++中发出哔哔声(Linux) [英] Playing beep in C++ (Linux)

查看:78
本文介绍了在C ++中发出哔哔声(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用C语言在Linux上浏览

我一直在寻找一种在Linux中播放简单蜂鸣声的方法,但是我发现的所有方法都不起作用.

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

我已经尝试了\ a,\ b \ 7,但是有人发出了哔声.

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

正如我所说,我使用的是Linux(完全是LMDE),因此无法使用Windows的最简单方法(包括windows.h和Beep()).

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.

我结束了用Java进行操作,并且已经可以使用它了.

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

推荐答案

尝试包括ncurses.h

Try including ncurses.h

#include <ncurses.h>

beep();

使用-inccurses标志进行编译

compile with the -lncurses flag

参考资料: http://invisible-island.net/ncurses/man/curs_beep.3x.html

也是这个问题:使用c ++发出声音(哔)

修改:

尝试此命令行

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

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

也尝试在 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));

这篇关于在C ++中发出哔哔声(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆