«Experiment with roots of unity» by Muse Score

on 28 Jan'23 11:04 in

This is an experiment with roots of unity in supercollider. I took Eulers formula exp(2*pi*I*k/n) = cos(2*pi*k/n)+sin(2*pi*k/n)*I to sonify sums of roots of unity where the sums run through divisors of some numbers.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(

~divisors = {
	arg n;
	~divs = List.newClear(0);
	for( 1, floor(sqrt(n)), {arg i; if(n%i==0,{
			//i.postln;
			~divs.add(i);
		//	(i==n.div(i)).postln;
			if(i==n.div(i),{},{~divs.add(n.div(i))});
		   },{});
		});
	~divs.sort;
	~divs;
};


SynthDef(\rootsOfUnitySum, { |out=0,freq=1,amp=1,n=1,ks=#[1]|
    var l,sigl,sigr,env;


	sigl = SinOsc.ar(freq:0,mul:0);
	sigr = SinOsc.ar(freq:0,mul:0);
	ks.do({arg item,i;
		k = item;
        sigr = sigr+SinOsc.ar(freq:freq*2pi*k/n,mul:amp,phase:0.5*pi);
		sigl = sigl+SinOsc.ar(freq:freq*2pi*k/n,mul:amp);
	});
	env = EnvGen.kr(Env.linen(attackTime: 0.001, sustainTime: 1, releaseTime: 0.01, level: 1.0, curve: 'lin'), doneAction: Done.freeSelf);
	sigr = sigr*env;
    sigl = sigl*env;

	Out.ar(out, [sigl,sigr])
}).add;


~getPbind = { arg n, amps, durs, freq;
    ~nums = ~divisors.value(n);
    r = Pbind(\instrument,\rootsOfUnitySum,
	\amp,amps,
	\dur,durs,
	\freq,freq,
	\n,Pseq([n],~nums.size),
	\ks , Pseq(all{:~divisors.value(n),n<-~nums},1)).trace();
	r
};

~seq = (1..13);
~tau = all{:~divisors.value(n).size,n<-~seq};


~r = Pseq(all{:~getPbind.value(
	  n:n,
	  amps:Pseq(all{:0.5/t,t<-~tau},1),
	  durs:Pseq(all{:0.3333/t,t<-~tau},1),
	freq:220/3),n<-~seq},1);

~s = Pseq(all{:~getPbind.value(
	  n:n,
	  amps:Pseq(all{:0.5/t,t<-~tau},1),
	  durs:Pseq(all{:0.5/t,t<-~tau},1),
	freq:110),n<-~seq},1);

~t = Pseq(all{:~getPbind.value(
	  n:n,
	  amps:Pseq(all{:0.5/t,t<-~tau},1),
	  durs:Pseq(all{:1/t,t<-~tau},1),
	freq:220),n<-~seq},1);

~x = Pseq([
	    Ppar([~t],1),
	    Ppar([~s],1),
	    Ppar([~s,~t],1),
	    Ppar([~r],1),
	    Ppar([~r,~t],1),
	    Ppar([~r,~s],1),
	    Ppar([~r,~s,~t],1),
     ],inf);

);

Pdef(\mplayer, ~x).clock_(TempoClock(100/60)).play;
Pdef(\mplayer, Pn(Event.silent)).fadeTime_(8);
raw 1858 chars (focus & ctrl+a+c to copy)
reception
comments