A newer version of Max is available. Click here to access the latest version of this document.

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


Return the number of channels in the buffer~ object.


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


Return the length of the buffer~ object in milliseconds.



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

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



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).



message-name [string]
arguments [anything]

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


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

See Also

Name Description
JavaScript Usage JavaScript Usage