AWK Music

Sox and OSX are anagrams.

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

This makes sound, but it pretty crude. It plays random square waves for random durations. The BEGIN{} stanza gives a chunk of code for Awk to execute before processing standard input. Sadly I don't have the previous iteration of the script, which used yes | awk '{...}' instead of BEGIN. The third line, wl=400*(0.87055^(int(rand()*10)+1)), takes a bit of explaining. A musical scale is exponential in nature, and this function generates the wavelengths of notes on a musical scale. There is one magic number, 0.87055. This is not a random number or even something found by trial and error. It is the fifth root of 0.5. One half is important because every octave the wavelength doubles or halves. Using the fifth root gives five intervals for each octave, a pentatonic scale. Why five notes? It is really easy to make something that sounds good in the pentatonic scale and really hard for a pair of notes to be dissonant. With a wavelength and a duration for the note, a pair of for loops pumps out a square wave. A and Z make up the low and high values.

Name:
Mail: (not shown)

Please type this: