This is an old revision of the document!
the basics of sound in p5js
making a sound play and loop
making a sound play only when the mouse is clicked
This one plays two sound files simultaneously. There are a few other things it does, which you should try to disable so that you can understand how it works. Try disabling one of the sounds. It also uses a randomized start time for the second of the sound files. Also notice that it pauses the loop when the mouse is released; that means that the loop starts from where it left off when the button is re-pressed. A different possible behaviour is for the loop to restart. Can you look at the documentation and figure out how to do that?
the problem: clicking
Notice the terrible clicking that happens when you stop pressing the mouse button. There's not proper envelope for the sound. That sudden drop from some amplitude to 0 makes the click. One way to fix that might be this:
notes
After your add your sound in the editor, be sure to save the drawing. My sound didn't load until I did so.
Be sure to add the file extension in the file name. I didn't and got a difficult-to-interpret error.