Hello, I got this script from this thread I started. How can I use it to detect a sudden increase in volume, (like a drum beat) and then tie it to another function (like increasing the velocity of a particle emitter or spawning an enemy)?
asked Dec 18 '10 at 01:04 AM
I havent tried it, but perhaps you could sum all the samples within a RMS and check if it makes an abnormally large jump in the sum?
The RMS function seems to be summing your samples already? so the "vol" variable, isnt that the thing you should be watching?
perhaps if you store the value from each update in a "previousVol" somewhere globally and then compare the previous to the new vol. If the difference is... lets say 30 then you have a spike. Then you call your "volumeter trigger"?
Wouldnt that do the trick?
answered Dec 18 '10 at 01:14 AM
If you want to detect a sudden peak just check the absolute value of the samples:
This is simplified, better analysis would require more complex code. You would probably have to develop some heuristics to distinguish beats from other sounds in the music.