A few months ago it came up that someone was able to get audio to play in my preferred programming language, R. Even better, the piece they orchestrated was the highly litigated "Birthday Song" that was even more recently freed from copyright purgatory. I quickly realized that this was an excellent opportunity to finally get the precision I wanted from the experimental Bach Canon that I had previously composed. So that's what I did!

Old School

You can listen to my original version to while reading my original verbose explanation below:

The Endlessly Rising Canon (Canon a 2, per tonos; Bach's Musical Offering) was made known to me by Douglas Hofstadter's Pulitzer-winning book Godol, Escher, Bach: an Eternal Golden Braid. The canon consists of an eight measure phrase beginning in C minor. "What makes this canon different from any other is that when it concludes-or, rather, seems to conclude-it is no longer in the key of C minor, but now is in D minor… And it is so constructed that this 'ending' ties smoothly onto the beginning again… After six repetitions of the canon it returns to the key of C minor, but now one octave higher." […] Anyone who has played with a record player knows that as the speed of an audio track increases, so does it's pitch. A sound played twice as fast has the same pitch as before, but one octave higher. I exploit this audio-timescale/pitch-modification connection to play the canon in 16 different octaves. I record one iteration of the canon and speed it up digitally by a factor of 2^1/6 or 1.1225 (or 12.25% faster) to get the next iteration of the canon… just as recording a C4 tone and increasing its tempo by a factor of 1.1225 will result in a D4 tone. Repeating this process six times results in the tempo doubling; i.e. a power rule of exponents. With six iterations recorded I am able to paste them together as one audio file and digitally double the tempo to get the next six iterations that are one octave higher. This process was repeated 16 times resulting in the canon being played in 16 different octaves (C4 to C19), with the tempo doubling 16 times (60 bpm to 3932160 bpm ( or 2^16 = 65536 beats per second (bps) ) ). To make the speed/tempo increase smooth throughout the canon, each measure is 2^(1/6*1/8) or 1.01455 times (1.455 %) faster than the previous measure.

New School

I'm going to walk through the code that I used to create this piece in R. The major contributions here are that I had to figure out how to:

create polyphony from two sine waves speed up the a wave's tone while increasing its pitch create mathematically precise accelerando

Warning: You'll need to be able to at least copy/paste code into R to listen to this piece. Also, the audio package doesn't have native Linux support. If someone gets it working key me know.

I worked off of the original StackExchange piece, but it had a very new school style of R coding utilizing the magrittr and dplyr packages. My brain works much more clearly in vanilla R so I converted many of the pieces back to something more familiar to me. For that reason, the code is a bit of a hodge-podge of naming conventions. Also, I code at work all day, so I'm letting my hair down on this one.

First, I loaded the audio library and then I hard-coded the notes and their corresponding numbers that were later used to create the actual sine waves.

library("audio") notes <- c(G2 = -14, Ab2 = -13, A2 = -12, Bb2 = -11, B2 = -10, C3 = -9, Db3 = -8, D3 = -7, Eb3 = -6, E3 = -5, F3 = -4, Fs3 = -3, Gb3 = -3, G3 = -2, Ab3 = -1, A3 = 0, Bb3 = 1, B3 = 2, C = 3, Db = 4, D = 5, Eb = 6, E = 7, F = 8, Fs = 9, Gb = 9, G = 10, Ab = 11) notes.num <- notes + 48

Next I used the almost the exact same make_sine function, except that I removed the last sample from the wave vector. I did this so I would get the desired number of samples and not the desired number plus 1.

make_sine <- function(fre