Review: Loading And Playing Sounds - The Coding Train - p5.js Sound Tutorail - Part 1 (17min)
TODO
There's a few vidoes covered here. split them out to individual posts
clean up the examples
Notes
-
Use
preload()
for things like file loads that need to happen before the rest of the processes run. - This will load and play a sound
var song;
-
set the volume with
.setVolume(0.5)
- the volume number is between 0 and 1
- this creates a volume slider
var song;
var slider;
- Instead of preload() you can also use a callback. (see the video for the sample at ~11min)
-
Can also do
.rate()
and.pan()
for changing the speed and the panning
Part 2 video
https://www.youtube.com/watch?v=YcezEwOXun4&list=PLRqwX-V7Uu6aFcVjlDAkkGIixw70s7jpW&index=2
This is how to do play/pause with a button:
var song;
var button;
</script>
I'm skipping part 3 on timing, jumps, and cues right now
part 4 - amplitutude analysis
This is what I'm after for the stream
This is a parsed down example
var amp;
var button;
var song;
I skipped over videos 5, 6, and 7 to get to 8 which has mic input which is what I'm after for the stream.
Part 8
This is how to get the mic input and graph the audio
var mic;
Part 9
Graphing amplititude
This was the sample. Should be able to use the mic instead
var song;
var amp;
var button;
var vol_history = [];
function toggle() {
if (song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound("example.mp3");
}
function setup() {
createCanvas(200, 200);
button = createButton('toggle');
button.mousePressed(toggle);
// song.play();
amp = new p5.Amplitude();
// mic = new p5.AudioIn();
// mic.start();
}
function draw() {
background(0);
// var vol = mic.getLevel();
var vol = amp.getLevel();
vol_history.push(vol);
stroke(255);
noFill();
beginShape();
for (var i = 0; i < vol_history.length; i++) {
var y = map(vol_history[i], 0, 1, height / 2, 0);
vertex(i, y);
}
endShape();
if (vol_history.length > width) {
vol_history.splice(0, 1);
}
}
part 10
making a radial graph of amplitutde
Not pulling the code, but it's kinda fun
part 11
frequency analysis.
still need to watch this one