From 2b1ce3cca6d474a5e3fbf47c2c0ae78c5cee387c Mon Sep 17 00:00:00 2001 From: stagas Date: Wed, 12 Nov 2014 12:43:35 +0200 Subject: [PATCH] initial --- index.js | 34 ++++++++++++++++++++++++++++++++++ test.js | 11 +++++++++++ 2 files changed, 45 insertions(+) create mode 100644 index.js create mode 100644 test.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..6df4250 --- /dev/null +++ b/index.js @@ -0,0 +1,34 @@ + +/** + * @module osc + * @author stagas + * @org opendsp + * @desc oscillators + * @license mit + */ + +var tau = 2 * Math.PI; + +export function sin(t, f){ + return Math.sin(f * t * tau); +} + +export function saw(t, f){ + return 1 - 2 * (t % (1 / f)) * f; +} + +export function ramp(t, f){ + return 2 * (t % (1 / f)) * f - 1; +} + +export function tri(t, f){ + return Math.abs(1 - (2 * t * f) % 2) * 2 - 1; +} + +export function sqr(t, f){ + return (t*f % 1/f < 1/f/2) * 2 - 1; +} + +export function noise(){ + return Math.random() * 2 - 1; +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..1ae76c1 --- /dev/null +++ b/test.js @@ -0,0 +1,11 @@ + +/** + * test + */ + +import { sin, saw, ramp, tri, sqr, noise } from './index'; + +export function dsp(t){ + //return (sqr(t, .1) + sin(t, .1)) / 3; + return [sin, saw, ramp, tri, sqr, noise][2*t%6|0](t, 300) * 0.4; +}