Today we worked with a library for sound.
Free sounds for downloading
https://orangefreesounds.com/sound-effects/
The functions connected to sound are added into the project with a library. This means that at the top of the html-file we need to add this:
<script src=”path/to/p5.sound.js”></script>
At the time of writing, the latest version of the sound library does some weird clipping. But this one seems to work:
<script src=”https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js”/><script>
We of course also need to upload a soundfile to the project.
Basic sound play
let mySound; //create a variable to
//represent your sound
function preload() //preload in case the file is big
{ //load your sound file
mySound = loadSound("CASH2.mp3");
}
function setup() {
createCanvas(400, 400);
mySound.play(); //command to play the sound
}
function draw() {
background(220);
}
function mouseClicked()
{ //Of course you can trigger it many ways
mySound.play();
}
Concepts we worked with
play();
playMode();
pause();
jump();
stop();
currentTime();
jump();
reverseBuffer();
setVolume();
Homework is to have something triggering sound using keyboard or mouse, and preferably with something nice on the screen.