Sample Synth [Source Code]

How does this work?

According to music theory, musical notes have frequencies that are a 12th root of 2 apart. This website has some formulas for doing this math. If we know the pitch of any one sound, and the difference in pitches between any two notes, we can apply that difference to the original note to get the desired sound.

When the preservesPitch property of an Audio element is set to false, modifying the playbackRate to the difference in note frequencies will play the intended note.