LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 5705|回复: 17

弱弱地问:怎么样编个程序让机箱发出声音呢?

[复制链接]
发表于 2005-9-13 11:41:16 | 显示全部楼层 |阅读模式
printf(“\007");好象不行!
发表于 2005-9-13 12:01:33 | 显示全部楼层
这样fprintf(stderr, "\007");
或者自己手动flush
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-13 22:54:42 | 显示全部楼层
不行阿,/tmp/ccY2vI4v.o(.text+0x30): In function `main':
beep.c: undefined reference to `flash'
flash()在哪里呢?
回复 支持 反对

使用道具 举报

发表于 2005-9-14 00:01:52 | 显示全部楼层
Post by smallpeg
不行阿,/tmp/ccY2vI4v.o(.text+0x30): In function `main':
beep.c: undefined reference to `flash'
flash()在哪里呢?


$man flash
回复 支持 反对

使用道具 举报

发表于 2005-9-14 09:47:04 | 显示全部楼层
有pc-speaker的驱动,它生成设备文件/dev/pcsp设备文件,可以对其进行编程,这玩意可以模拟声卡发声。
但没有包括进标准内核,需要自己打补丁,重新编译内核。
回复 支持 反对

使用道具 举报

发表于 2005-9-14 16:20:35 | 显示全部楼层
是fflush
回复 支持 反对

使用道具 举报

发表于 2005-9-19 01:22:11 | 显示全部楼层
c中"\a"
回复 支持 反对

使用道具 举报

发表于 2005-9-19 01:57:13 | 显示全部楼层
我晕死了,无话可说...
我啥都没看见!
回复 支持 反对

使用道具 举报

发表于 2005-9-19 10:09:38 | 显示全部楼层
先cat一下/proc/bus/input/devicces
I: Bus=0010 Vendor=001f Product=0001 Version=0100
N: Name="C Speaker"
P: Phys=isa0061/input0
H: Handlers=kbd event2
B: EV=40001
B: SND=6
如果有类似以上信息,说明内核加载了pcspkr模块,是可以支持PC喇叭的。
然后使用如下程序,即可以发声。

  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <linux/kd.h>
  5. #include <stdio.h>

  6. #define ERROR (-1)

  7. main() {
  8.   int fd=open("/dev/tty0",O_RDWR|O_NDELAY);

  9.   if (fd<0) {
  10.     perror("/dev/tty0");
  11.     exit(2);
  12.   }

  13.   /* 125 = 125 milliseconds, or 1/8th of a second;
  14.       0x637 is the number of clock cycles in the standard kernel beep */
  15.   if (ioctl(fd,KDMKTONE,(125<<16)+0x637) == ERROR) {
  16.     perror("/dev/tty0: ioctl");
  17.     exit(2);
  18.   }

  19.   close(fd);
  20. }


复制代码

这个程序很难找,是给内核的维护者Vojtech Pavlik发mail才得到的。

版主请加精吧,谢谢。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-21 15:43:58 | 显示全部楼层
太感谢了,太感动了,很敬业!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表