Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scijs/periodic-function
List of periodic functions normalized to 0..1 range
https://github.com/scijs/periodic-function
Last synced: about 1 month ago
JSON representation
List of periodic functions normalized to 0..1 range
- Host: GitHub
- URL: https://github.com/scijs/periodic-function
- Owner: scijs
- Created: 2017-06-22T07:16:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-25T17:00:47.000Z (about 4 years ago)
- Last Synced: 2024-10-31T17:27:54.429Z (about 1 month ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 55
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-javascript-audio - scijs/periodic-function - oscillator modifiers (sawtooth, square, sine, pulse, step, interpolate, etc) as JS functions, normalized 0..1 (Sound creation / Low frequency oscillators ("LFOs"):)
README
# periodic-function [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://img.shields.io/travis/dfcreative/periodic-function.svg)](https://travis-ci.org/dfcreative/periodic-function)
Collection of periodic functions with period normalized to turns.
## Usage
[![npm install periodic-function](https://nodei.co/npm/periodic-function.png?mini=true)](https://npmjs.org/package/periodic-function/)
```js
const fn = require('periodic-function/')//π radians
let halfTurn = fn(.5)//2π radians
let fullTurn = fn(1)
```## API
### let fn = require('periodic-function/\')
The `fn` takes the amount of turn `t` as the first argument and optional parameters. The list of available functions:
| Signature | Waveform | Meaning |
---|:---:|---|
|sine(t, phase=0)
| ![sine](img/sine.png) | `Math.sin` normalized to `0..1` rather than radians `0..2π`. To turn into cos, set `phase=.25`. |
|triangle(t, ratio=0.5)
| ![triangle](img/triangle.png) | Triangular waveform with regulated ratio. To turn into sawtooth set `ratio=0` or `ratio=1`. |
|sawtooth(t, inverse=false)
| ![sawtooth](img/sawtooth.png) | Edge case of triangular waveform, whether descending or ascending. |
|square(t, ratio=0.5)
| ![square](img/square.png) | Rectangular waveform with regulated ratio. To turn into pulse set `ratio=0`. |
|pulse(t, tlr=0)
| ![pulse](img/pulse.png) | Delta-pulse, which is `1` at `0` and `0` anywhere else. Pass `tlr` as a precision tolerance, ie. `1e-5`. |
|fourier(t, real, imag?, normalize=false)
| ![fourier](img/fourier.png) | [Fourier Series](https://en.wikipedia.org/wiki/Fourier_series) coefficients, ie. harmonics. `0` harmonic is static level, `1`st is base frequency, `2`nd is double base frequency, `3`rd is triple etc. Set `normalize=true` to bring max harmonic to `1`. |
|clausen(t, limit=10)
| ![clausen](img/clausen.png) | [Clausen function](https://en.wikipedia.org/wiki/Clausen_function). Pass `limit` to indicate number of iterations, precision/performance tradeoff. |
|step(t, samples)
| ![step](img/step.png) | [Step function](https://en.wikipedia.org/wiki/Step_function), picks closest sample value out of a set. |
|interpolate(t, samples)
| ![interpolate](img/interpolate.png) | Interpolates between closest values in a sample set. |
|noise(t)
| ![noise](img/noise.png) | Repeated sample of noise. |If you feel like it is not complete list of you know example of a good periodic function, suitable for dsp, welcome to [contribute](https://github.com/dfcreative/periodic-function/issues).
## Related
* [audio-oscillator](https://github.com/audiojs/audio-oscillator)
* [createPeriodicWave](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)
* [List of periodic functions](https://en.wikipedia.org/wiki/List_of_periodic_functions)## Credits
© 2017 Dima Yv. MIT License