I'm trying to write a program to randomly generate music based on a simple set of rules. I would like the program to be able to generate its own sounds, as opposed to having a file with audio for each note. Does anyone know a simple way of doing this? It would be nice (but not essential) for the sound to be polytonal, and I would like a solution for Linux, using C.
I suggest you try the PortAudio library. It is a lean cross-platform library that abstracts the audio-output functionality.
It comes with a bunch of small examples. One of them plays a single sine-wave, one plays a bunch of sine-waves at the same time. Since the examples already do 90% of what you need you should have your audio up and running in less than half an hour.
Hint: The best documentation of PortAudio is in the headerfile!
Here is an ALSA example that plays a pure sine-wave tone. Accidentally, I guess, it also demonstrates why you might not want to do this directly against the ALSA library.
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