audio-buffer-list
Advanced tools
Comparing version 1.1.0 to 1.2.0
109
index.js
@@ -17,2 +17,3 @@ /** | ||
var context = require('audio-context') | ||
var nidx = require('negative-index') | ||
@@ -117,27 +118,2 @@ module.exports = AudioBufferList | ||
//repeat contents N times | ||
AudioBufferList.prototype.repeat = function (times) { | ||
times = Math.floor(times) | ||
if (!times && times !== 0 || !Number.isFinite(times)) throw RangeError('Repeat count must be non-negative number.') | ||
if (!times) { | ||
this.consume(this.length) | ||
return this | ||
} | ||
if (times === 1) return this | ||
var data = this | ||
for (var i = 1; i < times; i++) { | ||
data = data.slice() | ||
this.append(data) | ||
} | ||
return this | ||
} | ||
//patch BufferList methods | ||
@@ -338,17 +314,84 @@ AudioBufferList.prototype.append = function (buf) { | ||
// Remove buffer dep | ||
// Additional methods | ||
//repeat contents N times | ||
AudioBufferList.prototype.repeat = function (times) { | ||
times = Math.floor(times) | ||
if (!times && times !== 0 || !Number.isFinite(times)) throw RangeError('Repeat count must be non-negative number.') | ||
// AudioBufferList.prototype.insert = function (what, start) { | ||
if (!times) { | ||
this.consume(this.length) | ||
return this | ||
} | ||
// } | ||
if (times === 1) return this | ||
// AudioBufferList.prototype.delete = function (from, duration) { | ||
var data = this | ||
for (var i = 1; i < times; i++) { | ||
data = data.slice() | ||
this.append(data) | ||
} | ||
// } | ||
return this | ||
} | ||
// AudioBufferList.prototype.splice = function (from, del, insert) { | ||
//insert new buffer/buffers at the offset | ||
AudioBufferList.prototype.insert = function (source, offset) { | ||
if (offset == null) return this.append(source) | ||
// } | ||
offset = nidx(offset, this.length) | ||
var offsets = this._offset(offset) | ||
var leftBuf = offsets[1] ? util.slice(this._bufs[offsets[0]], 0, offsets[1]) : null | ||
var rightBuf = offsets[1] !== this._bufs[offsets[0]].length ? util.slice(this._bufs[offsets[0]], offsets[1]) : null | ||
//convert any type of source to audio buffer list | ||
source = new AudioBufferList(source) | ||
//form new list | ||
let bufs = this._bufs.slice(0, offsets[0]) | ||
if (leftBuf) bufs.push(leftBuf) | ||
bufs = bufs.concat(source._bufs) | ||
if (rightBuf) bufs.push(rightBuf) | ||
bufs = bufs.concat(this._bufs.slice(offsets[0] + 1)) | ||
this._bufs = bufs | ||
//update params | ||
this.length += source.length | ||
this.duration += source.duration | ||
return this | ||
} | ||
//delete N samples from any position | ||
AudioBufferList.prototype.delete = function (count, offset) { | ||
if (offset == null) offset = 0 | ||
if (!count) return this | ||
if (count < 0) { | ||
count = -count | ||
offset -= count | ||
} | ||
offset = nidx(offset, this.length) | ||
var offsetsLeft = this._offset(offset) | ||
var offsetsRight = this._offset(offset + count) | ||
//same segment slice | ||
var leftBuf = offsetsLeft[1] ? util.slice(this._bufs[offsetsLeft[0]], 0, offsetsLeft[1]) : null; | ||
var rightBuf = this._bufs[offsetsRight[0]].length !== offsetsRight[1] ? util.slice(this._bufs[offsetsRight[0]], offsetsRight[1]) : null; | ||
//delete buffers | ||
this._bufs.splice(offsetsLeft[0], offsetsRight[0] - offsetsLeft[0] + 1) | ||
//insert buffers | ||
if (rightBuf) this._bufs.splice(offsetsLeft[0], 0, rightBuf) | ||
if (leftBuf) this._bufs.splice(offsetsLeft[0], 0, leftBuf) | ||
this.length -= count | ||
this.duration = this.length / this.sampleRate | ||
return this | ||
} |
{ | ||
"name": "audio-buffer-list", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Data structure for sequence of AudioBuffers", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"is-audio-buffer": "^1.0.5", | ||
"negative-index": "^1.0.2", | ||
"object-assign": "^4.1.1" | ||
@@ -42,0 +43,0 @@ }, |
@@ -31,2 +31,30 @@ # 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.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. | ||
## AudioBuffer properties & methods | ||
### `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)` | ||
@@ -44,6 +72,28 @@ | ||
### `list.repeat(count)` | ||
Repeats contents of the list specified number of times. Modifies list in-place. | ||
## BufferList properties and methods | ||
### `list.length` | ||
Total length of list in samples, i.e. sum of inner buffer lengths. | ||
### `list.append(buffer)` | ||
### `list.slice(start?, end?)` | ||
### `list.shallowSlice(start?, end?)` | ||
### `list.get(idx, channel)` | ||
### `list.duplicate()` | ||
### `list.copy(dest, destStart?, srcStart?, srcEnd?)` | ||
### `list.consume(length)` | ||
## Stream methods | ||
## See also | ||
@@ -50,0 +100,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
16996
359
103
8
+ Addednegative-index@^1.0.2