User Tools

Site Tools


courses:intro.prototyping.fall.2013.oct1

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.2013.oct1 [2013/10/03 00:37]
rickard
courses:intro.prototyping.fall.2013.oct1 [2013/10/03 01:54] (current)
rickard
Line 1: Line 1:
 +=== Audio and wrap up ===
  
 +The homework is to make something new with sound, and I'd love it if you could combine it with images or 2D-shapes. I'll give you until the next time we meet as entire class. So NOT next time, when we do the lecture to get access to the workshop.
 +
 +I started this weeks class with some boring but valuable tips about planning any larger programming ideas in english before starting to put it into code. While exploring ideas of course is a whole other matter. Expanding on ideas step by step is also fun. 
 +
 +Which brings me to the other valuable tip. Saving versions. If you have something working that you like, save it, and continue on a copy in case you slip up. 
 +
 +Which brings me to println(). A valuable function to track how your program is working. It puts text in the black window at the bottom of the processing programming window, and you can use it either to see what value a variable has, or check is you're reaching that part of an if-statement that you just put in the code. All depending on where you place it, or have it print.
 +
 +== Webcam ==
 +
 +Last time was all about loading images and manipulating them. I wanted to finish that subject by showing how easy it is to connect to a webcam in Processing, and once you have that going, each frame can be handled as a picture. Which means that you can do filters and graphics with the video feed.
 +
 +<code java>
 +import processing.video.*;​
 +
 +Capture cam;
 +
 +void setup() {
 +  size(640, 480);
 +
 +  String[] cameras = Capture.list();​
 +  ​
 +  if (cameras.length == 0) {
 +    println("​There are no cameras available for capture."​);​
 +    exit();
 +  } else {
 +    println("​Available cameras:"​);​
 +    for (int i = 0; i < cameras.length;​ i++) {
 +      println(cameras[i]);​
 +    }
 +    ​
 +    // The camera can be initialized directly using an 
 +    // element from the array returned by list():
 +    cam = new Capture(this,​ cameras[1]);​
 +    cam.start(); ​    
 +  }      ​
 +  ​
 +}
 +
 +void draw() {
 +  if (cam.available() == true) {
 +    cam.read();
 +  }
 +  image(cam, 0, 0);
 +}
 +
 +</​code>​
 +
 +== 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/​tools/​minim/​manual-minim/​|library]]. As Madya pointed out, there is more information on the same website under "​tools",​ and the full documentation is [[http://​code.compartmental.net/​minim/​javadoc/​|here]].
 +
 +
 +Two of the classes we played around with was audioSample and audioPlayer.
 +
 +== Audiosample ==
 +<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 ==
 +
 +<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, give the AudioPlayer buffers that are 2048 samples long
 +  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>
 +println()
 +audioPlayer
 +play()
 +pause()
 +rewind()
 +isPlaying()
 +position()
 +skip()
 +audioSample
 +trigger()
 +
 +</​code>​
courses/intro.prototyping.fall.2013.oct1.txt · Last modified: 2013/10/03 01:54 by rickard