Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Sound Response (beginner needing serious help!)

$
0
0
Hello all! I am extremely new to processing and this forum, so your help and patience would be greatly appreciated!

My professor wants us to create a sound responsive work - in a zip folder, he included 

1.) SoundRespond.pde :
  1. class SoundRespond { // Define a class with custom name

  2.   import ddf.minim.*; // Variables and library imports
  3.   private Minim minim;
  4.   private AudioInput input;

  5.   SoundRespond(PApplet myApplet) { //A constructor, necessary part of a class

  6.     minim = new Minim (myApplet);
  7.     input = minim.getLineIn (Minim.STEREO, 512);
  8.   }

  9.   float adding( float _upperRange) { // Function for sound response
  10.     ////////////sound stuff///////
  11.     float volumeValue = input.mix.level () * 250;
  12.     volumeValue = constrain(volumeValue, 0, 100);

  13.     volumeValue = map(volumeValue, 0, 100, 0, _upperRange);
  14.     //println(volumeValue);// uncomment to debug only, else leave comment
  15.     ////////sound stuff end////////
  16.     return volumeValue;
  17.   }


  18. }
2.) His example sketch:
  1. //  1) +++++ To make a sketch sound responsive the first step is to put the SoundRespond.pde file in the same folder
  2. //with the sketch you are working on.
  3. //++++++++++++++++++++++++++++++++

  4. //  2) +++++ The second step is to copy the line below into your sketch above void setup() +++++
  5. SoundRespond mySoundRespond;
  6. //+++++++++++++++++++++++++++++++

  7. float diam =60;   //diameter of the circle
  8. float xPos = 0;   //the position of the circle left to right on x axis
  9. float yPos = 200; //the position of the circle to to bottom on y axis
  10. float speed = 3;  // how many pixels the circle will move with each frame
  11. float sndChng;

  12. void setup() {
  13.   size(500,500);
  14.   //  3) +++++ The third step is to copy the line below into your sketch below size(width,height);  +++++
  15.   // between the curly brackets of of setup()
  16.   mySoundRespond = new SoundRespond(this);
  17.   //++++++++++++++++++++++++++++++++++
  18.   smooth();
  19. }

  20. void draw() {
  21.   background(255);  // redraw the background each frame to erase the previous circle

  22.   // Use values to draw an ellipse
  23.   noStroke();
  24.   fill(#831919);
  25.   ellipse(xPos,yPos,diam,diam);
  26.   
  27.     //  4) +++++ The forth step is to choose a variable of something you want to change with sound  +++++
  28.   // this has to be between the curly brackets of of draw().
  29.   // Copy and paste "mySoundRespond.adding(value);" and put a number in the place of the word ""value".

  30.   sndChng = mySoundRespond.adding(5);

  31.   //The number determines the amount of the sound response effect. 
  32.   //For speed changes try 2.0-5.0 to start, size changes can be much larger numbers.
  33.   //++++++++++++++++++++++++++++++++++

  34. //must multiply speed by sndChng! adding does not work!!
  35. //uncomment constrain() below to keep circle moving
  36. //sndChng = constrain(sndChng,1,10);
  37.   xPos = xPos + (speed*sndChng);


  38.   println("xPos " + xPos);
  39.    println("speed " + speed);
  40.   if ((xPos > width) || (xPos < 0)) {
  41.    speed = speed * -1;
  42.   }
  43.  
  44.  
  45. }
I followed his first few instructions, copying the folder into my new sketch folder. In creating my own sketch, as well as trying to run this example, I received a "Found one too many { characters without a } to match it." message with the 
  1.   import ddf.minim.*; // Variables and library imports
line highlighted in the SoundRespond file. I've been scanning this over and over - I cannot find a source for this error! Any suggestions on what I might be reading wrong?

Viewing all articles
Browse latest Browse all 1768

Trending Articles