Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: example fft sc->processing
name
code content
/* //--processing code: import oscP5.*; import netP5.*; OscP5 oscP5; final int BUFFERSIZE= 2048; //should correspond with fft size in supercollider final int BUFFERSIZE2= BUFFERSIZE/2; float[] fftArray; void setup() { size(1280, 768); frameRate(60); background(0); noSmooth(); fftArray= new float[BUFFERSIZE2]; for (int i= 0; i<BUFFERSIZE2; i++) { fftArray[i]= 0.0; } //--network OscProperties properties= new OscProperties(); //properties.setRemoteAddress("127.0.0.1", 57120); //osc send port (to sc) properties.setListeningPort(47120); //osc receive port (from sc) //properties.setSRSP(OscProperties.ON); //unused //properties.setDatagramSize(min(BUFFERSIZE*4, 8192)); properties.setDatagramSize(5136); //5136 is the minimum oscP5= new OscP5(this, properties); } void oscEvent(OscMessage msg) { if (msg.checkAddrPattern("/fftArray")) { for (int i= 0; i<BUFFERSIZE2; i++) { fftArray[i]= msg.get(i).floatValue(); } } } void draw() { background(0); noFill(); for (int x= 0; x<BUFFERSIZE2; x++) { stroke(fftArray[x]*255.0, 0, 0); line(x, height*0.1, x, height*0.9); } } */ //--supercollider code: ( var buffersize= 2048; var buffersize2= buffersize.div(2); n= NetAddr("127.0.0.1", 47120); s.options.memSize= 8192*2; s.waitForBoot{ c= Bus.control(s, buffersize2); SynthDef(\avTrk, {|in= 0, t_trig= 0, amp= 1, bus| var z= Mix(In.ar(in, 2)*amp); var chain= FFT(LocalBuf(buffersize), z); Array.fill(buffersize2, {|i| var a= Unpack1FFT(chain, buffersize, i); var d= Demand.kr(chain>=0, 0, a); Out.kr(bus+i, d.min(1)); }); }).load; s.sync; ~trk= Synth(\avTrk, [\in, 0, \amp, 0.3, \bus, c]); a= play{var a=SinOsc;Splay.ar(a.ar(PulseCount.ar(f=InFeedback.ar(0,2).sum)%999+(60,63.0005..99)*a.ar(2**f)*2+[3,4],f>0*f*9)).tanh*MouseX.kr(0, 1)}; Routine.run({ inf.do{ var fftArray= c.getnSynchronous(buffersize2); n.sendMsg(\fftArray, *fftArray); //sending 1024 values (1/61).wait; //a tiny bit faster than framerate }; }); CmdPeriod.doOnce({c.free}); }; )
code description
template code for sending lots of data (1024 fft values 61 times per second) from sc to processing. sound function from an old sc-tweet. updated to work with sc3.9 and processing 3.3.6
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