«Series of numbers» by Henk Lasschuit

on 29 Mar'12 16:59 in series of numbers

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//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;
)
raw 1999 chars (focus & ctrl+a+c to copy)
reception
comments