dsp-bufferdeprecated

Functions to create and manipulate Float64Array buffers

Usage no npm install needed!

<script type="module">
  import dspBuffer from 'https://cdn.skypack.dev/dsp-buffer';
</script>

README

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

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

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

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)