Created
April 30, 2016 00:35
-
-
Save erstwhile/c8d4a1fecfcd5a19b2f458856e522791 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
/* | |
boot six servers to load-balance the audio rendering across cpu cores | |
*/ | |
~z = (1..6).collect({|x| Server.new("xs"+x,NetAddr("127.0.0.1",9989-x));}); | |
~z.collect(_.boot); | |
~z.collect(_.makeWindow); | |
) | |
( | |
/* | |
define an FM Synthesis instrument | |
*/ | |
~synths = { | |
~z.collect({|z| | |
SynthDef("waves0",{|freq=100,par=#[1,1,1,1],atk=1, rel=1, sus=1,pma=1, amp=0.005, gate=0, w=1 ,p=0, pm=1,mo=0,out=0,f1=1| | |
var parr = p,xar,phasemod, | |
pn = ((1-(parr))+(par[0..2]*parr)), sin,car; | |
xar = XLine.ar(pma,1,w); | |
amp = amp/(freq+24); | |
freq = freq * pn; | |
phasemod = (SinOsc.ar(freq*(pm*4),0,1-mo).cubed*pi*(XLine.ar(0.5,0.25,w/8)-0.25)); | |
car = SinOsc.ar(freq,phasemod,0.5,0.5)*pn; | |
sin = SinOsc.ar(freq*pm,phasemod,1)*XLine.ar(f1,1,w/8)*(mo.pow(xar)); | |
sin = sin + car; | |
sin = (sin * 2pi).cos; | |
sin = LeakDC.ar(sin) * amp * (XLine.ar((freq.log2+4).sqrt*2 ,1,1/3)); | |
OffsetOut.ar(out,Mix.ar(Pan2.ar(sin,[-0.75,0,0.75])) * EnvGen.ar(Env.perc(atk,rel,1,sus),gate, doneAction:2) );}).send(z); | |
}); | |
}; | |
~synths.(); | |
) | |
( | |
/* | |
the set of pitches which will be used in the composition | |
just-intonation major thirteenth chord | |
5th overtone is approximated via the 11th overtone (121/24) interval | |
*/ | |
~pitch = {|x,p,xf| | |
var f = 121/24, tf = 3*f, | |
fr = [1,f/4,3/2,tf/8,9/4,tf*3/16,2*f/3].permute(((p*~offset.nextPowerOfTwo.half.sqrt)+(~offset.mod(~offset.nextPowerOfTwo.half))).asInt).rotate(((~x*p.abs.nextPowerOfTwo/2)/(~x.asInt.nextPowerOfTwo.half.sqrt)).asInt)[0..4].sort; | |
//modulation via the interval of an "imperfect fifth" (121/81) | |
fr = fr * (([1,1,1]*.x[1.5,1.5,1.5,121/81])[0..(12*p.abs).floor.asInt].product/1.5); | |
fr = 2.pow(fr.log2.mod(2)); | |
fr=fr*.x(2.pow((-1..4))); | |
fr.sort.foldAt((x*fr.size)+~ck.(x,xf)); | |
}; | |
/* | |
Carotid-Kundalini function as described in Clifford Pickover's "Chaos in Wonderland" | |
~ck function takes a values c (-1 to 1) and a natural number i | |
This function gives the overall structure for the piece + determines note-by-note content | |
*/ | |
~ck = {|c,i| | |
var out = (c * c.acos *i).cos; | |
//(just in case an out of range value is sent to the function, check for NaN and return an arbitrary value so audio inputs don't blow up) | |
(out.isNaN).if({"NaN: "+~x.postln;out=0.5}); | |
out; | |
}; | |
/* | |
player function, executed on every beat | |
*/ | |
~player = {|x,d| | |
var l = 2.pow(x.log2.ceil).asInt, xl = x.mod(l.half)/l.half, xf = x.factors.first,xc, c = (2*xl)-1,pc= c-(1/l).clip(-1,1), | |
freq,sn,slope,pma,xb=x.factors[0..((1-c.abs)*x.factors.size).floor.asInt].product, | |
cxf,mo,amp,pm,xbfs = xb.factors.size,atk, | |
xflr = x.factors.last.sqrt.half.clip(2,384/d.size); | |
xc=c; | |
~xc = xc; | |
((x.isPrime).and(~offset > 2.pow(20))).if({d=[]}); | |
d.collect({|i| | |
c=xc; | |
c=~ck.(c,xb*i); | |
pc=~ck.(pc,xb*i); | |
slope = l*(c-pc); | |
cxf = ~ck.((2pi*slope/xf).atan.cos,x/xb); | |
pm = [1,2,3,4,6,8].foldAt(xbfs.half.floor+(6*~ck.(cxf,xb/xf).abs.floor).mod(x.factors.size)); | |
pma = 2.pow((slope/xb.sqrt).atan.sin*3); | |
freq = ~pitch.(c,xc,x/xb) * ~fr; | |
mo = (pi.half *(xb/x).sqrt).sin*(0.8.pow(xf/x)); | |
atk =(~density * xflr * ~w * (xf/x))+(1/freq); | |
sn=[\out,0, | |
\pm,pm, | |
\mo,mo.abs/pm.sqrt, | |
\sus, ((((xb/xf).log2).pow(1-(xb/x)).neg/(4*(4.pow(4/xf))))), | |
\rel,(~density * xflr * ~w)+(32*~w), | |
\atk,atk, | |
\pma, pma.reciprocal, | |
\amp, ~amp*2.pow((~ck.(cxf,x/xb)*2pi).atan.sin.abs*3)/(6*pm.sqrt.sqrt), | |
\w,((mo.abs.acos.sin).squared * ~w * pma.pow((1-c).abs*c.sign.neg) * xf).clip(atk,~w*xflr), | |
\f1,pma.reciprocal.half.nextPowerOfTwo, | |
\p,(~w.reciprocal*xbfs.sqrt.nextPowerOfTwo)/(freq*64), | |
\par,((freq > ~fr).and(x.isPrime==false)).if({[-4,4,1,-1].permute(x)/pm.sqrt},{([-2,2,0,0]+(x.isPrime==true).if({[0,0,1,-1]},{[0]})).permute(x)/pm.sqrt}), | |
\freq,freq, | |
\gate,1]; | |
Synth("waves0",sn,~z.wrapAt(~x+i)); | |
}); | |
}; | |
) | |
( | |
~start = { | |
~r =Routine { | |
~dur.asInt.do({|x| | |
~x = (~x +1); | |
~player.((~x+~offset).asInt,~i); | |
[~w*2,0].wrapAt(x).wait; | |
}); | |
}; | |
~r.play; | |
}; | |
) | |
//Soundfonts Ruined Computer Music | |
( | |
//set frequency, tempo, other params | |
~fr = 11.pow(3)/24; | |
~w = 8/121; | |
~i = [1]; | |
~density = 1; | |
~amp=1.5; | |
//stop any existing sequences / cancel playing sounds | |
~r.stop; | |
~z.collect(_.freeAll); | |
Routine { | |
~dur = 2.pow(16); | |
~offset = 2.pow(16); | |
~x=0; | |
~start.(); | |
}.play; | |
) | |
//when x is 2/3 the slope of cos(x * acos(x) * i) is zero for all integer values of i | |
( | |
~dur = 2.pow(16); | |
//stop any existing sequences / cancel playing sounds | |
~r.stop; | |
~z.collect(_.freeAll); | |
//set frequency, tempo, other params | |
~fr = 11.pow(3)/24; | |
~w = 8/121; | |
~i = [1]; | |
~density = 1; | |
~amp=1.8; | |
~offset = 2.pow(24); | |
//start position, 5/6ths through, 2/3 on x axis, the point at which all slopes are zero | |
~x=(~offset*5/6).asInt; | |
~start.(); | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment