AudioBuffer

@native @JSType
trait AudioBuffer extends Object

The AudioBuffer interface represents a short audio asset residing in memory, created from an audio file using the AudioContext.decodeAudioData() method, or from raw data using AudioContext.createBuffer(). Once put into an AudioBuffer, the audio can then be played by being passed into an AudioBufferSourceNode.

Objects of these types are designed to hold small audio snippets, typically less than 45 s. For longer sounds, objects implementing the MediaElementAudioSourceNode are more suitable.

The buffer contains data in the following format: non-interleaved IEEE754 32-bit linear PCM with a nominal range between -1 and +1, that is, 32bits floating point buffer, with each samples between -1.0 and 1.0. If the AudioBuffer has multiple channels, they are stored in separate buffer.

class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

def copyFromChannel(destination: Float32Array, channelNumber: Int, startInChannel: Int): Unit

Copies the samples from the specified channel of the AudioBuffer to the destination array.

Copies the samples from the specified channel of the AudioBuffer to the destination array.

Value parameters:
channelNumber

The channel number of the current AudioBuffer to copy the channel data from. If channelNumber is greater than or equal to AudioBuffer.numberOfChannels, an INDEX_SIZE_ERR will be thrown.

destination

A Float32Array to copy the channel data to.

startInChannel

An optional offset to copy the data from. If startInChannel is greater than AudioBuffer.length, an INDEX_SIZE_ERR will be thrown.

def copyToChannel(source: Float32Array, channelNumber: Int, startInChannel: Int): Unit

Copies the samples to the specified channel of the AudioBuffer, from the source array.

Copies the samples to the specified channel of the AudioBuffer, from the source array.

Value parameters:
channelNumber

The channel number of the current AudioBuffer to copy the channel data to. If channelNumber is greater than or equal to AudioBuffer.numberOfChannels, an INDEX_SIZE_ERR will be thrown.

source

A Float32Array that the channel data will be copied from.

startInChannel

An optional offset to copy the data to. If startInChannel is greater than AudioBuffer.length, an INDEX_SIZE_ERR will be thrown.

def getChannelData(channel: Int): Float32Array

Returns a Float32Array containing the PCM data associated with the channel, defined by the channel parameter (with 0 representing the first channel).

Returns a Float32Array containing the PCM data associated with the channel, defined by the channel parameter (with 0 representing the first channel).

Value parameters:
channel

The channel property is an index representing the particular channel to get data for. An index value of 0 represents the first channel. If the channel index value is greater than of equal to AudioBuffer.numberOfChannels, an INDEX_SIZE_ERR exception will be thrown.

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from:
Object
def isPrototypeOf(v: Object): Boolean
Inherited from:
Object
def propertyIsEnumerable(v: String): Boolean
Inherited from:
Object
def toLocaleString(): String
Inherited from:
Object
def valueOf(): Any
Inherited from:
Object

Concrete fields

val duration: Double

Returns a double representing the duration, in seconds, of the PCM data stored in the buffer.

Returns a double representing the duration, in seconds, of the PCM data stored in the buffer.

val length: Int

Returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.

Returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.

Returns an integer representing the number of discrete audio channels described by the PCM data stored in the buffer.

Returns an integer representing the number of discrete audio channels described by the PCM data stored in the buffer.

val sampleRate: Double

Returns a float representing the sample rate, in samples per second, of the PCM data stored in the buffer.

Returns a float representing the sample rate, in samples per second, of the PCM data stored in the buffer.