AudioBuffer
An implementation of Web Audio API's AudioBuffer for node.js.Getting started
Install AudioBuffer
with npm
:npm install AudioBuffer
Then import it in your code, and do your stuff :
var AudioBuffer = require('AudioBuffer')
var audioBuffer = new AudioBuffer(1, 100000, 44100)
API
AudioBuffer(numberOfChannels, length, sampleRate)
Creates an emptyAudioBuffer
with numberOfChannels
channels and length
frames.getChannelData(channel)
Returns achannel
.slice(start, end)
Returns a slice of the callingAudioBuffer
.
The arguments have the same meaning as a standard Array.slice
.
The slice happens in the length, therefore the returned buffer has the same number of channels and the same sample rate as the calling AudioBuffer
.concat(audioBuffer)
Returns a newAudioBuffer
, result of the concatenation of the calling instance with audioBuffer
.
audioBuffer
must have the same number of channels and the same sample rate as the calling instance, or an error will be thrown.
This method behaves similarly to Array.concat
.
The concatenation happens in the length, therefore the returned buffer has the same number of channels and the same sample rate than the calling AudioBuffer
.Class methods
filledWithVal(val, numberOfChannels, length, sampleRate)
Returns anAudioBuffer
, each sample filled with val
.fromArray(array, sampleRate)
Returns anAudioBuffer
, with data taken from array
. Example :// Creates a stereo AudioBuffer of length 5 and sample rate 22050.
var audioBuffer = AudioBuffer.fromArray([
[1, 0.5, 0.2, 1, 0.5],
[-1, -0.8, -0.7, -0.6, 0.3],
], 22050)