Sound Response (beginner needing serious help!)
in
Core Library Questions
•
8 months ago
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 :
- class SoundRespond { // Define a class with custom name
- import ddf.minim.*; // Variables and library imports
- private Minim minim;
- private AudioInput input;
- SoundRespond(PApplet myApplet) { //A constructor, necessary part of a class
- minim = new Minim (myApplet);
- input = minim.getLineIn (Minim.STEREO, 512);
- }
- float adding( float _upperRange) { // Function for sound response
- ////////////sound stuff///////
- float volumeValue = input.mix.level () * 250;
- volumeValue = constrain(volumeValue, 0, 100);
- volumeValue = map(volumeValue, 0, 100, 0, _upperRange);
- //println(volumeValue);// uncomment to debug only, else leave comment
- ////////sound stuff end////////
- return volumeValue;
- }
- }
- // 1) +++++ To make a sketch sound responsive the first step is to put the SoundRespond.pde file in the same folder
- //with the sketch you are working on.
- //++++++++++++++++++++++++++++++++
- // 2) +++++ The second step is to copy the line below into your sketch above void setup() +++++
- SoundRespond mySoundRespond;
- //+++++++++++++++++++++++++++++++
- float diam =60; //diameter of the circle
- float xPos = 0; //the position of the circle left to right on x axis
- float yPos = 200; //the position of the circle to to bottom on y axis
- float speed = 3; // how many pixels the circle will move with each frame
- float sndChng;
- void setup() {
- size(500,500);
- // 3) +++++ The third step is to copy the line below into your sketch below size(width,height); +++++
- // between the curly brackets of of setup()
- mySoundRespond = new SoundRespond(this);
- //++++++++++++++++++++++++++++++++++
- smooth();
- }
- void draw() {
- background(255); // redraw the background each frame to erase the previous circle
- // Use values to draw an ellipse
- noStroke();
- fill(#831919);
- ellipse(xPos,yPos,diam,diam);
- // 4) +++++ The forth step is to choose a variable of something you want to change with sound +++++
- // this has to be between the curly brackets of of draw().
- // Copy and paste "mySoundRespond.adding(value);" and put a number in the place of the word ""value".
- sndChng = mySoundRespond.adding(5);
- //The number determines the amount of the sound response effect.
- //For speed changes try 2.0-5.0 to start, size changes can be much larger numbers.
- //++++++++++++++++++++++++++++++++++
- //must multiply speed by sndChng! adding does not work!!
- //uncomment constrain() below to keep circle moving
- //sndChng = constrain(sndChng,1,10);
- xPos = xPos + (speed*sndChng);
- println("xPos " + xPos);
- println("speed " + speed);
- if ((xPos > width) || (xPos < 0)) {
- speed = speed * -1;
- }
- }
- import ddf.minim.*; // Variables and library imports
1