Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: example fft sc->processing v2
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[] fftArrayHi; float[] fftArrayMd; float[] fftArrayLo; void setup() { size(1280, 768); frameRate(60); background(0); noSmooth(); fftArrayHi= new float[BUFFERSIZE2]; fftArrayMd= new float[BUFFERSIZE2]; fftArrayLo= new float[BUFFERSIZE2]; for (int i= 0; i<BUFFERSIZE2; i++) { fftArrayHi[i]= 0.0; fftArrayMd[i]= 0.0; fftArrayLo[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("/fftArrayHi")) { for (int i= 0; i<BUFFERSIZE2; i++) { fftArrayHi[i]= msg.get(i).floatValue(); } } else if (msg.checkAddrPattern("/fftArrayMd")) { for (int i= 0; i<BUFFERSIZE2; i++) { fftArrayMd[i]= msg.get(i).floatValue(); } } else if (msg.checkAddrPattern("/fftArrayLo")) { for (int i= 0; i<BUFFERSIZE2; i++) { fftArrayLo[i]= msg.get(i).floatValue(); } } } void draw() { background(0); noFill(); for (int x= 0; x<BUFFERSIZE2; x++) { stroke(fftArrayHi[x]*255.0, 0, 0); line(x, height*0.1, x, height*0.3); stroke(fftArrayMd[x]*255.0, 0, 0); line(x, height*0.4, x, height*0.6); stroke(fftArrayLo[x]*255.0, 0, 0); line(x, height*0.7, x, height*0.9); } } */ //--supercollider code ( var buffersize= 2048; var buffersize2= buffersize.div(2); var n= NetAddr("127.0.0.1", 47120); s.options.memSize= 8192*4; s.waitForBoot{ var busHi= Bus.control(s, buffersize2); var busMd= Bus.control(s, buffersize2); var busLo= Bus.control(s, buffersize2); SynthDef(\avTrkHi, {|in= 0, amp= 1, bus, freq= 5000| var z= BHiPass.ar(Mix(InFeedback.ar(in, 2)*amp), freq); 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; SynthDef(\avTrkMd, {|in= 0, amp= 1, bus, freq= 1000| var z= BBandPass.ar(Mix(InFeedback.ar(in, 2)*amp), freq); 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; SynthDef(\avTrkLo, {|in= 0, amp= 1, bus, freq= 100| var z= BLowPass.ar(Mix(InFeedback.ar(in, 2)*amp), freq); 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; Synth(\avTrkHi, [\in, 0, \amp, 0.3, \bus, busHi]); Synth(\avTrkMd, [\in, 0, \amp, 0.3, \bus, busMd]); Synth(\avTrkLo, [\in, 0, \amp, 0.3, \bus, busLo]); Routine.run({ inf.do{ var fftArrayHi= busHi.getnSynchronous(buffersize2); var fftArrayMd= busMd.getnSynchronous(buffersize2); var fftArrayLo= busLo.getnSynchronous(buffersize2); n.sendMsg(\fftArrayHi, *fftArrayHi); //sending 1024 values n.sendMsg(\fftArrayMd, *fftArrayMd); //sending 1024 values n.sendMsg(\fftArrayLo, *fftArrayLo); //sending 1024 values (1/61).wait; //a tiny bit faster than framerate }; }); CmdPeriod.doOnce({ busHi.free; busMd.free; busLo.free; }); }; )
code description
an extended version of http://sccode.org/1-4Ty this one sends 3 streams of spectral data at the same time - high, mid and low filtered. note: quite heavy on the cpu and sends a lot of data via osc (1024*3 values 61times/second). play any sound on output bus 0 and 1 to test it. e.g. {SoundIn.ar!2}.play 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