Project: p5_sc / Class: Buffer
Processing.org classes for interfacing with the SuperCollider synthesis engine.
Class: Buffer
Represents a single audio buffer. Used to read, record and write sound data.
Examples: read write setn getn fill
Variables
- int index - this buffer's unique index
- int frames - number of frames (not yet updated after read() operations)
- int channels - number of sound channels (not yet updated after read() operations)
- int sampleRate - audio sample rate
Methods
Buffer (Server server, int channels)
Buffer (Server server, int frames, int channels)
void read (String path, Object target, String action)
Allocate a buffer and read the specified sound file into it.
The method named action is invoked on the object target upon completion, with this Buffer object as its single argument.
The frames, channels and sampleRate instance variables are automatically populated with the correct values after the command is completed.
Allocates the required buffer space on the server.
The method named action is invoked on the object target upon completion, with this Buffer object as its single argument.
void write (String path, String type, String format)
Begins writing to disk from the buffer, using the specified type and format parameters (see SuperCollider's Buffer helpfile for details). Writes at most frames frames, from index start. If leave_open is greater than 0, leaves the buffer open for further writing (for use with DiskOut).
void close()
Closes the output file previously opened with write().
The method named action is invoked on the object target upon completion, with this Buffer object as its single argument.
void free()
Free the buffer object.
The method named action is invoked on the object target upon completion, with this Buffer object as its single argument.
Get a single sample from a buffer object, passing the float value via the specified callback.
The method named action is invoked on the object target upon completion, which must have the below signature:
(Buffer buffer, int index, float value)
Get multiple samples from a buffer at the given frame indices, passing an array of float values via the specified callback.
The method named action is invoked on the object target upon completion, which must have the below signature:
(Buffer buffer, int [] indices, float [] values)
Get a range of samples from a buffer object, passing an array of float values.
This function cannot be used to retrieve large numbers of values; currently, it can only get a maximum of 200 samples. To retrieve a full buffer from an scsynth running locally, use Buffer.write() with a callback which reads the file data using a sound library such as Minim (example).
The method named action is invoked on the object target upon completion, which must have signature:
(Buffer buffer, int index, float [] values)
Set a single sample to the specified value (-1..1).
Set several discrete sample values at the given frame indices. frames and values must have the same number of elements.
Set a range of samples to the specified array of values. The array values must have count elements.
Fill a range of samples with the same value.
Set every sample in the buffer to 0.0.
Sample Code
Usage
import supercollider.*; Buffer buffer; void setup () { buffer = new Buffer(2); buffer.read("/Users/daniel/audio/samples/acoustic/piano-chord.aif", this, "done"); } void draw () { } void done (Buffer buffer) { println("Buffer loaded."); println("Channels: " + buffer.channels); println("Frames: " + buffer.frames); println("Sample Rate: " + buffer.sampleRate); Synth synth = new Synth("playbuf_2"); synth.set("bufnum", buffer.index); synth.create(); } void mousePressed() { buffer.free(this, "freed"); } void freed (Buffer buffer) { println("Buffer freed."); }

