0.0.1 • Published 7 years ago

dsp-buffer v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

buffer

Array buffer manipulation functions

npm install dsp-buffer

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(...)

buffer~zeros(size) ⇒ Array

Create a buffer (a Float64Array) filled with zeros

Kind: inner method of buffer
Returns: Array - the buffer

ParamType
sizeInteger

buffer~generate(buffer, fn)

Generate a buffer using a function

Kind: inner method of buffer

ParamTypeDescription
bufferNumber | ArrayThe buffer (to reuse) or a buffer length to create one
fnfunctionthe 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))

buffer~map(fn, source, destination) ⇒ Array

Map a buffer with a function

This function can be partially applied (see examples)

Kind: inner method of buffer
Returns: Array - the mapped buffer

ParamTypeDescription
fnfunctionthe mapping function
sourceArraythe source
destinationArray(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

ParamTypeDescription
sourceArraythe source buffer
destinationArray(Optional) the destination buffer (a new buffer is created if no one is provided)

Example

buffer.copy(src, dest)