Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created November 20, 2023 20:28
Show Gist options
  • Save dontpaniclabsgists/09a39bfd7477e33417434e93e2360f18 to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/09a39bfd7477e33417434e93e2360f18 to your computer and use it in GitHub Desktop.
async function play_notes(notes) {
for (const note of notes) {
await play_note(note);
}
}
function play_note({ note, octave, duration }) {
return new Promise((resolve) => {
// Play the note for the duration
if (note != null && octave != null) {
const freq = noteFreq[octave][note];
// playTone brought to you by Mozilla
const oscillator = playTone(freq);
setTimeout(() => {
oscillator.stop();
resolve();
}, duration);
// Pause for the duration
} else {
setTimeout(() => {
resolve();
}, duration);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment