Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
p5js-sound1 [2024/03/19 23:23] – renick | p5js-sound1 [2024/03/19 23:27] (current) – renick | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== the basics of sound in p5js ====== | ====== the basics of sound in p5js ====== | ||
+ | |||
+ | All of the documentation for sound-related functions in p5js is here: https:// | ||
===== making a sound play and loop ===== | ===== making a sound play and loop ===== | ||
- | https:// | + | Let's get a sound playing in p5js. |
+ | |||
+ | This works, but notice the problem when you click the square more than once! | ||
+ | |||
+ | < | ||
+ | <iframe src="https:// | ||
+ | </ | ||
===== making a sound play only when the mouse is clicked ===== | ===== making a sound play only when the mouse is clicked ===== | ||
Line 10: | Line 18: | ||
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? | 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? | ||
+ | < | ||
+ | <iframe src=" | ||
+ | </ | ||
- | https:// | + | ===== the problem: clicking |
- | + | ||
- | ==== the problem: clicking ==== | + | |
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. | In this version, we use setVolume and give pause an argument to tell it to pause AFTER the fade-out. | ||
+ | < | ||
+ | <iframe src=" | ||
+ | </ | ||
- | https:// | + | ===== stopping a loop ===== |
- | + | ||
- | ==== 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. | 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:// | + | <iframe src="https:// |
+ | </ | ||
===== notes ===== | ===== notes ===== |