Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

audio-buffer-list

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-buffer-list - npm Package Compare versions

Comparing version 2.0.7 to 3.0.0

94

index.js
/**
* AudioBuffer class
* AudioBufferList class
*

@@ -10,9 +10,7 @@ * @module audio-buffer/buffer

var isAudioBuffer = require('is-audio-buffer')
var inherit = require('inherits')
var util = require('audio-buffer-utils')
var AudioBuffer = require('audio-buffer')
var extend = require('object-assign')
var nidx = require('negative-index')
var isPlainObj = require('is-plain-obj')
var Emitter = require('events')
var AudioBuffer = require('audio-buffer')

@@ -22,5 +20,3 @@ module.exports = AudioBufferList

inherit(AudioBufferList, Emitter)
function AudioBufferList(arg, options) {

@@ -45,15 +41,20 @@ if (!(this instanceof AudioBufferList)) return new AudioBufferList(arg, options)

//AudioBuffer interface
AudioBufferList.prototype.numberOfChannels = 2
AudioBufferList.prototype.numberOfChannels = 1
AudioBufferList.prototype.sampleRate = null
//copy from channel into destination array
AudioBufferList.prototype.copyFromChannel = function (destination, channel, startInChannel) {
if (startInChannel == null) startInChannel = 0
var offsets = this.offset(startInChannel)
var offset = startInChannel - offsets[1]
var initialOffset = offsets[1]
for (var i = offsets[0], l = this.buffers.length; i < l; i++) {
AudioBufferList.prototype.copyFromChannel = function (destination, channel, from, to) {
if (from == null) from = 0
if (to == null) to = this.length
from = nidx(from, this.length)
to = nidx(to, this.length)
var fromOffset = this.offset(from)
var offset = from - fromOffset[1]
var initialOffset = from
var toOffset = this.offset(to)
for (var i = fromOffset[0], l = toOffset[0]; i < l; i++) {
var buf = this.buffers[i]
var data = buf.getChannelData(channel)
if (startInChannel > offset) data = data.subarray(startInChannel)
if (from > offset) data = data.subarray(from - offset)
if (channel < buf.numberOfChannels) {

@@ -64,9 +65,18 @@ destination.set(data, Math.max(0, offset - initialOffset))

}
var lastBuf = this.buffers[toOffset[0]]
if (toOffset[1]) {
destination.set(lastBuf.getChannelData(channel).subarray(0, toOffset[1]), offset - initialOffset)
}
}
//put data from array to channel
AudioBufferList.prototype.copyToChannel = function (source, channel, startInChannel) {
if (startInChannel == null) startInChannel = 0
var offsets = this.offset(startInChannel)
var offset = startInChannel - offsets[1]
AudioBufferList.prototype.copyToChannel = function (source, channel, from) {
if (from == null) from = 0
from = nidx(from, this.length)
var offsets = this.offset(from)
var offset = from - offsets[1]
for (var i = offsets[0], l = this.buffers.length; i < l; i++) {

@@ -76,3 +86,3 @@ var buf = this.buffers[i]

if (channel < buf.numberOfChannels) {
data.set(source.subarray(Math.max(offset, startInChannel), offset + data.length), Math.max(0, startInChannel - offset));
data.set(source.subarray(Math.max(offset, from), offset + data.length), Math.max(0, from - offset));
}

@@ -83,37 +93,4 @@ offset += buf.length

//return float array with channel data
AudioBufferList.prototype.getChannelData = function (channel, from, to) {
if (from == null) from = 0
if (to == null) to = this.length
from = nidx(from, this.length)
to = nidx(to, this.length)
if (!this.buffers.length || from === to) return new Float32Array()
//shortcut single buffer preserving subarraying
if (this.buffers.length === 1) {
return this.buffers[0].getChannelData(channel).subarray(from, to)
}
var floatArray = this.buffers[0].getChannelData(0).constructor
var data = new floatArray(to - from)
var fromOffset = this.offset(from)
var toOffset = this.offset(to)
var firstBuf = this.buffers[fromOffset[0]]
data.set(firstBuf.getChannelData(channel).subarray(fromOffset[1]))
var offset = -fromOffset[1] + firstBuf.length
for (var i = fromOffset[0] + 1, l = toOffset[0]; i < l; i++) {
var buf = this.buffers[i]
data.set(buf.getChannelData(channel), offset);
offset += buf.length
}
var lastBuf = this.buffers[toOffset[0]]
data.set(lastBuf.getChannelData(channel).subarray(0, toOffset[1]), offset)
return data
}
//patch BufferList methods

@@ -138,3 +115,3 @@ AudioBufferList.prototype.append = function (buf) {

else if (buf) {
buf = new AudioBuffer(this.numberOfChannels || 2, buf)
buf = util.create(buf, this.numberOfChannels)
this._appendBuffer(buf)

@@ -188,5 +165,5 @@ }

if (srcStart >= this.length)
return dst || new AudioBuffer(this.numberOfChannels, 0)
return dst || new AudioBuffer(null, {length: 0})
if (srcEnd <= 0)
return dst || new AudioBuffer(this.numberOfChannels, 0)
return dst || new AudioBuffer(null, {length: 0})

@@ -226,3 +203,3 @@ var copy = !!dst

if (!copy) // a slice, we need something to copy in to
dst = new AudioBuffer(this.numberOfChannels, len)
dst = util.create(len, this.numberOfChannels)

@@ -293,2 +270,3 @@ for (i = off[0]; i < this.buffers.length; i++) {

this.length = 0
this.buffers = null
}

@@ -330,3 +308,3 @@

var offset = this.offset(offset)
offset = this.offset(offset)

@@ -452,4 +430,2 @@ //convert any type of source to audio buffer list

let middle = this.buffers.slice(fromOffset[0], toOffset[0] + 1)
if (options.reversed) {

@@ -456,0 +432,0 @@ let offset = to - toOffset[1]

{
"name": "audio-buffer-list",
"version": "2.0.7",
"version": "3.0.0",
"description": "Data structure for sequence of AudioBuffers",

@@ -34,5 +34,4 @@ "main": "index.js",

"dependencies": {
"audio-buffer": "^3.0.0",
"audio-buffer-utils": "^4.1.1",
"inherits": "^2.0.3",
"audio-buffer": "^4.0.1",
"audio-buffer-utils": "^5.0.0",
"is-audio-buffer": "^1.0.5",

@@ -44,5 +43,4 @@ "is-plain-obj": "^1.1.0",

"devDependencies": {
"audio-through": "^2.2.2",
"tape": "^4.6.3"
}
}

@@ -12,6 +12,7 @@ # audio-buffer-list [![Build Status](https://travis-ci.org/audiojs/audio-buffer-list.svg?branch=master)](https://travis-ci.org/audiojs/audio-buffer-list) [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Greenkeeper badge](https://badges.greenkeeper.io/audiojs/audio-buffer-list.svg)](https://greenkeeper.io/)

const AudioBuffer = require('audio-buffer')
const util = require('audio-buffer-utils')
let abl = new AudioBufferList(new AudioBuffer(1, [0, .1, .2, .3]), new AudioBuffer(1, 100))
let abl = new AudioBufferList(util.create([0, .1, .2, .3]), util.create(100))
abl.append(new AudioBuffer(1, 100))
abl.append(util.create(100))

@@ -27,8 +28,2 @@ abl.length // 204

* [new AudioBufferList(src, opts?)](#new-audiobufferlistsource-options)
* [list.buffers](#listbuffers)
* [list.length](#listlength)
* [list.duration](#listduration)
* [list.numberOfChannels](#listnumberofchannels)
* [list.sampleRate](#listsamplerate)
* [list.offset(idx)](#listoffsetsample)
* [list.append(buf)](#listappendbuffer)

@@ -45,8 +40,8 @@ * [list.insert(idx?, buf)](#listinsertoffset0-buffer)

* [list.repeat(times)](#listrepeatcount)
* [list.getChannelData(ch, from?, to?)](#listgetchanneldatachannel-from0-to-0)
* [list.copy(dst?, from?, to?)](#listcopydest-start0-end-0)
* [list.copyFromChannel(dst, ch, offset?)](#listcopyfromchannelarr-channel-startinchannel0)
* [list.copyToChannel(src, ch, offset?)](#listcopytochannelarr-channel-startinchannel0)
* [list.copyFromChannel(dst, ch, from?, to?)](#listcopyfromchannelarr-channel-startinchannel0)
* [list.copyToChannel(src, ch, from?)](#listcopytochannelarr-channel-startinchannel0)
* [list.split(a, b, c, ...)](#listsplita-b-c-)
* [list.join(from?, to?)](#listjoinstart0-end-0)
* [list.offset(idx)](#listoffsetsample)
* [list.destroy()](#listdestroy)

@@ -62,26 +57,11 @@

### `list.buffers`
The created list instance contains the following properties:
Sequence of audio buffers with actual data.
* `list.buffers` − sequence of audio buffers with actual data.
* `list.length` − total length of list in samples, i.e. sum of inner buffer lengths.
* `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.length`
Total length of list in samples, i.e. sum of inner buffer lengths.
### `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.offset(sample)`
Return `[bufIdx, offset]` pair for any sample number. `bufIdx` is the number of buffer in the list, `offset` is sample offset inside of that buffer.
### `list.append(buffer)`

@@ -117,17 +97,15 @@

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.
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 absolute `buffer` offset in new list, `index` reflects buffer count.
```js
list = list.map((buf, idx, offset) => {
for (let c = 0; c < channels; c++) {
let data = buf.getChannelData(channel)
for (let c = 0; c < channels; c++) {
let data = buf.getChannelData(c)
//start buffer from the subset may start earlier than the subset
//end buffer from the subset may end later than the subset
for (let i = Math.max(from - offset, 0),
l = Math.min(to - offset, buf.length);
i < l; i++) {
data[i] = process(data[i])
}
}
//start buffer from the subset may start earlier than the subset
//end buffer from the subset may end later than the subset
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)

@@ -148,15 +126,11 @@ ```

### `list.getChannelData(channel, from=0, to=-0)`
Return _FloatArray_ with merged data for the channel.
### `list.copy(dest?, start=0, end=-0)`
Put data into destination _AudioBuffer_ or create one.
Put data into destination _AudioBuffer_ or create one. It is like `slice`, but returns an _AudioBuffer_.
### `list.copyFromChannel(arr, channel, startInChannel=0)`
### `list.copyFromChannel(dest, channel, startInChannel=0, end=-0)`
Put data from the channel to destination _FloatArray_. Optional `startInChannel` defines offset in the channel to start from.
### `list.copyToChannel(arr, channel, startInChannel=0)`
### `list.copyToChannel(src, channel, startInChannel=0, end=-0)`

@@ -167,3 +141,3 @@ Put data from the source _FloatArray_ into channel, optionally starting at `startInChannel` offset.

Split list at the indicated indexes. That increases number of inner buffers and that's it.
Split list at the indicated indexes. That increases number of inner buffers.

@@ -174,2 +148,6 @@ ### `list.join(start=0, end=-0)`

### `list.offset(idx)`
Return `[bufIdx, offset]` pair for any sample number. `bufIdx` is the number of buffer in the list, `offset` is sample offset inside of that buffer.
### `list.destroy()`

@@ -181,5 +159,5 @@

* [audio](https://github.com/audiojs/audio) — high-level class for audio
* [audio-buffer](https://github.com/audiojs/audio-buffer) — audio buffer class for nodejs and browser
* [audio-buffer-utils](https://github.com/audio-buffer-utils) — toolset for audio buffers
* [buffer-list](https://npmjs.org/package/bl) — canonical BufferList implementation
* [audio](https://github.com/audiojs/audio) — high-level class for audio manipulations.
* [audio-buffer](https://github.com/audiojs/audio-buffer) — audio buffer class for nodejs and browser.
* [audio-buffer-utils](https://github.com/audio-buffer-utils) — toolset for audio buffers.
* [buffer-list](https://npmjs.org/package/bl) — canonical BufferList implementation.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc