There are countless ways to create music. In the simplest form, it won’t even require any equipment, as evidenced by beatboxing or a capella. If we move to the computer, it’s pretty much the same situation: audio programming languages have been around for as long as general-purpose high-level languages, and sound synthesis software along with them. And just as with physical equipment, none of that is particularly necessary thanks to sed
. Yes, the sed
, the good old stream editor, as [laserbat] shows in her music generating script.
Providing both a minified and fully commented version of Bach’s Prelude 1 in C major as example, [laserbat] uses a string representation of the sheet music as the script’s starting point, along with a look-up table of each transformed note’s wavelength. From here, she generates fixed length PCM square wave signals of each of the notes, to be piped as-is to the sound card via ALSA’s aplay
or SoX’s play
. To keep things simple enough, she stays within the region of printable characters here, using space and tilde as low and high values respectively, providing highest possible volume at the same time this way.
The concept itself is of course nothing new, it’s how .au
and .wav
files work, as well as these little C lines. And while the fixed note duration takes away some of the smoothness in [laserbat]’s version, adding variable duration might just be a hint too much for a sed
implementation, although we’ve certainly seen some more complex scripts in the past.
[via r/programming]