Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
p5js-sound1 [2024/03/19 22:52] – renick | p5js-sound1 [2024/03/19 23:23] – renick | ||
---|---|---|---|
Line 8: | Line 8: | ||
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? | 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? | ||
+ | |||
+ | Also, can you figure out why it sounds like two different sound files even though it only uses one? What's been done in the second call to loop that makes it different? | ||
https:// | https:// | ||
Line 15: | Line 17: | ||
Notice the terrible clicking that happens when you stop pressing the mouse button. There' | Notice the terrible clicking that happens when you stop pressing the mouse button. There' | ||
+ | In this version, we use setVolume and give pause an argument to tell it to pause AFTER the fade-out. | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ==== stopping a loop ==== | ||
+ | |||
+ | This version is a little nicer in some ways; it loops while you press the box, but the looping stops once you stop pressing the mouse. We accomplish that by passing false to setLoop. | ||
+ | |||
+ | https:// | ||
===== notes ===== | ===== notes ===== | ||
Line 21: | Line 32: | ||
Be sure to add the file extension in the file name. I didn't and got a difficult-to-interpret error. | Be sure to add the file extension in the file name. I didn't and got a difficult-to-interpret error. | ||
+ | |||
+ | Use mp3s or ogg so that they load more quickly. For more on file formats, see this expanding page: https:// | ||