The Buffer Object

The Buffer Object

The Buffer object in JavaScript is a companion to the buffer~ object you instantiate in Max patchers, and provides the ability to access samples and metadata for the buffer~ object with the associated name.

Buffer Constructor


		var buf = new Buffer("name");
	

The name is required at the time the object is created.


The following methods relate to the functionality from the Max buffer~, info~, peak~, and poke~, objects. Please see the references for those objects for details.

Buffer Methods

channelcount

Return the number of channels in the buffer~ object.

framecount

Return the number of frames (samples in a single channel) in the buffer~ object.

length

Return the length of the buffer~ object in milliseconds.

peek

Arguments

channel [int]
frame [int]
count [int]

Return an array with count samples from channel (1-based counting) starting at frame (zero-based counting).

poke

Arguments

channel [int]
frame [int]
samples [float/array]

Write into the buffer~ object at channel (1-based counting) and frame (0-based counting). Samples may be a single sample value or an array of sample values. It is computationally more efficient to use an array).

send

Arguments

message-name [string]
arguments [anything]

Send a message to the associated buffer~ object. Can send any message that buffer~ understands.

Examples

Example code can be found in the "js" tab of the buffer~ help patcher.