AudioBufferSourceNode: AudioBufferSourceNode() constructor
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The AudioBufferSourceNode()
constructor creates a new AudioBufferSourceNode object instance.
Syntax
new AudioBufferSourceNode(context, options)
Parameters
context-
A reference to an
AudioContext. optionsOptional-
Options are as follows:
buffer-
An instance of
AudioBufferto be played. detune-
A value in cents to modulate the speed of audio stream rendering. Its nominal range is (-∞ to +∞). The default is
0. loop-
A boolean indicating whether the audio should play in a loop. The default is
false. If the loop is dynamically modified during playback, the new value will take effect on the next processing block of audio. loopEnd-
An optional value, in seconds, where looping should end if the loop attribute is
true. The default is0. Its value is exclusive to the content of the loop. The sample frames, comprising the loop, run from the valuesloopStarttoloopEnd-(1/sampleRate). It's sensible to set this to a value between 0 and the duration of the buffer. IfloopEndis less than 0, looping will end at 0. IfloopEndis greater than the duration of the buffer, looping will end at the end of the buffer. This attribute is converted to an exact sample frame offset within the buffer, by multiplying by the buffer's sample rate and rounding to the nearest integer value. Thus, its behavior is independent of the value of theplaybackRateparameter. loopStart-
An optional value in seconds, where looping should begin if the loop attribute is
true. The default is0. It's sensible to set this to a value between 0 and the duration of the buffer. IfloopStartis less than 0, looping will begin at 0. IfloopStartis greater than the duration of the buffer, looping will begin at the end of the buffer. This attribute is converted to an exact sample frame offset within the buffer, by multiplying by the buffer's sample rate and rounding to the nearest integer value. Thus, its behavior is independent of the value of theplaybackRateparameter. playbackRate-
The speed at which to render the audio stream. Its default value is
1. This parameter is k-rate. This is a compound parameter with detune. Its nominal range is (-∞ to +∞). channelCount-
Represents an integer used to determine how many channels are used when up-mixing and down-mixing connections to any inputs to the node. (See
AudioNode.channelCountfor more information.) Its usage and precise definition depend on the value ofchannelCountMode. channelCountMode-
Represents an enumerated value describing the way channels must be matched between the node's inputs and outputs. (See
AudioNode.channelCountModefor more information including default values.) channelInterpretation-
Represents an enumerated value describing the meaning of the channels. This interpretation will define how audio up-mixing and down-mixing will happen. The possible values are
"speakers"or"discrete". (SeeAudioNode.channelCountModefor more information including default values.)
Return value
A new AudioBufferSourceNode object instance.
Specifications
| Specification |
|---|
| Web Audio API> # dom-audiobuffersourcenode-audiobuffersourcenode> |
Browser compatibility
Loading…