«example fft sc->processing v2» by Fredrik Olofsson
on 15 Aug'14 00:21 inan 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/* //--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; }); }; )
reception
comments