Skip to content

Instantly share code, notes, and snippets.

@cheery
Last active August 29, 2015 14:03
Show Gist options
  • Save cheery/d8778894e3716b30b721 to your computer and use it in GitHub Desktop.
Save cheery/d8778894e3716b30b721 to your computer and use it in GitHub Desktop.
Feed into wavepot.com
var tau = Math.PI * 2;
var dot = 2.0;
var a = [
[69-4, 69-2, 69, 69, 69-4],
[ 8, 8, 4, 4, 4]
];
var b = [
[69-4, 69-2, 69, 69, 69, 69, 69+1, 69, 69-2],
[ 8, 8, 8, 8, 8, 8, 4, 4, 4]
];
var seq = sequencer([
a, a, b, [[0], [1/5.0]]
]);
function dsp(t) {
var afp = seq(t);
return afp[0] * 0.03 * Math.sin(tau * t * afp[1]);
}
function hz(pitch) {
return Math.pow(2.0, (pitch - 69)/12) * 440.0;
}
function sequencer(verses) {
var verse = 0;
var current = 0;
var struck = 0;
var n = verses.length;
return function(t) {
var duration = verses[verse][1][current % n];
var pitch = verses[verse][0][current % n];
var j = Math.max(0.0, (t - struck) / (dot/duration));
if (1.0 <= j) {
struck += dot/duration;
current += 1;
}
if (current >= verses[verse][0].length)
{
current = 0;
verse = (verse + 1) % verses.length;
}
if (pitch === 0) j = 0;
return [Math.min(1.0, j), hz(pitch), pitch];
};
}
@khoin
Copy link

khoin commented Jul 9, 2014

doesn't work for me?

@cheery
Copy link
Author

cheery commented Aug 20, 2014

Sorry. Something I did seems to have broken it. Added a fix so it runs now, but something's still wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment