1.1.1 • Published 6 years ago

audio-buffer-from v1.1.1

Weekly downloads
1,616
License
MIT
Repository
github
Last release
6 years ago

audio-buffer-from Build Status unstable Greenkeeper badge

Create AudioBuffer from any source.

Usage

$ npm install audio-buffer-from

var createBuffer = require('audio-buffer-from')

//mono-buffer 1024 samples
var abuf = createBuffer(1024)

//stereo-buffer 1024 samples
var abuf2 = createBuffer(1024, 2)

//buffer from data with bound audio context
var abuf3 = createBuffer(floatArray, {context: audioContext})

//empty 1-sample mono buffer with default context
var abuf4 = createBuffer()

//0-length no-context buffer
var abuf5 = createBuffer(0)

//from duration
var abuf6 = createBuffer({duration: 1})

//from pcm data
var abuf7 = createBuffer(new Uint8Array([0, 0, 255, 255]), 'interleaved 96000')

//from data-uri
var abuf8 = createBuffer('data:application/octet-stream;base64,AP8A/w==', 'uint8')

//from base64 string
var abuf9 = createBuffer('AAAAAAAAAAAAAIA/AACAPw==', 'float32 stereo planar')

//from node Buffer
var abuf10 = createBuffer(Buffer.from([0, 255, 0, 127]), 'interleaved')

API

audioBuffer = createBuffer(source|length, channels|format|options)

Create audio buffer from any source data or a number indicating length, pass options to ensure output buffer parameters. A channels number or format string can be used to shorthand options argument.

Source:

TypeInterpretation
nullBlank 1-sample length buffer.
NumberLength of resulting buffer.
Array of ArraysEvery subarray is considered a channel data.
AudioBufferClone other AudioBuffer.
AudioBufferListCoalesce AudioBufferList to AudioBuffer.
AudioRetrieve AudioBuffer from Audio.
ObjectCreate based on length/duration, channels/numberOfChannels and sampleRate properties.
Array of NumbersRaw data, interpreted by options.format, defaults to float64.
Float32ArrayRaw float32 data, amplitude range is -1..+1.
Float64ArrayRaw float64 data, amplitude range is -1..+1.
Int8ArrayRaw int8 data, amplitude range is -128..+127.
Uint8ArrayRaw uint8 data, amplitude range is 0..255.
TypedArrayAny other typed array, described by options.format argument (see pcm-convert).
ArrayBufferRaw data, interpreted by options.format.
BufferRaw data, interpreted by options.format.
base64 stringBase64-encoded data.
dataURI stringDataURI string.
ndarrayCreate from ndarray instance. The shape property is considered as [length, channels].
ndsamplesCreate from ndsamples instance, similar to ndarray.

Options:

PropertyDefaultMeaning
length1Buffer length. If 0, buffer is unbound from context.
contextaudio-contextAudio context to bind. null-context creates context-free audio buffer.
channels, numberOfChannels1Buffer number of channels.
sampleRate, rate44100Buffer sample rate.
formatnullSource pcm format string or object, see audio-format. If null, it will be detected from the source.

Related

License

© 2017 Dmitry Yv. MIT License