This past weekend, I spent some time honing the script from last blog post into a framework that could be used to give voice to my Little Robots. Okay, so what’s changed since I published that awesome .wav generating perl script? Well, first let’s listen to something rendered by the new script…
You can hear that the sound is far more refined. I took the time to add some basic attack and decay to the sine waveform. Even though it’s one of the most audible changes… it’s probably one of the least significant. One major change from the previous script is the movement of all data to external data files…
Here is the data file that generated the MP3 that you just listened to:
@SONGTITLE:Minuet in G @ALBUMNAME:Let Them Eat Test @ARTIST:Little Robots @YEAR:2011 @GENRE:other &righthand D4,1/4 G3,1/8 A3,1/8 B3,1/8 C4,1/8 D4,1/4 G3,1/4 G3,1/4 E4,1/4 C4,1/8 D4,1/8 E4,1/8 F#4,1/8 G4,1/4 G3,1/4 G3,1/4 &lefthand B2,1/2 A2,1/4 B2,1/2. C3,1/2. B2,1/2. &righthand C4,1/4 D4,1/8 C4,1/8 B3,1/8 A3,1/8 B3,1/4 C4,1/8 B3,1/8 A3,1/8 G3,1/8 F#3,1/4 G3,1/8 A3,1/8 B3,1/8 G3,1/8 A3,1/2. &lefthand A2,1/2. G2,1/2. D3,1/4 B2,1/4 G2,1/4 F#2,1/4 D2,1/4 F#2,1/4 &righthand D4,1/4 G3,1/8 A3,1/8 B3,1/8 C4,1/8 D4,1/4 G3,1/4 G3,1/4 E4,1/4 C4,1/8 D4,1/8 E4,1/8 F#4,1/8 G4,1/4 G3,1/4 G3,1/4 &lefthand B2,1/2 A2,1/4 B2,1/2. C3,1/2. B2,1/2. &righthand C4,1/4 D4,1/8 C4,1/8 B3,1/8 A3,1/8 B3,1/4 C4,1/8 B3,1/8 A3,1/8 G3,1/8 A3,1/4 B3,1/8 A3,1/8 G3,1/8 F#3,1/8 G3,1/2. &lefthand A2,1/2. G2,1/2. C2,1/4 D2,1/4 D2,1/4 G2,1/4 D2,1/4 G0,1/4
You can see, both the notes and metadata about the song are found all in one place, completely apart from the code. At the very top of the file are attributes which are denoted with an ‘@’. Notes are comma separated tuples where the first field is the note itself and the 2nd field is its duration. Notes are divided into sections attributed to instruments (set off by an &). Multiple sections for a single instrument simply append notes.
In this particular example, we have two instruments, one called lefthand and the other called righthand. They simulate the left and right hands when playing the very simplified version of Minuet in G from the Easiest Book of Piano Favorites.
Both the notes and the durations are defined in a file. The notes get mapped to frequencies and the durations get mapped to fractions of beats. In my notation, 1/2 means half note, 1/4 means quarter note, etc… and if it ends in a period, that’s a dotted note.
Like all great projects, this one needed a name… and so I scoured Wikipedia‘s audio/sound entries for the first cool sounding term that I had no real understanding of… and that became the name of the project… Submediant. Even after trying to read the wiki page… I still have no idea what a Submediant is… but I’m sticking to it.