class Buffer

Bind to a Max buffer~ object.

The Buffer object in JavaScript is a companion to the buffer~ object in Max. Through it, you can to access samples and metadata for the buffer~ object with the given name.

Index

Constructors

Methods

new Buffer(name)

new Buffer(name: string);

Constructs a new instance of the Buffer class

ParameterTypeDescription
namestringname of the Max buffer~ to bind to.

channelcount()

Buffer channel count

Return the channels the buffer~ object. This is a method, not a property, and so must be called to get the number of channels.

channelcount(): number;
NameTypeDescription
Return ValuenumberThe number of channels in the buffer~ object.

create(name, filename, duration, channelcount)

Supported only in the v8 engine.

Create a new Max buffer~ object.

create(
  name?: string,
  filename?: string,
  duration?: number,
  channelcount?: number,
): void;
NameTypeDescription
optional namestringname of the Max buffer~ to create. If no name is provided the current name is used.
optional filenamestringfilename of the audio file to load. If no filename is provided the buffer is created empty.
optional durationnumberduration of the buffer in milliseconds. If no duration is provided the buffer is created empty.
optional channelcountnumbernumber of channels in the buffer. If no channelcount is provided the buffer is created with 1 channel.

framecount()

Buffer frame count

Return the number of frames (samples in a single channel) in the buffer~ object. This is a method, not a property, and so must be called to get the number of frames.

framecount(): number;
NameTypeDescription
Return ValuenumberThe number of frames in the buffer~ object.

freepeer()

Free the native C peer

Frees the buffer~ data from the native C peer (created when making a Buffer object), which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based JS allocated memory. Once called, the Buffer object is not available for any other use. It's not necessary to call this function, as the memory will be freed eventually, but you can call it whenever you're done with your Buffer object.

freepeer(): void;

getattr(name)

Supported only in the v8 engine.

Get the value of the named attribute

getattr(name: string): number | string | (number | string)[];
NameTypeDescription
namestringthe name of the attribute to retrieve
Return Valuenumber | string | (number | string)[]the value of the attribute, as an array if the attribute value is a list

getname()

Supported only in the v8 engine.

Get the name of the buffer

getname(): string;
NameTypeDescription
Return ValuestringThe name of the buffer~ object.

length()

Length of the buffer in milliseconds

Return the length of the buffer~ object in milliseconds. This is a method, not a property, and so must be called to get the length of the buffer.

length(): number;
NameTypeDescription
Return ValuenumberThe length of the buffer in milliseconds.

peek(channel, frame, count)

Fetch an array of samples from the buffer

peek(channel: number, frame: number, count: number): number[];
NameTypeDescription
channelnumberchannel to fetch samples from (indexed from 1)
framenumberframe at which to start fetching samples (indexed from 0)
countnumbernumber of samples to fetch
Return Valuenumber[]

poke(channel, frame, samples)

Write samples into the buffer

It is more efficient to call this function once with an array, than to call it mulpitle times, each time with a single sample.

poke(channel: number, frame: number, samples: number | number[]): void;
NameTypeDescription
channelnumberchannel to write samples to (indexed from 1)
framenumberframe at which to start writing samples (indexed from 0)
samplesnumber | number[]samples to write (or a single sample to write)

send(message, args)

Send a message to the buffer.

Can send any message that buffer~ understands. See buffer~ reference.

send(message: string, ...args: any[]): void;
NameTypeDescription
messagestringthe name of message
argsany[]arguments that follow the name of the message

setattr(name, value)

Supported only in the v8 engine.

Set the value of the named attribute

setattr(name: string, value: number | string | (number | string)[]): void;
NameTypeDescription
namestringthe name of the attribute to set
valuenumber | string | (number | string)[]the value of the attribute to set

setname(name)

Supported only in the v8 engine.

Set the name of the buffer

setname(name: string): void;
NameTypeDescription
namestringthe name of the buffer to set