Created
November 20, 2023 20:28
-
-
Save dontpaniclabsgists/09a39bfd7477e33417434e93e2360f18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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