How to use PC speaker in linux for c/c++ programming ? Can I control the beep time and freq?
The easiest way to make the motherboard beep is to open a terminal and type "echo -e \\a". However, that may not work on some Linux systems. To fix the issue, try running "modprobe pcspkr" in a terminal with Root privileges. Now, try running "echo -e \\a".
pcspkr : PC-Speaker driver. snd_pcsp : PC-Speaker driver.
beep allows the user to control the pc-speaker with precision, allowing different sounds to indicate different events. While it can be run quite happily on the command line, it's intended place of residence is within shell/perl scripts, notifying the user when something interesting occurs.
Taken from here:
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/kd.h>
int main(void)
{
int freq[] = { /* C D E F G A B C */
523, 587, 659, 698, 784, 880, 988, 1046 };
int i;
for (i=0; i<8; i++)
{
ioctl(STDOUT_FILENO, KIOCSOUND, 1193180/freq[i]);
usleep(500000);
}
ioctl(STDOUT_FILENO, KIOCSOUND, 0); /*Stop silly sound*/
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With