User Tools

Site Tools


courses:intro.prototyping.fall.2015.oct5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:intro.prototyping.fall.2015.oct5 [2015/10/05 07:06]
rickard
courses:intro.prototyping.fall.2015.oct5 [2015/10/07 01:04] (current)
rickard
Line 1: Line 1:
 +===Sound in Processing ===
 +
 +Today we worked with a library for sound called Minim.
 +The homework for next time (not next week) is to make something using sound. Preferably using some of the graphic and interactive elements we've gone through before.
 +[[http://​code.compartmental.net/​minim/​javadoc/​|Minim documentation]]
 +
 +== Sound ==
 +
 +http://​www.mediacollege.com/​downloads/​sound-effects/​
 +
 +http://​www.freesoundeffects.com/​
 +
 +We moved on to a brief look into object oriented programming and on to play with sound using the Minim [[http://​code.compartmental.net/​minim/​|library]]. The full documentation is [[http://​code.compartmental.net/​minim/​javadoc/​|here]].
 +
 +
 +Two of the classes we played around with was audioSample and audioPlayer.
 +
 +== Audiosample - short samples ==
 +<code java>
 +import ddf.minim.*;​
 + 
 +Minim minim;
 +AudioSample money, gun;
 + 
 +void setup()
 +{
 +  size(640, 480);
 +  // always start Minim before you do anything with it
 +  minim = new Minim(this);​
 +  // load soundfile from the data folder
 +  money = minim.loadSample("​CASH2.WAV"​);​
 +  gun = minim.loadSample("​SHOTGUN-X3.WAV"​);​
 +  ​
 +}
 + 
 +void draw()
 +{
 +  //nothing to actually draw
 +}
 + 
 +void keyPressed()
 +{  ​
 +  if ( key == '​y'​ ) 
 +  {
 +    money.trigger();​
 +  }
 +  ​
 +  if ( key == '​p'​ ) 
 +  {
 +    gun.trigger();​
 +  }
 +}
 +  ​
 +void stop()
 +{
 +  // always close Minim audio classes when you are done with them
 +  money.close();​
 +  gun.close();​
 +  minim.stop();​
 +}
 +</​code>​
 +
 +
 +
 +== AudioPlayer - longer audio files ==
 +
 +<code java>
 +import ddf.minim.*;​
 +
 +Minim minim;
 +AudioPlayer soundtrack;
 +
 +void setup()
 +{
 +  size(640, 480);
 +  // always start Minim before you do anything with it
 +  minim = new Minim(this);​
 +  //load a file, 
 +  soundtrack = minim.loadFile("​song2.mp3"​);​
 +}
 +
 +void draw()
 +{
 +  //nothing to actually draw
 +}
 +
 +void keyPressed()
 +{
 +  if ( key == '​q'​ ) 
 +  {
 +    if(soundtrack.isPlaying()) //checking if the song is playing to choose play/pause
 +     ​soundtrack.pause();​
 +    else
 +     ​soundtrack.play();​
 +  }
 +  ​
 +  if ( key == '​w'​)
 +  {
 +    soundtrack.skip(3000);​ //skipping three seconds
 +  }
 +  ​
 +  if( key == '​e'​)
 +  {
 +    soundtrack.rewind();​ //​well...yeah,​ guess. :-)
 +  }
 +}
 +
 +void stop()
 +{
 +  // always close Minim audio classes when you are done with them
 +  soundtrack.close();​
 +  minim.stop(); ​
 +}
 +  ​
 +</​code>​
 +
 +== Concepts we worked with ==
 +<code java>
 +
 +audioPlayer
 +play()
 +pause()
 +rewind()
 +isPlaying()
 +position()
 +skip()
 +cue()
 +
 +
 +audioSample
 +trigger()
 +length()
 +stop()
 +</​code>​
  
courses/intro.prototyping.fall.2015.oct5.txt · Last modified: 2015/10/07 01:04 by rickard