Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Nov 12, 2014
0 parents commit 2b1ce3c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 2b1ce3c

Please sign in to comment.