-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
|
||
/** | ||
* @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; | ||
} | ||
|
||
/** | ||
* @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 pulse(t, f, w){ | ||
return (t*f % 1/f < 1/f/2*w) * 2 - 1; | ||
} | ||
|
||
export function noise(){ | ||
return Math.random() * 2 - 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
/** | ||
* test | ||
*/ | ||
|
||
import { sin, saw, ramp, tri, sqr, pulse, noise } from './index'; | ||
|
||
export function dsp(t){ | ||
//return pulse(t, 70, sin(t, .1)+1); | ||
//return (sqr(t, .1) + sin(t, .1)) / 3; | ||
return [sin, saw, ramp, tri, sqr, pulse, noise][2*t%6|0](t, 300, 0.5) * 0.4; | ||
} |