I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker. My OS is linux.
Thanks. I hope I am clear enough.
http://www.linuxjournal.com/article/6735
This is a link to an article in Linux Journal about programming with the ALSA (Advance Linux Sound Architecture). It contains some example code.
The following information comes from a command-line program called beep, available in Debian. The source code is available through the repositories, and also available here.
There's an ioctl() call with a KIOCSOUND request to the console device that you can use to play sounds through the PC speaker. The snippet is:
ioctl(fd, KIOCSOUND, CLOCK_TICK_RATE/(int)frequency);
to play a sound with frequency frequency, and:
ioctl(fd, KIOCSOUND, 0);
to stop the beep. fd is a file descriptor with write permission to /dev/console, and frequency is the sound frequency, given in hertz. The constant CLOCK_TICK_RATE is related to a timer chip used to create the beep, and in the beep source code has the value 1193180 (hertz). Although this might be different for your system, if my mind is correct, I do remember have seen this same constant on old DOS programs that used the PC speaker.
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