How to reproduce tone in Linux using C?

I am trying to write a program for randomly creating music based on a simple set of rules. I would like the program to be able to create its own sounds, and not have an audio file for each note. Does anyone know an easy way to do this? It would be nice (but not necessary) for the sound to be a politon, and I would like to get a Linux solution using C.

+6
c linux random audio
source share
3 answers

I suggest you try the PortAudio library. This 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 sine wave, while playing a bunch of sine waves. Since the examples already do 90% of what you need, you should have your sound and work in less than half an hour.

Hint: The best PortAudio documentation is in the header file!

+5
source share

You may try to find a C midi sequencer (e.g. MIDI Sequencer ). Also look at creating formatted .au audio files (for example, see the specifications for .au headers and audio data format). You will not be able to use the .wav format, because the title length is required before playback.

0
source share

Here is an ALSA example that reproduces a pure sine wave tone. Incidentally, I think this also demonstrates why you cannot do it directly against the ALSA library.

0
source share

All Articles