Skip to content

Latest commit

 

History

History

dsp

@thi.ng/dsp

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils.

Partially ported from other thi.ng projects (e.g. thi.ng/synstack, thi.ng/vexed-generation, toxiclibs).

Status

STABLE - used in production

Installation

yarn add @thi.ng/dsp

Dependencies

Usage examples

Several demos in this repo's /examples directory are using this package.

A selection:

fft-synth

screenshot

Interactive inverse FFT toy synth

Live demo | Source

poly-spline

Live demo | Source

webgl-ssao

screenshot

Live demo | Source

API

Generated API docs

IGen

  • add - adder
  • alt - alternating values
  • constant - constant value
  • cosP - trig-free cosine osc
  • exp - time-based exponential gain/decay (factory for mul)
  • impulse - impulse gen
  • line - line gen (factory for add)
  • madd - multiply-adder
  • mul - multiplier (exponential gain/decay)
  • reciprocal - fractional sequence (1, 1/2, 1/3, 1/4 etc.)
  • trigger - cyclic impulse

Higher order generators

  • comp - IGen composition (1-4 inputs)
  • addG - higher-order adder
  • product - product of input gens
  • sum - sum of input gens
  • wrapAroundG - folds input gen into given interval

Oscillators

  • osc - arbitrary function oscillator
  • modOsc - FM / FMAM oscillator
Stateless & band-unlimited:
  • comb()
  • mix() (HOF)
  • rect()
  • saw()
  • sin()
  • tri()
  • wavetable() (HOF)

Band-limited:

  • additive() (HOF)
  • squareAdditive()
  • sawAdditive()

LFO

Trigonometry free sin/cos oscillator / iterator based on a state-variable filter. Only useable for freq < ~2Hz.

Filters

The following diagrams show various combinations of oscillator signals and their filtered responses (with different cutoff/center frequencies). The red waveform is the original generated 1kHz signal.

All diagrams were generated with this script.

TODO

1-pole low pass

waveform

waveform

waveform

waveform

waveform

waveform

Frequency modulated osc & 1-pole low pass

waveform

waveform

waveform

waveform

waveform

1-pole all-pass

waveform

waveform

waveform

waveform

waveform

2-pole all-pass

The bandwidth of each filter is set to 1/2 of its center frequency.

waveform

waveform

waveform

waveform

waveform

DelayLine

Source

Ringbuffer / delay line for arbitrary values and support for tapping at any relative position.

  • DelayLine class

FFT

Source

  • fft()
  • ifft()
  • normalizeFFT()
  • denormalizeFFT()
  • scaleFFT()
  • complexArray()
  • conjugate()
  • spectrumMag()
  • spectrumPow() (optionally as dBFS)
  • spectrumPhase()
  • binFreq()
  • freqBin()
  • fftFreq()

Window functions

Source

  • window()
  • windowRect()
  • windowSin()
  • windowSinPow()
  • windowLanczos()
  • windowHann()
  • windowHamming()
  • windowBlackman()
  • windowBlackmanHarris()
  • windowNuttal()
  • windowBlackmanNuttal()
  • windowGauss()

Authors

Karsten Schmidt

License

© 2015 - 2020 Karsten Schmidt // Apache Software License 2.0