How to make the hardware beep sound with c++?
Thanks
I tried most things here, none worked on my Ubuntu VM.
Here is a quick hack (credits goes here):
#include
int main() {
system("(speaker-test -t sine -f 1000)& pid=$!; sleep 1.0s; kill -9 $pid");
}
It will basically use system's speaker-test
to produce the sound. This will not terminate quickly though, so the command runs it in background (the &
part), then captures its process id (the pid=$1
part), sleeps for a certain amount that you can change (the sleep 1.0s
part) and then it kills that process (the kill -9 $pid
part).
sine
is the sound produced. You can change it to pink
or to a wav
file.