How do I play a tone in Linux using C?

audio, c, linux, random

Solution

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!

Problem

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.

Original source