// title: Series of numbers // author: Henk Lasschuit // description: // In his book "Schema's voor programmeren" (Diagrams for programming, Kluwer, Deventer, 1988) Andree Hollander introduces a simple algorithm for generating a series of numbers: pick a number, if it is even, divide by 2, else multiply by 3 and add 1. Repeat until the value 1 is reached (or else 4,2,1,4,2,1 will be repeated endlessly). Use the numbers as sound parameters and you have, well, music! // I generated 100 series, starting with 1 to 100. Of the sound in the middle the pitch is controlled by the numbers within a series and the timbre by the starting number. The sound in the left channel is the length of a series (pitch) and the longest series up until now determines the timbre. The sound in the right channel is controlled by the maximum value within a series and the highest value up until now determines the timbre. // code: //series of numbers Server.default.boot; ( SynthDef(\beep, { |freq=440, cutoff=1000, pan=0| Out.ar(0, Pan2.ar(LPF.ar(Saw.ar(freq), cutoff), pan)) }).send(s); ) //from 1 to 100 //while number>1 //if even: divide by 2, else multiply by 3 and add 1 //remember highest value, remember longest series, both with their startnumber //startnumber->cutoff, number-> frequency, pan mid //startnumber->cutoff, highest value -> frequency, pan right //startnumber->cutoff, longest series -> cutoff, pan left ( var highest=1, longest=1, starthighest=1, startlongest=1; var numberbeep, highestbeep, longestbeep; numberbeep=Synth(\beep, [\freq, 200, \cutoff, 200, \pan, 0]); longestbeep=Synth(\beep, [\freq, 200, \cutoff, 200, \pan, -1]); highestbeep=Synth(\beep, [\freq, 200, \cutoff, 200, \pan, 1]); Routine({ for (1, 100, { arg startnumber; var number, length=1, maximum; number=startnumber; maximum=startnumber; (number.asString+" ").post; numberbeep.set(\cutoff, 100*startnumber); while ( {number>1},{ if (number.asInteger.even, {number=(number/2)}, {number=3*number+1}); length=length+1; if (number>maximum, {maximum=number}); numberbeep.set(\freq, 30+number); longestbeep.set(\freq, 75*length); highestbeep.set(\freq, 30+maximum); 0.1.wait; }); if(length>longest, {longest=length; startlongest=startnumber}); if (maximum>highest, {highest=maximum; starthighest=startnumber}); longestbeep.set(\cutoff, 100*longest); highestbeep.set(\cutoff, highest*2); ("length: "+length.asString).post; (" maximum: " + maximum.asString).postln; }); postf("longest series % at % \n", longest, startlongest); postf("highest value % at % \n", highest, starthighest); numberbeep.set(\freq, 30, \cutoff, 10000); longestbeep.set(\freq, 75*longest, \cutoff, 100*startlongest); highestbeep.set(\freq, 30+highest, \cutoff, 100*starthighest); 10.wait; numberbeep.free; highestbeep.free; longestbeep.free; }).play; )