Intrigued by a recent XKCD comic regarding the Collatz Sequence, I whipped up a fairly simple ChucK program that runs through the Collatz sequences of increasing odd starting points and assigns the raw number in each sequence as the frequency of an oscillator. I few spatial effects are there as well, to make it a bit more listenable than just a simple oscillator running. I limited the output to (20,1000) Hz because anything else drops straight to one Hz or begins to create undesireably high pitched frequencies that don’t provide much of anything interesting.
I think I’ve heard this familiar-sounding sequence of tones before, but I can’t imagine where. If it has been in something I’ve heard before, I’m sure it was coincidental because there are only so many whole number frequency sequences to be made! :P
ChucK code follows:
21 => int fo;
fo => int f;
fo => int fmax;
0 => int loopcount;
0 => int looplength_timer;
0 => int looplength;
SawOsc osc1 => LPF lp => PRCRev r;
0.1 => r.mix;
f => osc1.freq;
0.4 => osc1.gain;
SinOsc bg => r;
0.025 => bg.gain;
fmax => bg.freq;
SinOsc lpm => blackhole;
0.183 => lpm.freq;
50 => lpm.gain;
r => dac;
//Loop until process is terminated
while(1)
{
//Print values to terminal
<<< "f=",f, "\t\tfo=",fo,"\t\tfmax=",fmax,"\t\tlooplength_timer=",looplength_timer,"\t\tlooplength=",looplength,"\t\tloopcount=",loopcount >>>;
183::ms => now;
f => osc1.freq;
if(looplength > 0) { (((looplength $ float) / (looplength_timer $ float)) / (looplength $ float)) * 0.05 => bg.gain; }
else { 0.01 => bg.gain; }
lpm.last() + f + 60 => lp.freq;
if(f%2 != 0) { f*3 + 1 => f; }
else { f / 2 => f; }
if(f < 20) { fo => f; }
if(f > 1000) { fo => f; }
if(f == fo) { looplength_timer => looplength; 0 => looplength_timer; loopcount++; }
if(f > fmax) { f => fmax; fmax => bg.freq; }
if(loopcount == 4) { fo + 2 => fo; fo => f => fmax => bg.freq; 0 => looplength_timer => looplength => loopcount;}
looplength_timer++;
}