Interface AudioBufferSourceNode

This interface represents an audio source from an in-memory audio asset in an AudioBuffer. It generally will be used for short audio assets which require a high degree of scheduling flexibility (can playback in rhythmically perfect ways). The playback state of an AudioBufferSourceNode goes through distinct stages during its lifetime in this order: UNSCHEDULED_STATE, SCHEDULED_STATE, PLAYING_STATE, FINISHED_STATE. The start() method causes a transition from the UNSCHEDULED_STATE to SCHEDULED_STATE. Depending on the time argument passed to start(), a transition is made from the SCHEDULED_STATE to PLAYING_STATE, at which time sound is first generated. Following this, a transition from the PLAYING_STATE to FINISHED_STATE happens when either the buffer's audio data has been completely played (if the loop attribute is false), or when the stop() method has been called and the specified time has been reached. Please see more details in the start() and stop() description. Once an AudioBufferSourceNode has reached the FINISHED state it will no longer emit any sound. Thus start() and stop() may not be issued multiple times for a given AudioBufferSourceNode.

numberOfInputs  : 0
numberOfOutputs : 1

Hierarchy

Index

Properties

Methods

Properties

public buffer: AudioBuffer

Represents the audio asset to be played.

public context: AudioContext

The AudioContext which owns this AudioNode.

public loop: boolean

Indicates if the audio data should play in a loop. The default value is false.

public loopEnd: number

An optional value in seconds where looping should end if the loop attribute is true. Its default value is 0, and it may usefully be set to any value between 0 and the duration of the buffer.

public loopStart: number

An optional value in seconds where looping should begin if the loop attribute is true. Its default value is 0, and it may usefully be set to any value between 0 and the duration of the buffer.

public numberOfInputs: number

The number of inputs feeding into the AudioNode. This will be 0 for an AudioSourceNode.

public numberOfOutputs: number

The number of outputs coming out of the AudioNode. This will be 0 for an AudioDestinationNode.

public onended: EventListener

A property used to set the EventHandler for the ended event that is dispatched to AudioBufferSourceNode node types. When the playback of the buffer for an AudioBufferSourceNode is finished, an event of type Event will be dispatched to the event handler.

public playbackRate: AudioParam

The speed at which to render the audio stream. The default playbackRate.value is 1. This parameter is a-rate

public playbackState: number

The playback state, initialized to UNSCHEDULED_STATE.

Methods

public connect(destination: AudioNode, output?: number, input?: number)

Connects the AudioNode to another AudioNode.

It is possible to connect an AudioNode output to more than one input with multiple calls to connect(). Thus, "fanout" is supported.

It is possible to connect an AudioNode to another AudioNode which creates a cycle. In other words, an AudioNode may connect to another AudioNode, which in turn connects back to the first AudioNode. This is allowed only if there is at least one DelayNode in the cycle or an exception will be thrown.

There can only be one connection between a given output of one specific node and a given input of another specific node. Multiple connections with the same termini are ignored. For example:

nodeA.connect(nodeB);
nodeA.connect(nodeB);

will have the same effect as

nodeA.connect(nodeB);

Parameters

  • destination: AudioNode

    the AudioNode to connect to.

  • output?: number optional

    an index describing which output of the AudioNode from which to connect. An out-of-bound value throws an exception.

  • input?: number optional

    an index describing which input of the destination AudioNode to connect to. An out-of-bound value throws an exception.

public connect(destination: AudioParam, output?: number)

Connects the AudioNode to an AudioParam, controlling the parameter value with an audio-rate signal.

It is possible to connect an AudioNode output to more than one AudioParam with multiple calls to connect(). Thus, "fanout" is supported.

It is possible to connect more than one AudioNode output to a single AudioParam with multiple calls to connect(). Thus, "fanin" is supported.

An AudioParam will take the rendered audio data from any AudioNode output connected to it and convert it to mono by down-mixing if it is not already mono, then mix it together with other such outputs and finally will mix with the intrinsic parameter value (the value the AudioParam would normally have without any audio connections), including any timeline changes scheduled for the parameter.

There can only be one connection between a given output of one specific node and a specific AudioParam. Multiple connections with the same termini are ignored. For example:

nodeA.connect(param);
nodeA.connect(param);

will have the same effect as

nodeA.connect(param);

Parameters

  • destination: AudioParam

    the AudioParam to connect to.

  • output?: number optional

    an index describing which output of the AudioNode from which to connect. An out-of-bound value throws an exception.

public disconnect(output?: number)

Disconnects an AudioNode's output.

Parameters

  • output?: number optional

    an index describing which output of the AudioNode to disconnect. An out-of-bound value throws an exception.

public start(when: number, offset?: number, duration?: number)

Schedules a sound to playback at an exact time.

Parameters

  • when: number

    time (in seconds) the sound should start playing. It is in the same time coordinate system as AudioContext.currentTime. If 0 is passed in for this value or if the value is less than currentTime, then the sound will start playing immediately. start may only be called one time and must be called before stop is called or an exception will be thrown.

  • offset?: number optional

    the offset time in the buffer (in seconds) where playback will begin. This parameter is optional with a default value of 0 (playing back from the beginning of the buffer).

  • duration?: number optional

    the duration of the portion (in seconds) to be played. This parameter is optional, with the default value equal to the total duration of the AudioBuffer minus the offset parameter. Thus if neither offset nor duration are specified then the implied duration is the total duration of the AudioBuffer.

public stop(when: number)

Schedules a sound to stop playback at an exact time. Please see deprecation section for the old method name.

The when parameter describes at what time (in seconds) the sound should stop playing. It is in the same time coordinate system as AudioContext.currentTime. If 0 is passed in for this value or if the value is less than currentTime, then the sound will stop playing immediately. stop must only be called one time and only after a call to start or stop, or an exception will be thrown.

Parameters

  • when: number