audio-buffer-list
Advanced tools
Comparing version 4.1.0 to 5.0.0
83
index.js
@@ -19,3 +19,3 @@ /** | ||
// @constructor | ||
function AudioBufferList(arg, options) { | ||
@@ -47,6 +47,2 @@ if (!(this instanceof AudioBufferList)) return new AudioBufferList(arg, options) | ||
//test instance | ||
AudioBufferList.isInstance = function (a) { | ||
return a instanceof AudioBufferList | ||
} | ||
@@ -114,3 +110,2 @@ //copy from channel into destination array | ||
//patch BufferList methods | ||
@@ -142,15 +137,2 @@ AudioBufferList.prototype.append = function (buf) { | ||
AudioBufferList.prototype.offset = function _offset (offset) { | ||
var tot = 0, i = 0, _t | ||
if (offset === 0) return [ 0, 0 ] | ||
for (; i < this.buffers.length; i++) { | ||
_t = tot + this.buffers[i].length | ||
if (offset < _t || i == this.buffers.length - 1) | ||
return [ i, offset - tot ] | ||
tot = _t | ||
} | ||
} | ||
AudioBufferList.prototype._appendBuffer = function (buf) { | ||
@@ -178,2 +160,16 @@ if (!buf) return this | ||
AudioBufferList.prototype.offset = function _offset (offset) { | ||
var tot = 0, i = 0, _t | ||
if (offset === 0) return [ 0, 0 ] | ||
for (; i < this.buffers.length; i++) { | ||
_t = tot + this.buffers[i].length | ||
if (offset < _t || i == this.buffers.length - 1) | ||
return [ i, offset - tot ] | ||
tot = _t | ||
} | ||
} | ||
//copy data to destination audio buffer | ||
@@ -257,2 +253,12 @@ AudioBufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) { | ||
//create a new list with the same data | ||
AudioBufferList.prototype.clone = function clone (start, end) { | ||
var i = 0, copy = new AudioBufferList(0, this.numberOfChannels), sublist = this.slice(start, end) | ||
for (; i < sublist.buffers.length; i++) | ||
copy.append(util.clone(sublist.buffers[i])) | ||
return copy | ||
} | ||
//do superficial handle | ||
@@ -288,12 +294,3 @@ AudioBufferList.prototype.slice = function slice (start, end) { | ||
//clone with preserving data | ||
AudioBufferList.prototype.clone = function clone (start, end) { | ||
var i = 0, copy = new AudioBufferList(0, this.numberOfChannels), sublist = this.slice(start, end) | ||
for (; i < sublist.buffers.length; i++) | ||
copy.append(util.clone(sublist.buffers[i])) | ||
return copy | ||
} | ||
//clean up | ||
@@ -313,3 +310,3 @@ AudioBufferList.prototype.destroy = function destroy () { | ||
if (!times) { | ||
this.consume(this.length) | ||
this.remove(0, this.length) | ||
return this | ||
@@ -345,4 +342,5 @@ } | ||
source = new AudioBufferList(source) | ||
this.buffers.splice.apply(this.buffers, [offset[0], 0].concat(source.buffers)) | ||
this.buffers.splice.apply(this.buffers, [offset[0] + (offset[1] ? 1 : 0), 0].concat(source.buffers)) | ||
//update params | ||
@@ -392,27 +390,2 @@ this.length += source.length | ||
//delete samples from the list, return self | ||
AudioBufferList.prototype.delete = function () { | ||
this.remove.apply(this, arguments) | ||
return this | ||
} | ||
//remove N sampled from the beginning | ||
AudioBufferList.prototype.consume = function consume (size) { | ||
while (this.buffers.length) { | ||
if (size >= this.buffers[0].length) { | ||
size -= this.buffers[0].length | ||
this.length -= this.buffers[0].length | ||
this.buffers.shift() | ||
} else { | ||
//util.subbuffer would remain buffer in memory though it is faster | ||
this.buffers[0] = util.subbuffer(this.buffers[0], size) | ||
this.length -= size | ||
break | ||
} | ||
} | ||
this.duration = this.length / this.sampleRate | ||
return this | ||
} | ||
//return new list via applying fn to each buffer from the indicated range | ||
@@ -419,0 +392,0 @@ AudioBufferList.prototype.map = function map (fn, from, to) { |
{ | ||
"name": "audio-buffer-list", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Data structure for sequence of AudioBuffers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,8 +30,4 @@ # 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/) | ||
* [list.remove(idx?, len)](#listremoveoffset0-count) | ||
* [list.delete(idx?, len)](#listdeleteoffset0-count) | ||
* [list.consume(len)](#listconsumecount) | ||
* [list.slice(from?, to?)](#listslicestart0-end-0) | ||
* [list.clone(from?, to?)](#listclonestart0-end-0) | ||
* [list.map(fn, from?, to?)](#listmapbuffer-index-offset--bufferbool-from0-to-0) | ||
* [list.repeat(times)](#listrepeatcount) | ||
* [list.map(val|fn, from?, to?)](#listmapbuffer-index-offset--bufferbool-from0-to-0) | ||
* [list.copy(dst?, from?, to?)](#listcopydest-start0-end-0) | ||
@@ -44,4 +40,5 @@ * [list.copyFromChannel(dst, ch, from?, to?)](#listcopyfromchannelarr-channel-startinchannel0) | ||
* [list.destroy()](#listdestroy) | ||
* [AudioBufferList.isInatance(arg)](#audiobufferlistisinstancearg) | ||
<!-- * [list.repeat(times)](#listrepeatcount) --> | ||
### `new AudioBufferList(source, options?)` | ||
@@ -76,10 +73,3 @@ | ||
### `list.delete(offset=0, count)` | ||
Same as `list.remove`, but returns current list with deleted part being lost. That allows for different type of chainability. | ||
### `list.consume(count)` | ||
Delete data from the beginning. Returns current list. | ||
### `list.slice(start=0, end=-0)` | ||
@@ -89,9 +79,5 @@ | ||
### `list.clone(start=0, end=-0)` | ||
Return copy of the list, consisting of cloned buffers. | ||
### `list.map(mapper, from=0, to=-0, {reversed: false})` | ||
Map buffers of part of the list, defined by `from` and `to` arguments. Modifies list in-place. | ||
Map buffers from the interval defined by `from` and `to` arguments. Modifies list in-place. | ||
@@ -148,6 +134,3 @@ Mapper function has signature `(buffer, idx, offset) => buffer`. `buffer` is an audio buffer to process, `idx` is buffer number, and `offset` is first buffer sample absolute offset. If mapper returns `undefined`, the buffer is preserved. If mapper returns `null`, the buffer is discarded. If mapper returns `false`, iterations are stopped. | ||
### `AudioBufferList.isInstance(arg)` | ||
Check if passed argument is instance of _AudioBufferList_. | ||
## See also | ||
@@ -154,0 +137,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21076
5
425
137