We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Bouncing balls with sound
Page Index Toggle Pages: 1
Bouncing balls with sound (Read 2825 times)
Bouncing balls with sound
May 2nd, 2010, 7:13pm
 
I'm working on a sketch that draws balls that bounce. The size is chosen according to the volume of sound input, and I would like the bounciness of the balls to be determined by the pitch of the sound input.

This is what my draw function looks like right now:

Code:
void draw() {
 background(190,50,360);

 //iterate through buffer, draw a ball for each with random X position and size dictated by volume
 for(int i = 0; i < in.bufferSize() - 1; i+=8){ //to create fewer balls, only check every eighth one
   Ball newBall = new Ball(int(random(width)), abs(int(in.left.get(i)*100)), 4);
   balls.add(newBall); //adds the ball to a vector
 }
}


The 4 represents the bounciness of the ball. The bounciness should stay between 2 and 10. How would I go about using the pitch to determine the pitch? I was told to use ForwardFFT, but I've been staring at the example forever and I don't understand how to incorporate it into my program.
Re: Bouncing balls with sound
Reply #1 - May 3rd, 2010, 5:33am
 
When you proceed a FFT analysis, you get a spectrum. Like column charts in a spreasheet.

You can get the spectrum result in fft.getBand(). You know how much bands there are thanks to fft.specSize().

You want to find the higher level band? Just iterate and compare the values.

Quote:
int higher_band = -1;
float higher_value = -1.0;
for (int i = 0; i < fft.specSize(); i++) {
  float current_value = fft.getBand(i);
  if (current_value > higher_value) {
    higher_value = current_value;
    higher_band = i;
  }
}


Then you can use higher_band which should be a value between 0 and fft.specSize().
Re: Bouncing balls with sound
Reply #2 - May 3rd, 2010, 7:59am
 
I'm sorry, I'm afraid I still don't understand. If I'm iterating through a buffer and using the volume of the sound input to create the balls, is there a way to simultaneously isolate the pitch of the sound? I apologize if I'm being dense -- I'm very new to Processing.
Re: Bouncing balls with sound
Reply #3 - May 15th, 2010, 8:49pm
 
There's a way but it ain't easy...

lessee...   I may have something for you later, I made a ptich follower in supercollider once, maybe I can dust it off and port it.

It basically counted the samples between zero crossings... that is, when the waveform crosses the zero line... uh... but it can get confused and produce weird results when the input contains more than one tone.  Like a guitar octaver pedal does. Undecided
Re: Bouncing balls with sound
Reply #4 - May 16th, 2010, 2:52am
 
Err...   this thing works pretty badly lol

http://openprocessing.org/visuals/?visualID=9739
Re: Bouncing balls with sound
Reply #5 - May 16th, 2010, 2:55am
 
I guess I should learn more than I ever wanted to know about
Fast Fourier Transforms, too
Page Index Toggle Pages: 1