c - Linux 中 C 的 sound() 和 nosound() 函数?

标签 c linux audio

谁能告诉我如何在 Linux 中使用 C 的 sound() 和 nosound() 函数?我可以通过包含 dos.h 头文件在 Windows 中使用它,但我在 Linux 上,所以我不能在那里使用 dos.h。

最佳答案

不幸的是,似乎没有简单的解决方案。你可以定义一个蜂鸣函数,比如

/* beep.c - for Linux and DOS/Windows */

#include <stdio.h>
#include <stdlib.h>
#ifdef __DJGPP__
#include <dos.h>
#include <pc.h>
#endif
#define ESC 27

void beep (int frequency, int duration)
{
#ifdef __DJGPP__
  sound (frequency);
  delay (duration);
  nosound ();
#else  /* Linux */
  FILE *tty;
  if ( NULL == (tty = fopen ("/dev/console", "w")) ) {
    fprintf (stderr, "Cannot write to /dev/console!\n" );
    exit (1);
  }
  fprintf(tty, "%c[10;%d]%c[11;%d]\a", ESC, frequency, ESC, duration);
#endif
}

int main (int argc, char *argv[])
{
  int frequency, duration;
  if (argc != 3) {
    fprintf (stderr, "Usage: beep <frequency> <duration>\n" );
    exit (1);
  }
  frequency = atoi (argv [1]);
  duration = atoi (argv [2]);
  beep (frequency, duration);
  return (0);
}

/* end of beep.c */

Linux 中没有 dos.h 等价物。您需要从 linux 中可用的内容中探索

检查 here

关于c - Linux 中 C 的 sound() 和 nosound() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23173025/

相关文章:

python - 如何在不使用 aptitude 或 apt-get 的情况下在 linux 中安装 lxml

iphone - 如何在iPhone中以特定频率放大声音?

php - 即时获取 YouTube 音频流

c - 如何定义字符串数组的结尾

c - 为指向结构的指针分配空间

linux - Unix shell 脚本 : Update timestamp on all sub-directories and sub-files, 包括带空格的脚本

linux - 进程在 sleep 状态下使用 nohup 运行

qt - 在 Qt 中执行 ffmpeg 以裁剪音频

c - 带 lwip 的网络服务器(Cortex M3、Stellaris LM3S6965 评估板)

c - 使用 gcc 包含目录未正确链接