Using sound files: play, loop, spectrum analysis

Keyboard example, with different ways to play sound samples: download

Real time spectrum analysis via Fast Fourier transform download

Adding cues to the sound that trigger a function at a certain points in the reproduction download

Sounds work almost like images. To make this example work download an mp3 file and put it in an assets folder inside your project. You can go to freesound or download mp3 from youtube.

var mySound;

function preload() {
  mySound = loadSound('assets/mySound.mp3');
}

function setup() {
  mySound.setVolume(0.1);
  mySound.play();
//also try looping
//mySound.loop();
}

function draw() {
if(mySound.isPlaying())
println("PLAYING");
}

//sound mode
function mouseClicked() {
  mySound.playMode('sustain');
  mySound.play();
}

function keyPressed() {
  mySound.playMode('restart');
  mySound.play();
}

Posted in