The goal of this lab is to create sounds that are driven by events in your animation.
You can have continuous sounds, e.g. use a particle’s height or velocity to control the pitch or amplitude of a continuous tone. If you have swarms of particles, you can have swarms of tones.
You can “trigger” individual sounds. You must put sound files containing the sounds in your project directory and use a local server as with images. You can start playing a sound when some event happens, e.g. a particle bounces off the wall or collides with an object.
Sound Controlled by Animation
- Start with any animation.
- Use your own sketch, or
- Use a class example from Notes pages, or
- Modify a sketch or class example.
- Add sounds to the animation. Here are some techniques:
- Continuous tones:
123456789101112131415161718// in setup, you can start one or more tones (oscillators):myOsc = new p5.Oscillator();myOsc.setType('sine');// frequency should be (roughly) between 200 and 2000. You can hear// down to 20, but your laptop speakers will not put out much sound below// 200. You can hear up to 20,000 but 2000 is already very high in terms of// musical pitch.myOsc.freq(800);myOsc.start();// to change the amplitude (how load) or frequency (pitch), you can update// the oscillator from within draw() or anywhere:myOsc.amp(x); // where 0 <= x <= 1myOsc.freq(f); // where 200 <= f <= 2000 (recommended)// A simple way to make “pings” that die away is set the variable amp to 1 to start// the “ping.” Each draw, do amp *= 0.95; myOsc.amp(amp); This will// cause the “ping” to die away. Use smaller factors to fade away faster, etc. - Sound file playback (e.g. play a “boing” when something bounces).
12345678// each sound should be preloaded into a variable from a file. You will need// a local server to load files (just like images):function preload() {mySnd = loadSound("samplefile.wav");mySnd.setVolume(0.5);}// to play the sound from within draw() or anywhere:mySnd.play()</li>
- Continuous tones:
Have fun!