Skip to content

Instantly share code, notes, and snippets.

@cheery
Created July 25, 2014 00:11
Show Gist options
  • Save cheery/2afcc0925e8aa8cabd77 to your computer and use it in GitHub Desktop.
Save cheery/2afcc0925e8aa8cabd77 to your computer and use it in GitHub Desktop.
Oscillators that blend without phase shifting. Not huge difference but noticeable.
var mi = Math.PI/2;
var pi = Math.PI;
var tau = Math.PI*2;
function arp(ts, x, y, z) {
return Math.sin(x * Math.exp(-ts * y)) * Math.exp(-ts * z);
}
var sin = Math.sin;
function tri(x) {
return Math.abs(1 - ((x-mi) % tau) / pi) * 2.0 - 1.0;
}
function saw(x) {
return 1 - ((x-mi) % tau) / pi;
}
function sqr(x) {
return sin(x) > 0 ? 1 : -1;
}
function dsp(t) {
var ts = t % 0.5;
var a = 301.467 * t * tau;
var b = sin(t*tau/2)*0.5 + 0.5;
return 0.1 * (sin(a)*b + saw(a)*(1-b));
return 0.5 * arp(ts, saw(a) + sqr(a), tau, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment