// title: Experiment with roots of unity // author: Muse Score // description: // 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. // code: ( ~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);