Project: p5_sc / Examples: Buffer.getn
Examples: Buffer.getn
SuperCollider reads from the audio input to a single-channel
buffer, whose contents are continually read to Processing
via buffer.getn and displayed as a waveform.
SynthDefs
SynthDef(\recordbuf_1, { |bufnum = 0, outbus = 0, amp = 0.5, loop = 0| var data = RecordBuf.ar(AudioIn.ar(1), bufnum, 0, 1, 0, 1, loop); FreeSelfWhenDone.kr(data); }).store;
Processing Code
import supercollider.*; Buffer buffer; void setup () { size(256, 256); background(0); stroke(255); buffer = new Buffer(width, 1); buffer.alloc(this, "done"); } void draw () { buffer.getn(0, buffer.frames, this, "getn"); } void done (Buffer buffer) { Synth synth = new Synth("recordbuf_1"); synth.set("bufnum", buffer.index); synth.set("loop", 1); synth.create(); } void getn (Buffer buffer, int index, float [] values) { background(0); for (int i = 0; i < values.length; i++) { point(i, (height * 0.5) + (values[i] * height * 0.5)); } }

