Today we worked with a library for sound.
Free sound for downloading
http://www.mediacollege.com/downloads/sound-effects/
http://www.freesoundeffects.com/
There are also a whole heap of sounds on the server under the “public” folder.
For this we have a brief look into object oriented programming and on to play with sound using the library.
To play a soundfile we use the class soundFile.
soundFile
import processing.sound.*; SoundFile soundtrack; float volume, pan; void setup() { size(640, 480); //load a file soundtrack = new SoundFile(this, "song.mp3"); //soundtrack.play(); background(255); } void draw() { //nothing to actually draw volume = map(mouseY,0,height,0,1); } void keyPressed() { if ( key == 'q' ) { soundtrack.play(); } if ( key == 'w') { soundtrack.pause(); } if( key == 'e') { soundtrack.stop(); } }
Concepts we worked with
play();
isPlaying();
loop();
cue();
pause();
jump();
stop();
amp();
position();
pan(); <-(mono only)
Homework is to have something triggering sound using keyboard or mouse, and preferably with something nice on the screen.