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 › flashing images to frquencies of music
Page Index Toggle Pages: 1
flashing images to frquencies of music (Read 1655 times)
flashing images to frquencies of music
May 14th, 2007, 7:50am
 
hi all,
just wondering if anyone knows how to get images to flash up on a computer screen in relation to particular sound frequencies.
for instance, if a piece of music ahs a high frequency, a certain image will flash.
we already ahve the sonia code that reads the frequency and shows an equalizer in response to the music frequencies.
dont really know where to go from here to pinpoint certain images to flash up and off when a certain level of frequency is reached.
would really appreciate any help or advice.
Re: flashing images to frquencies of music
Reply #1 - May 14th, 2007, 10:17pm
 
Its pretty easy.
For each frame, check to see which frequency bin has the highest value.  Go through all the spectrum[] values and save the index of the one with the highest value.

So if bin 1 has the highest value of the 256 bins, display image 1, etc.

From that starting point you can do millions of things.
Re: flashing images to frquencies of music
Reply #2 - Jun 22nd, 2007, 2:16am
 


Well, you make it sound quite easy :) how do you ctually "Go through all the spectrum[] values and save the index of the one with the highest value." ? I just want to be able to assign an array of horizontal lines(through the whole height of the screen), each responding to a different frequency bin.

Can someone help?


                 
                                   
Re: flashing images to frquencies of music
Reply #3 - Jun 22nd, 2007, 12:05pm
 
int highVal = 0;


for( int i=0; i<numBins; i++ )
{
 //if current bin's value is higher than the one we have, just overwrite it
 if( spectrum[i] > highVal )
 {
   highVal = spectrum[i];
 }
}

we're keeping the actual value, not the index.. for that just save "i" value.

to draw horizontal lines based on spectrum

for( int j=0; j<height; j++ )
{
 line( 0, 0, spectrum[i], j );
}

draws value of height bins on screen which measure the value in each bin.. to scale them, multiply but some scale_value..

hope it helps
Re: flashing images to frquencies of music
Reply #4 - Jun 22nd, 2007, 10:18pm
 


I can clearly understand how this works (the logic). My problem lies in my inadequacy in the syntax and the language itself. For example, what is the proper calling name for numBins (number of frequency bins)?  And is this code for Sonia or SoniaHelper?

thanks a lot for the help, I really want to learn how all this works..
Re: flashing images to frquencies of music
Reply #5 - Jun 23rd, 2007, 2:09pm
 
Hi,

I was wondering how the frequency bins relate to actual frequencies.

Is frequency bin 1 always the same frequence, not depending on the amount of bins? And, the same question for the last bin?

/BEnm
Re: flashing images to frquencies of music
Reply #6 - Jun 23rd, 2007, 8:06pm
 

hi,

it depends on the number of bins. bins contain a range of frequencies depending on their size. more bins mean smaller bins, thus a smaller range of frequencies in each bin. it should give you more control if you want a specific range of frequencies to do something, like triggering a visual effect or anything.
you just divide the whole spectrum into small sections.

this is true for fft in general, but I don't know if processing is doing something else that I don't know. I'm just learning this! Smiley

error
Page Index Toggle Pages: 1