Skip to content

Commit

Permalink
Add TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Apr 30, 2017
1 parent fcd53ac commit cbe79ac
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

Utility functions for [_AudioBuffers_](https://github.com/audiojs/audio-buffer) in web-audio and node. Optimized for performance.

* [util.create(src, ch?, rate?)](#utilcreatedatalength-channels--2-samplerate--44100)
* [util.shallow(buf)](#utilshallowbuffer)
* [util.clone(buf)](#utilclonebuffer)
* [util.copy(buf, dst, start?)](#utilcopyfrombuffer-tobuffer-offset--0)
* [util.reverse(src, dst?, start?, end?)](#utilreversebuffer-target-start0-end-0)
* [util.invert(src, dst?, start?, end?)](#utilinvertbuffer-target-start0-end-0)
* [util.zero(buf)](#utilzerobuffer)
* [util.noise(buf)](#utilnoisebuffer)
* [util.equal(a, b, ...)](#utilequalbuffera-bufferb-)
* [util.fill(buf, dst?, val, start?, end?)](#utilfillbuffer-target-valuevalue-i-channel--value-start--0-end---0)
* [util.slice(buf, start?, end?)](#utilslicebuffer-start--0-end---0)
* [util.subbuffer(buf, start?, end?)](#utilsubbufferbuffer-start--0-end---0)
* [util.concat(a, b, ...)](#utilconcatbuffer1-buffer2-buffer3-buffern-)
* [util.resize(buf, len)](#utilresizebuffer-length)
* [util.pad(buf, len, val?)](#utilpadbufferlength-lengthbuffer-value--0)
* [util.shift(buf, off)](#utilshiftbuffer-offset)
* [util.rotate(buf, off)](#utilrotatebuffer-offset)
* [util.normalize(buf, dst?, start?, end?)](#utilnormalizebuffer-target-start--0-end---0)
* [util.removeStatic(buf, dst?, start?, end?)](#utilremovestaticbuffer-target-start--0-end---0)
* [util.trim(buf, lvl)](#utiltrimbuffer-threshold--0)
* [util.mix(a, b, amt?, off?)](##utilmixbuffera-bufferb-ratiovala-valb-i-channel--val-offset--0)
* [util.size(buf)](#utilsizebuffer)
* [util.data(buf, dst?)](#utildatabuffer-data)

## Usage

[![npm install audio-buffer-utils](https://nodei.co/npm/audio-buffer-utils.png?mini=true)](https://npmjs.org/package/audio-buffer-utils/)
Expand All @@ -13,7 +37,7 @@ _AudioBuffer_ data layout is considered horizontal, in that samples are arranged

Sample values range from `-1` to `1`, but not limited to it.

### `util.create(data|length, channels = 2, sampleRate = 44100)`
### `util.create(data|length, channels=2, sampleRate=44100)`
Create a new buffer from any argument.
Data can be a length, an array with channels' data, an other buffer or plain array.

Expand Down Expand Up @@ -52,7 +76,7 @@ let b = util.clone(a)
util.equal(a, b) //true
```

### `util.copy(fromBuffer, toBuffer, offset = 0)`
### `util.copy(fromBuffer, toBuffer, offset=0)`
Copy the data from one buffer to another, with optional offset. If length of `fromBuffer` exceeds `offset + toBuffer.length`, an error will be thrown.

### `util.reverse(buffer, target?, start=0, end=-0)`
Expand Down Expand Up @@ -82,7 +106,7 @@ if (util.equal(a, b, c)) {
}
```

### `util.fill(buffer, target?, value|(value, i, channel) => value, start = 0, end = -0)`
### `util.fill(buffer, target?, value|(value, i, channel)=>value, start=0, end=-0)`
Fill `buffer` with provided function or value.
Place data to `target` buffer, if any, otherwise modify `buffer` in-place (that covers _map_ functionality).
Pass optional `start` and `end` indexes.
Expand All @@ -94,13 +118,13 @@ let frequency = 440, rate = 44100
let a = util.create(2 * rate)

//populate with 440hz sine wave
util.fill(a, (value, i, channel) => Math.sin(Math.PI * 2 * frequency * i / rate))
util.fill(a, (value, i, channel)=>Math.sin(Math.PI * 2 * frequency * i / rate))
```

### `util.slice(buffer, start = 0, end = -0)`
### `util.slice(buffer, start=0, end=-0)`
Create a new buffer by slicing the current one.

### `util.subbuffer(buffer, start = 0, end = -0)`
### `util.subbuffer(buffer, start=0, end=-0)`
Create a new buffer by subreferencing the current one. The new buffer represents a handle for the source buffer, working on it's data.

### `util.concat(buffer1, [buffer2, buffer3], bufferN, ...)`
Expand All @@ -116,9 +140,9 @@ Initial data is whether sliced or filled with zeros. Combines `util.pad` and `ut
let b = util.resize(a, 2 * a.sampleRate)
```

### `util.pad(buffer|length, length|buffer, value = 0)`
### `util.padLeft(buffer, length, value = 0)`
### `util.padRight(buffer, length, value = 0)`
### `util.pad(buffer|length, length|buffer, value=0)`
### `util.padLeft(buffer, length, value=0)`
### `util.padRight(buffer, length, value=0)`
Right/left-pad buffer to the length, filling with value.

```js
Expand All @@ -139,7 +163,7 @@ Modify `buffer` in-place.
Shift signal in the time domain by `offset` samples, in circular fashion.
Modify `buffer` in-place.

### `util.normalize(buffer, target?, start = 0, end = -0)`
### `util.normalize(buffer, target?, start=0, end=-0)`
Normalize buffer by the amplitude, bring to -1..+1 range. Channel amplitudes ratio will be preserved. You may want to remove static level beforehead, because normalization preserves zero static level. Note that it is not the same as [array-normalize](https://github.com/dfcreative/array-noramalize).
Places data to `target` buffer, if any, otherwise modifies `buffer` in-place.

Expand All @@ -152,7 +176,7 @@ util.normalize(buf);
buf.getChannelData(0) // [0, .5, 0, -1]
```

### `util.removeStatic(buffer, target?, start = 0, end = -0)`
### `util.removeStatic(buffer, target?, start=0, end=-0)`
Remove DC (Direct Current) offset from the signal, i.e. remove static level, that is bring mean to zero. DC offset will be reduced for every channel independently.

```js
Expand All @@ -164,13 +188,13 @@ a.getChannelData(0) // [-.1, .1]
a.getChannelData(1) // [-.1, .1]
```

### `util.trim(buffer, threshold = 0)`
### `util.trimLeft(buffer, threshold = 0)`
### `util.trimRight(buffer, threshold = 0)`
### `util.trim(buffer, threshold=0)`
### `util.trimLeft(buffer, threshold=0)`
### `util.trimRight(buffer, threshold=0)`

Create buffer with trimmed zeros from the start and/or end, by the threshold amplitude.

### `util.mix(bufferA, bufferB, ratio|(valA, valB, i, channel) => val?, offset = 0)`
### `util.mix(bufferA, bufferB, ratio|(valA, valB, i, channel)=>val?, offset=0)`
Mix second buffer into the first one. Pass optional weight value or mixing function.

### `util.size(buffer)`
Expand Down

0 comments on commit cbe79ac

Please sign in to comment.