audio-buffer-list
Advanced tools
Comparing version 1.4.0 to 1.5.0
50
index.js
@@ -17,2 +17,3 @@ /** | ||
var nidx = require('negative-index') | ||
var isPlainObj = require('is-plain-obj') | ||
@@ -30,3 +31,3 @@ module.exports = AudioBufferList | ||
this._bufs = [] | ||
this._bufs = [] | ||
this.length = 0 | ||
@@ -151,6 +152,3 @@ this.duration = 0 | ||
else if (buf != null) { | ||
if (typeof buf == 'number') { | ||
buf = [buf] | ||
} | ||
buf = new AudioBuffer(this.numberOfChannels, buf) | ||
buf = new AudioBuffer(this.numberOfChannels || 2, buf) | ||
this._appendBuffer(buf) | ||
@@ -180,3 +178,4 @@ } | ||
AudioBufferList.prototype.get = function get (index, channel) { | ||
return this.slice(index, index + 1).getChannelData(channel || 0)[0] | ||
let offset = this._offset(index) | ||
return this._bufs[offset[0]].getChannelData(channel || 0)[offset[1]] | ||
} | ||
@@ -352,4 +351,5 @@ | ||
var data = this | ||
for (var i = 1; i < times; i++) { | ||
data = data.slice() | ||
data = new AudioBufferList(data.slice()) | ||
this.append(data) | ||
@@ -410,3 +410,3 @@ } | ||
//delete buffers | ||
this._bufs.splice(offsetsLeft[0], offsetsRight[0] - offsetsLeft[0] + 1) | ||
let deleted = this._bufs.splice(offsetsLeft[0], offsetsRight[0] - offsetsLeft[0] + 1) | ||
@@ -420,3 +420,3 @@ //insert buffers | ||
return this | ||
return deleted | ||
} | ||
@@ -460,5 +460,8 @@ | ||
//apply fn to every buffer for the indicated range | ||
AudioBufferList.prototype.each = function each (fn, from, to) { | ||
if (from == null) from = 0 | ||
if (to == null) to = this.length | ||
AudioBufferList.prototype.each = function each (fn, from, to, reversed) { | ||
let options = arguments[arguments.length - 1] | ||
if (!isPlainObj(options)) options = {reversed: false} | ||
if (typeof from != 'number') from = 0 | ||
if (typeof to != 'number') to = this.length | ||
from = nidx(from, this.length) | ||
@@ -470,13 +473,24 @@ to = nidx(to, this.length) | ||
let offset = from - fromOffset[1] | ||
let middle = this._bufs.slice(fromOffset[0], toOffset[1] + 1) | ||
for (let i = fromOffset[0], l = toOffset[0]+1; i < l; i++) { | ||
let buf = this._bufs[i] | ||
fn.call(this, buf, i, offset, this._bufs, this) | ||
offset += buf.length | ||
if (options.reversed) { | ||
let offset = to - toOffset[1] | ||
for (let i = toOffset[0], l = fromOffset[0]; i >= l; i--) { | ||
let buf = this._bufs[i] | ||
let res = fn.call(this, buf, i, offset, this._bufs, this) | ||
if (res === false) break | ||
offset -= buf.length | ||
} | ||
} | ||
else { | ||
let offset = from - fromOffset[1] | ||
for (let i = fromOffset[0], l = toOffset[0]+1; i < l; i++) { | ||
let buf = this._bufs[i] | ||
let res = fn.call(this, buf, i, offset, this._bufs, this) | ||
if (res === false) break | ||
offset += buf.length | ||
} | ||
} | ||
return this; | ||
} |
{ | ||
"name": "audio-buffer-list", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Data structure for sequence of AudioBuffers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,7 +63,6 @@ # audio-buffer-list [![Build Status](https://travis-ci.org/audiojs/audio-buffer-list.svg?branch=master)](https://travis-ci.org/audiojs/audio-buffer-list) [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) | ||
### `list.each((buffer, index, offset) => {}, from=0, to=-0)` | ||
### `list.each((buffer, index, offset) => {}, from=0, to=-0, {reversed}?)` | ||
Iterate over buffers from the indicated range. Buffers can be modified in-place during the iterating. | ||
Iterate over buffers from the indicated range. Buffers can be modified in-place during the iterating. Return `false` to break loop. Pass `{reversed: true}` as the last argument to iterate in reverse order. | ||
## [AudioBuffer](https://github.com/audiojs/audio-buffer) properties & methods | ||
@@ -70,0 +69,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
21677
433
138