Skip to content

Instantly share code, notes, and snippets.

@ahmattox
Created June 22, 2014 18:58
Show Gist options
  • Save ahmattox/12fced48b940199f3031 to your computer and use it in GitHub Desktop.
Save ahmattox/12fced48b940199f3031 to your computer and use it in GitHub Desktop.
Wavepot
function dsp(t) {
// return sinOsc(t, 220, .5);
return .3 * saw(t, 220, 4, .5) + saw(t, 221, 4, .5);
// return 0.1 * Math.sin(2 * Math.PI * t * 440);
}
function saw(time, frequency, octaves, falloff) {
value = 0;
for (var i = 0; i < octaves; i++) {
f = frequency * (i + 1);
a = .5 / (Math.pow(2, i))
value += osc(time, f, a);
}
return value;
}
function osc(time, frequency, amplitude) {
return amplitude * Math.sin(2 * Math.PI * time * frequency);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment