Skip to content

Instantly share code, notes, and snippets.

@eric-wood
Created July 27, 2017 13:10
Show Gist options
  • Save eric-wood/8bb864e4f74e214ef9b323296b6c6f8d to your computer and use it in GitHub Desktop.
Save eric-wood/8bb864e4f74e214ef9b323296b6c6f8d to your computer and use it in GitHub Desktop.
// here's the MIDI notes for the sequence
// const NOTES = [36, 40, 43, 47, 48, 47, 43, 40];
// web audio oscillators want frequency values, tho, so here's the frequencies:
const NOTES = [65.4063913251, 82.4068892282, 97.9988589954, 123.4708253140, 130.8127826503, 123.4708253140, 97.9988589954, 82.4068892282];
let current = 0;
setInterval(() => {
postMessage(NOTES[current]);
current = current < NOTES.length - 1 ? current + 1 : 0;
}, 200);
// set up a bunch of stuff, pretend oscillator is already defined
const arpeggiator = new Worker('arpeggiator.js');
arpeggiator.onmessage = (event) => {
oscillator.frequency.value = event.data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment