A digital signal processing library in Javascript
This is my journey to study dsp. This library is not intended to be used.. There are excellent dsp js libraries out there, for example:
Since I usually learn by coding, this is my code learning result. I'm building while trying to understand the main concepts of dsp targeting audio applications.
Work in progress. Experimental (API). Not sure if it will be published, currently is just a playground to understand DSP concepts.
const dsp = require('dsp-kit')
const signal = dsp.fill(1024, (x) => Math.sin(x))
const { magnitudes, phases } = dsp.spectrum(dsp.fft(1024, signal))
// generate a signal adding two sines
const oscillator = dsp.fill(1024, dsp.add(dsp.sine(440), dsp.sine(880)))
This is a multimodule repository, each functionallity wrapped in its own package:
- dsp: a facade module that exposes some modules as a coherent package. Probably you just need to install and use that one (unless you are concerned with code size or some esoteric features)
- array: array utilities
- dft: discrete fourier implementation (very slow, but easy to understand)
- elastica: timestretch for web audio api (it will be extracted it is own repo when ready).
- fft: the default fast fourier algorithm
- fft-radix2: fast forward fourier algorithm using a Cooley-Tukey radix-2 algorithm
- fft-asm: a high performance fft implementation based on asm.js (work in progress)
- fftshift: rotate arrays to perform zero-phasing windowing
- ola: overlap and add algorithm for time strething
- oscillator: work in progress
- noise: functions to generate noise
- signal: generate and manipulate signals
- phase-vocoder: phase vocoder algorithm to perform time strething and other signal transformations
- rfft: real split radix FFT (work in progress)
- spectrum: spectrum manipulation utilities
- waa: web audio api interop utilities (wip)
- window: windowing functions
But currently is not updated to latests version. You can install from this repository:
npm i git@github.com:oramics/dsp-kit.git
Read the generated API documentation
Clone the repo and install dependencies: npm install
and init lerna: lerna bootstrap
Then you can list all the npm tasks with npm run
:
- run tests:
npm test
- run benchmarks:
npm run benchmark
- generate documentation:
npm run docs
Large part of the code is based on the now unmantained dsp.js library by @corbanbrook, that in turn was based on code samples by Almer Thie.
Also, this library takes (steal) inspiration from:
- https://github.com/kunstmusik/pink
- https://github.com/colinbdclark/Flocking
- https://github.com/mohayonao/timbre.js/
- https://github.com/MTG/sms-tools
- https://github.com/charlieroberts/genish.js
## References
- https://dsprelated.com in general, and Spectral Audio Signal Processing in particular: https://www.dsprelated.com/freebooks/sasp/
- http://www.dafx.de/
- The awesome Circles, sines and signals by Jack Schaedler
- Thanks Xavier for the Digital signal processing for music applications course in coursera.
- The most accessible book I found: Understanding Digital Signal by Richard G. Lyons.
- Spectrum and spectral density estimation by the Discrete Fourier transform (DFT), including a comprehensive list of window functions and some new flat-top windows by G. Heinzel and others.