Beep from a C application on Ubuntu 15.10?

时间:2016-08-31 16:54:02

标签: c ubuntu

I have an existing application in C that needs to produce a beep. I tried using printf("\a") and printf("\7") but no sound is produced. Currently, I am using the following snippet:

#include <iostream> 
#include <sys/ioctl.h> 
#include <fcntl.h> 
#include <linux/kd.h>

int freq = 2000;
int ms = 1000;
int fd = open("/dev/console", O_WRONLY);
ioctl(fd, KIOCSOUND, (int)(1193180/freq));
usleep(1000*ms);
ioctl(fd, KIOCSOUND, 0);
close(fd);

Based on beep.c and several other forum answers. Still, it produces no sound.

I've also done the following steps (as per this post) to solve the problem to no avail:

Run gconf-editor and if the desktop | gnome | peripherals | keyboard | bell_mode setting is present then change it from off to on

Run dconf-editor and if the org | gnome | settings-daemon | peripherals | keyboard | bell-mode setting is present then change it from off to on

Add pactl upload-sample /usr/share/sounds/gnome/default/alerts/glass.ogg bell.ogg to the file ~/.xprofile (you need gnome-control-center-data for glass.ogg)

Add [ "$DISPLAY" ] && xset b 100 to the file ~/.bashrc

Also:

uncomment the following in /etc/pulse/default.pa:

load-sample-lazy x11-bell /usr/share/sounds/ubuntu/stereo/bell.ogg

load-module module-x11-bell sample=bell-windowing-system

I saw a separate thread with the alsamixer solution but there doesn't seem to be a 'PC Beep' option that I can see.

What else can I try to produce a beep from my C program?

0 个答案:

没有答案