{
   "name" : "click clack toot // fm-grains",
   "author" : "_Lf0",
   "description" : "/*\r\n clicks and ambience. click clack tooot.....\r\n   partly loud clicks...\r\n\r\n i tried to practice granular synthesis but failed in the end to make\r\n nice randomized modulation envelopes. \r\n*/",
   "ancestor_list" : [],
   "labels" : [
      "fm grains envelope modulation"
   ],
   "code" : "/*\r\n clicks and ambience. click clack tooot.....\r\n   partly loud clicks...\r\n\r\n i tried to practice granular synthesis but failed in the end to make\r\n real nice randomized modulation envelopes. \r\n\r\n flo.huth\r\n \r\n*/\r\n\r\ns.boot;\r\n\r\n(\r\n~r=Routine{\r\n\t1.do{\r\n\r\n\t\t~hall = Bus.audio(s,2);\r\n\t\t~main = Bus.audio(s,2);\r\n\r\n\r\n\t\t~a = Routine{ var n,i,a,b;\r\n\r\n\t\t\tn= 3;\r\n\r\n\t\t\t~arrays = Array.new(n);\r\n\r\n\t\t\ti = 0;\r\n\r\n\t\t\tn.do{\r\n\r\n\t\t\t\ti=i+1;\r\n\r\n\t\t\t\ta = Buffer.alloc(s,512);\r\n\t\t\t\tb = Array.fill(i,{1/i});\r\n\r\n\r\n\t\t\t\ta.sine1(b);\r\n\r\n\t\t\t\t~arrays.add(a);\r\n\r\n\t\t\t}\r\n\t\t}.play;\r\n\r\n\t\t0.5.wait;\r\n\r\n\t\tSynthDef(\\mainOut,\r\n\t\t\t{\r\n\t\t\t\targ gate,amp,ffreq=24000,q=0,dist=1;\r\n\r\n\t\t\t\tvar in,mix,out;\r\n\r\n\t\t\t\tin = In.ar(~main,2);\r\n\r\n\t\t\t\tmix = in*amp;\r\n\r\n\r\n\t\t\t\tmix = CompanderD.ar(mix,0.92,0.9,1,0.1,0.1);\r\n\r\n\t\t\t\tmix = Limiter.ar(mix,1);\r\n\r\n\t\t\t\tOffsetOut.ar(0,mix);\r\n\t\t\t\t//OffsetOut.ar(3,mix);\r\n\t\t\t}\r\n\t\t).add;\r\n\r\n\t\tSynthDef(\\hall,\r\n\t\t\t{\r\n\t\t\t\targ t_gate=1,amp,size,t60,att,dec;\r\n\r\n\t\t\t\tvar in,efx,mix,env;\r\n\r\n\t\t\t\tin = In.ar(~hall)*amp;\r\n\r\n\t\t\t\t//efx = FreeVerb1.ar(in,size);\r\n\t\t\t\tefx = JPverb.ar(in,t60,0,size);\r\n\r\n\t\t\t\t//env = EnvGen.kr(Env.asr(att,1,dec),gate:t_gate,doneAction:0);\r\n\r\n\t\t\t\tefx = efx;\r\n\r\n\t\t\t\tOut.ar(~main,efx);\r\n\r\n\t\t\t}\r\n\t\t).add;\r\n\r\n\t\tSynthDef(\\fmGrain,\r\n\t\t\t{\r\n\t\t\t\targ gate=1,trigger,dense,offset,freq,modFreq,size,wave,mul,index=1,\r\n\t\t\t\tgAtt=0.001,gDec=0.4,\r\n\r\n\r\n\t\t\t\tbPoints = #[0,1,1,1,1,1,1,1,1,1,1,0],\r\n\t\t\t\tbTimes = #[1,1,1,1,1,1,1,1,1,1,0],\r\n\r\n\t\t\t\tmPoints1 = #[1,1,1,1,1], mTimes1 = #[1,1,1,1],\r\n\r\n\t\t\t\tmPoints2 = #[1,1,1,1,1], mTimes2 = #[1,1,1,1];\r\n\r\n\r\n\t\t\t\tvar rand1,rand2,imp, osc, win, env, mix;\r\n\r\n\t\t\t\trand1 = EnvGen.kr(Env.new(mPoints1,mTimes1,\\exp),gate:gate);\r\n\r\n\t\t\t\trand2 = EnvGen.kr(Env.new(mPoints2,mTimes2,\\exp),gate:gate);\r\n\r\n\t\t\t\timp = Select.ar(K2A.ar(trigger),\r\n\t\t\t\t\t[\r\n\t\t\t\t\t\tImpulse.ar(dense*rand1,[0,offset]),\r\n\t\t\t\t\t\tDust.ar(dense*rand1)\r\n\t\t\t\t]);\r\n\r\n\t\t\t\twin = EnvGen.ar(Env.new([0,1,0],[((dense.reciprocal/size)*rand1)*gAtt,\r\n\t\t\t\t\t((dense.reciprocal/size)*rand1)*gDec]),gate:imp);\r\n\r\n\t\t\t\tosc = Osc.ar(wave,modFreq);\r\n\r\n\t\t\t\tosc = Osc.ar(wave,freq,(osc*index*rand2));\r\n\r\n\t\t\t\t//osc = Mix.ar(osc);\r\n\r\n\t\t\t\t//osc = BPF.ar(osc,TRand.ar(60,12000,imp),LFNoise2.kr(1).linlin(-1,1,0.5,1));\r\n\r\n\t\t\t\tosc = Pan2.ar(osc,LFNoise2.kr(TRand.kr(0,4.0,gate)));\r\n\r\n\t\t\t\tenv = EnvGen.ar(Env.new(bPoints,bTimes),gate:gate,doneAction:2);\r\n\r\n\t\t\t\tmix = (osc*win)*env;\r\n\r\n\t\t\t\tmix = HPF.ar(mix,90);\r\n\r\n\r\n\t\t\t\tOffsetOut.ar(~main,mix.scope);\r\n\t\t\t\tOffsetOut.ar(~hall,mix*0.2);\r\n\t\t\t}\r\n\t\t).add;\r\n\r\n\t\t0.5.wait;\r\n\r\n\r\n\t\t~c = Group.new;\r\n\r\n\t\tSynth(\\mainOut,[\\gate,1,\\amp,0.2],~c,\\addToTail);\r\n\r\n\r\n\t\t~verbos=Pmono(\\hall,\r\n\t\t\t\\gate,1,\r\n\t\t\t\\amp,Pexprand(0.1,0.7,inf),\r\n\t\t\t\\size,Pwhite(0.1,0.9,inf),\r\n\t\t\t\\t60,Pexprand(0.1,12,inf),\r\n\r\n\t\t\t\\dur,Pwhite(0.1,7.0,inf),\r\n\r\n\t\t\t\\att,Pkey(\\dur)/2,\r\n\t\t\t\\dec,Pkey(\\dur)/2,\r\n\r\n\t\t\t\\group,~c,\r\n\t\t\t//\\addAction,1\r\n\t\t).play;\r\n\r\n\t\t~tones=Routine{\r\n\t\t\tinf.do{\r\n\r\n\t\t\t\tvar freq = ([0,2,3,7,9,10,12,15,19].choose+22).midicps;\r\n\t\t\t\tvar dense =exprand(12,120);\r\n\r\n\t\t\t\tSynth(\\fmGrain,\r\n\t\t\t\t\t[\r\n\t\t\t\t\t\t\\trigger,2.rand,\r\n\r\n\t\t\t\t\t\t\\gate,1,\r\n\t\t\t\t\t\t\\freq,freq,\r\n\r\n\t\t\t\t\t\t\\modFreq,freq*rrand(1,4)+rrand(-0.1,0.1),\r\n\t\t\t\t\t\t\\index,1.0.rand,\r\n\r\n\t\t\t\t\t\t\\dense,dense,\r\n\t\t\t\t\t\t\\size,rrand(2,8.0),\r\n\t\t\t\t\t\t\\offset,0.5,\r\n\r\n\t\t\t\t\t\t\\gAtt,rrand(0.1,1),\r\n\t\t\t\t\t\t\\gDec,1,\r\n\r\n\t\t\t\t\t\t\\wave,~arrays[3.rand],\r\n\t\t\t\t\t\t\\mul,exprand(0.2,1.0),\r\n\r\n\r\n\t\t\t\t\t\t//global Env\r\n\t\t\t\t\t\t\\bPoints,Array.fill(9,{|a| a=a+rrand(-0.2,0.2); a.sin})++0,\r\n\t\t\t\t\t\t\\bTimes,Array.exprand(10,3.01,1.0),\r\n\r\n\t\t\t\t\t\t//dense env\r\n\t\t\t\t\t\t\\mPoints1, Array.exprand(5,0.01,16.0), //no zeroes\r\n\t\t\t\t\t\t\\mTimes1, Array.exprand(4,0.01,6.0),        //no zeroes\r\n\r\n\t\t\t\t\t\t//index env\r\n\t\t\t\t\t\t\\mPoints2, Array.exprand(4,0.01,6.0)++0, //no zeroes\r\n\t\t\t\t\t\t\\mTimes2, Array.exprand(4,0.01,6.0),        //no zeroes\r\n\r\n\t\t\t\t\t],~c,\\addToHead\r\n\t\t\t\t);\r\n\r\n\t\t\t\t8.wait;\r\n\t\t\t}\r\n\t\t}.play;\r\n\t}\r\n};\r\n\r\nAppClock.play(~r);\r\n)\r\n\r\n\r\n//kill the mess\r\n\r\n[~verbos,~tones].stop;s.freeAll;\r\n\r\n~arrays[0].plot",
   "id" : "1-56e",
   "is_private" : null
}
