README
buffer
Array buffer manipulation functions
This is part of dsp-kit
Example
var buffer = require('dsp-buffer')
const sine = buffer.generate(1024, (x) => Math.sin(0.5 * x))
Example
var dsp = require('dsp-kit')
dsp.buffer.generate(...)
Array
buffer~zeros(size) ⇒ Create a buffer (a Float64Array) filled with zeros
Kind: inner method of buffer
Returns: Array
- the buffer
Param | Type |
---|---|
size | Integer |
buffer~generate(buffer, fn)
Generate a buffer using a function
Kind: inner method of buffer
Param | Type | Description |
---|---|---|
buffer | Number | Array |
The buffer (to reuse) or a buffer length to create one |
fn | function |
the generator function. It receives the following parameters: - n: a number from [0..1] - index: a number from [0...length] - length: the buffer length |
Example
const sine = buffer.generate(10, (x) => Math.sin(x))
Array
buffer~map(fn, source, destination) ⇒ Map a buffer with a function
This function can be partially applied (see examples)
Kind: inner method of buffer
Returns: Array
- the mapped buffer
Param | Type | Description |
---|---|---|
fn | function |
the mapping function |
source | Array |
the source |
destination | Array |
(Optional) if no one is provided, a new buffer is created |
Example
const sine = buffer.generate(1024, (x) => Math.sin(x))
buffer.map((x) => x * 2, sine) // => a buffer with the gain doubled
// partially applied
const doubleGain = buffer.map((x) => x * 2)
doubleGain(buffer) // => a buffer with the gain doubled
buffer~copy(source, destination)
Copy two buffers
Kind: inner method of buffer
Param | Type | Description |
---|---|---|
source | Array |
the source buffer |
destination | Array |
(Optional) the destination buffer (a new buffer is created if no one is provided) |
Example
buffer.copy(src, dest)