Using the beep program, it's easy to play simple melodies. Here are the frequencies for some basic notes:
262 C - "middle C"
277 C#
294 D
311 D#
330 E
349 F
370 F#
392 G
415 G#
440 A
466 A#
494 B
To find the frequencies of subsequent notes, simply multiply the highest note you know by 1.0595, and then round up or down as appropriate. For example, 494 * 1.0595 = 523.393, or 523 Hz, which should be the "C" note that's one octave above middle C.
Here, then, is a script that plays a portion of Beethoven's F|r Elise:
The only problem with "beep" is that it's not very efficient. That is, you're consistently calling a program, and as such, the timing might not be absolutely perfect. As I said, Linux is often used for servers, and it's highly likely that other processes will be running at the same time. Therefore, you may experience some delays between notes.
One solution is to include beep's code within your own C program(s). This will definitely speed things up, as the program won't have to be called 400 times to play a tune.
Add www.developer.com to your favorites Add www.developer.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed