audio-buffer-list
Extension of BufferList for AudioBuffers. Handy and performant to deal with (possibly long) sequence of audio buffers − accumulate, read, stream, modify, delete etc. It provides interfaces of both AudioBuffer and BufferList, as well as bunch of other useful methods.
Usage
const AudioBufferList = require('audio-buffer-list')
const AudioBuffer = require('audio-buffer')
let abl = new AudioBufferList(new AudioBuffer(1, [0, .1, .2, .3]), new AudioBuffer(1, 100))
abl.append(new AudioBuffer(1, 100))
abl.length
abl.slice()
API
new AudioBufferList(source, options?)
Creates new audio buffer list instance, new
is not strictly required.
source
can be AudioBuffer, AudioBuffer array, AudioBufferList, AudioBufferList array or callback.
options
may provide numberOfChannels
, context
for web audio API context and sampleRate
.
list.insert(buffer, offset=0)
Put new AudioBuffer, AudioBufferList or array of them at the offset.
list.delete(count, offset=0)
Delete number of samples starting at the offset. count
can possibly be negative, then items are deleted on the left side from the offset. offset
can also be negative, meaning to start from the end.
list.repeat(count)
Repeats contents of the list specified number of times. Modifies list in-place.
list.map((buffer, index, offset) => buffer|bool?, from=0, to=-0)
Create new list by mapping every buffer. Optionally pass offsets from
and to
to map only buffers covering the subset, keeping the rest unchanged. If no buffer returned from the mapper function then the old buffer will be preserved. If null
returned then the buffer will be discarded. offset
tracks buffer
offset in new list, index
reflects buffer count.
list = list.map((buf, idx, offset) => {
for (let c = 0; c < channels; c++) {
let data = buf.getChannelData(channel)
for (let i = Math.max(from - offset, 0),
l = Math.min(to - offset, buf.length);
i < l; i++) {
data[i] = process(data[i])
}
}
}, from, to)
list.each((buffer, index, offset) => {}, from=0, to=-0)
Iterate over buffers from the indicated range. Buffers can be modified in-place during the iterating.
list.duration
Total duration of the audio list, i.e. sum of buffers durations.
list.numberOfChannels
Detected from the buffer with max number of channels in the list. Can be set by options.
list.sampleRate
Just for convenience with AudioBuffer interface
list.getChannelData(channel)
Return FloatArray with merged data for the channel.
list.copyFromChannel(destination, channel, startInChannel=0)
Put data from the channel to destination FloatArray. Optional startInChannel
defines offset in the channel to start from.
list.copyToChannel(source, channel, startInChannel=0)
Put data from the source
FloatArray into channel, optionally starting at startInChannel
offset.
BufferList properties and methods
list.length
Total length of list in samples, i.e. sum of inner buffer lengths.
list.append(buffer)
Insert new AudioBuffer, AudioBufferList or array of them to the end.
list.slice(start=0, end=-0)
Return merged AudioBuffer representing indicated interval.
list.shallowSlice(start=0, end=-0)
Return sublist — a handle for the data of the indicated interval.
list.get(idx, channel)
Get single sample value at the coordinate.
list.duplicate()
Create new AudioBufferList consisting of the same AudioBuffers as the initial list.
list.copy(dest, destStart?, srcStart?, srcEnd?)
Put data into destination AudioBuffer.
list.consume(length)
Delete data from the beginning.
Stream methods
See also