Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Sick LinCong
name
code content
//Linear congruence random number generator ( var file,data; var sr=44100; var last = 0.13154617451; var options = Array.rand(80,0.01,0.99); var mult= 1.02; var changechance = 0.0005; file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr); file.openWrite("/Users/nickcollins/Desktop/writetest.wav"); data = Signal.fill(sr*10, {|i| var next = last; if(changechance.coin,{ mult= [1.02, rrand(1.05,1.2),exprand(1.001,1.1), rrand(1.1,3.9)].choose; }); last = (last*mult)%1.0; if(abs(last)<0.0000001) {last = options.choose}; 2*next-1.0 }); file.writeData(data); file.close; ) //multiply with carry sequence //http://en.wikipedia.org/wiki/Multiply-with-carry ( var file,data; var sr=44100; var maxr = 200; var r = maxr; var roptions = Array.rand(8,2,199); var xr = Array.rand(maxr,0.01,0.99); //var options = Array.rand(500,0.01,0.99); var arraypos = 0; var a = 1.02; var c = rrand(0.0,1.0); var changechance = 0.001; var changechance2 = 0.0001; var changechance3 = 0.00002; //defaults to 44100 sample rate file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr); file.openWrite("/Users/nickcollins/Desktop/writetest.wav"); data = Signal.fill(sr*30, {|i| var prev = xr[arraypos]; var next = a*prev+c; c = floor(next); next = next%1.0; //if(abs(next)<0.0000001) {next = options.choose}; xr[arraypos] = next; arraypos = (arraypos + 1)%r; if(changechance.coin,{ a= [1.0001, rrand(1.0001,1.0005),exprand(1.0001,1.005), rrand(1.01,1.05), rrand(1.1,1.99)].wchoose([0.2,0.2,0.2,0.16,0.04]); }); if(changechance.coin) { r = [roptions.choose, exprand(2,199).asInteger].wchoose([0.95,0.05]); }; if(changechance2.coin) { roptions = Array.rand([exprand(1,100).asInteger,rrand(2,10)].choose,2,199); }; if(changechance3.coin) { xr = Array.rand(maxr,0.01,0.99); }; if(changechance3.coin) { c = rrand(0.0,1.0); }; if(changechance3.coin,{ changechance = [0.001,exprand(0.0001,0.001)].choose; changechance2 = [0.0001,exprand(0.0001,0.001)].choose; changechance3 = [0.0002,exprand(0.0001,0.001)].choose; }); 2*next-1.0 }); file.writeData(data); file.close; ) //multiply with carry sequence, with interpolation to slow down, and nonlinear powers ( var file,data; var sr=44100; var maxr = 200; var r = maxr; var roptions = Array.rand(8,2,199); var powers = Array.fill(maxr,{[1.0,1.0-exprand(0.1,1.0),rrand(0.1,3.0)].choose}); var xr = Array.rand(maxr,0.01,0.99); //var options = Array.rand(500,0.01,0.99); var arraypos = 0; var a = 1.02; var c = rrand(0.0,1.0); var changechance = 0.001; var changechance2 = 0.0001; var changechance3 = 0.00002; var changechance4 = 0.0005; var interpsteps = 5; var interpmul = 1.0/interpsteps; var interp = 0; var interpa = 0.0, interpb= 0.0; var t; //defaults to 44100 sample rate file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr); file.openWrite("/Users/nickcollins/Desktop/writetest.wav"); data = Signal.fill(sr*30, {|i| var prev = xr[arraypos]; var next = a*(prev**(powers[arraypos]))+c; if(interp==0) { c = floor(next); next = next%1.0; //if(abs(next)<0.0000001) {next = options.choose}; xr[arraypos] = next; arraypos = (arraypos + 1)%r; if(changechance.coin,{ a= [1.0001, rrand(1.0001,1.0005),exprand(1.0001,1.005), rrand(1.01,1.05), rrand(1.1,1.99)].wchoose([0.2,0.2,0.2,0.12,0.08]); }); if(changechance.coin) { r = [roptions.choose, exprand(2,199).asInteger].wchoose([0.95,0.05]); }; if(changechance2.coin) { roptions = Array.rand([exprand(1,100).asInteger,rrand(1,10)].choose,2,199); }; if(changechance3.coin) { xr = Array.rand(maxr,0.01,0.99); }; if(changechance3.coin) { c = rrand(0.0,1.0); }; if(changechance3.coin,{ changechance = [0.001,exprand(0.0001,0.001)].choose; changechance2 = [0.00005,exprand(0.0001,0.001)].choose; changechance3 = [0.00002,exprand(0.0001,0.001)].choose; }); if(changechance4.coin) { interpsteps = rrand(1,30); interpmul = 1.0/interpsteps; changechance4 = interpsteps*0.001; }; interpa = interpb; interpb = 2*next-1.0; }; t = interp * interpmul; next = ((1.0-t)*interpa) + (t*interpb); interp = (interp+1)%interpsteps; next; }); file.writeData(data); file.close; )
code description
Use of linear congruence and multiply with carry random number generators for non-realtime signal generation. Very noisy outputs, watch your ears! (you'll need to change the file write path to one valid for your machine)
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change