JSPM

  • Created
  • Published
  • Downloads 113524
  • Score
    100M100P100Q153014F
  • License MIT

Audio data container

Package Exports

  • audio-buffer

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (audio-buffer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

audio-buffer Build Status stable

AudioBuffer ponyfill. Provides useful constructor for Web-Audio API AudioBuffer, if available, otherwise provides optimal AudioBuffer implementation for node/browsers. Useful instead of Buffer in audio streams (see @audiojs components).

Usage

npm install audio-buffer

var AudioBuffer = require('audio-buffer')

//Create audio buffer from a data source or of a length.
//Data is interpreted as a planar sequence of float32 samples.
//It can be Array, TypedArray, ArrayBuffer, Buffer, AudioBuffer, DataView, NDArray etc.
var buffer = new AudioBuffer(channels = 2, data|length, sampleRate = 44100, options?)

//Duration of the underlying audio data, in seconds
buffer.duration

//Number of samples per channel
buffer.length

//Default sample rate is 44100
buffer.sampleRate

//Default number of channels is 2
buffer.numberOfChannels

//Get array containing the data for the channel (not copied)
buffer.getChannelData(channel)

//Place data from channel to destination Float32Array
buffer.copyFromChannel(destination, channelNumber, startInChannel = 0)

//Place data from source Float32Array to the channel
buffer.copyToChannel(source, channelNumber, startInChannel = 0)

Options

Options object can be passed as last argument with the following:

  • floatArray — type of array for data, defaults to Float32Array. Note that to use Float64Array in browser you would have to disable WebAudioAPI fallback by passing isWAA: false.
  • context — custom audio context, default context is audio-context module.
  • isWAA — if WebAudioAPI AudioBuffer should be created. Use false for emulated buffers - in nodejs that is always false. That can be handy in case if you need to create buffer from subarrays to avoid cloning the data, like so:
var a = new AudioBuffer(1, [0, .1, .2, .3], {isWAA: false})
var b = new AudioBuffer(1, [a.getChannelData(0).subarray(1,2)], {isWAA: false})
b.getChannelData(0)[0] = .4
a.getChannelData(0) // [0, .4, .2, .3]

See also

Similar

  • ndsamples — audio-wrapper for ndarrays. A somewhat alternative approach to wrap audio data, based on ndarrays, used by some modules in livejs.
  • 1, 2, 3, 4 — other AudioBuffer implementations.
  • audiodata alternative data holder from @mohayonao.