«Re: The Sounds of Fibonacci» by ttsesmetzis

on 18 Mar'14 12:42 in code forkmathematicsresearch

Pisano periods for rythmic patterns.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
b = Buffer.read( s, Platform.resourceDir +/+ "sounds/a11wlk01.wav" );

(
SynthDef(\playBuf, {| out = 0, buf = 0, amp = 0.2, pan = 0.0, dur = 0.2, gate = 1 startPos = 0 |
	var sig, env;
	env = EnvGen.ar( Env.sine( dur ), gate, amp, doneAction: 2 );
	sig = PlayBuf.ar( 
		1, 
		buf, 
		BufRateScale.ir( buf ), 
		1, 
		startPos * BufFrames.ir( buf )
	);
	OffsetOut.ar(out, Pan2.ar( sig * env, pan ) )
}).add
)

(
Pn(
	Plazy({
		var divisor = 3.rrand( 9 ), repeats = 10.rrand( 20 );
		var pisano, size, starts, durs, pans, amps;

		pisano = Array.pisano( divisor );
		size = pisano.size;
		starts = { 1.0.rand } ! size ;
		durs = { 0.03.rrand( 0.08 ) } ! size;
		pans = { 1.0.rand2 } ! size;
		amps = { 0.05.rrand( 0.8 ) } ! size;

		"Divisor: %\t pisano period is of length: %\n".postf( divisor, size );

		Pbind(
			\instrument, \playBuf,
			\pisano, Pseq( pisano, repeats ),
			\buf, b,
			\amp, Pindex( amps, Pkey( \pisano ) ),
			\dur, Pindex( durs, Pkey( \pisano ) ),
			\pan, Pindex( pans, Pkey( \pisano ) ),
			\startPos, Pindex( starts, Pkey( \pisano ) )
		)
	}),
	inf
).play
)

b.free

//////////////////////////////////////////////////////////////////////
// + Array { 
// 	// The pisano period for the given integer.
// 	*pisano { | divisor = 3 |
// 		var list, lastPair, sum;
// 		if ( divisor.isInteger.not or: { divisor < 0 } ){
// 			"The divisor must be a positive integer".throw;
// 		};
// 		list = List[ 0, 1 ];
// 		while {
// 			lastPair = list.keep( -2 );
// 			sum = lastPair.sum;
// 			sum != 1 or: { lastPair.last != 0 }
// 		}{
// 			list.add( sum % divisor );
// 		};
// 		^ list.array.drop( -1 )
// 	}

// }
//////////////////////////////////////////////////////////////////////
raw 1772 chars (focus & ctrl+a+c to copy)
reception
comments