Alright, I am trying to build a FFT audio visualizer and have two questions to make it better. Right now I have a bit of working code that does the basics of what I want, but as always, I want more.
Here is the code that I currently have:
var s:Sound = new Sound(new URLRequest("mix 3 v1.mp3"));
s.play(0, 1);
var ba:ByteArray = new ByteArray();
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void {
graphics.clear();
//Create ByteArray of song
SoundMixer.computeSpectrum(ba, true);
//For every 8 bytes to a max of 256
for (var i:uint=0; i<256; i+=32) {
var index = (i / 4);//or bitshift using i >> 3
var num:Number = -ba.readFloat()*250;
//Generate Bars
graphics.beginFill(0xFFFF00);
graphics.drawRect(191 + (index * 14), 500, 12, num-2);
}
}
What I want now, is to be able to change the colour after a certain amount of time. How would I go about doing that? Would I just go to that frame in the timeline and do a different set of AS3 code? Or is it better practice to leave everything on frame one?
Also how would I ease the updating of the bars? Right now I believe it clears all of the graphics, and redraws everything, leaving for a very jumpy/flickering visualizer. Should I just draw the rectangles and then scale the height? Or is there a way to make a buffer of the frequency values to transition between the current and next value? (Which now that I think about it isn't really possible cause if it is updating every frame, you can't transition between frames...)
Thanks in advance.