Pushing the boundaries

…couldn’t be any simpler!

computeSpectrum

Posted by vijayram on January 29, 2007

Greenbars


package {

import flash.display.Sprite;
import flash.media.Sound;
import flash.utils.ByteArray;
import flash.media.SoundMixer;
import flash.events.Event;
import flash.net.URLRequest;

[SWF( backgroundColor=”0x000000″, frameRate=”31″, width=”200″, height=”200″)]
public class wpSpectrum extends Sprite {

private var _bytes:ByteArray;

public function wpSpectrum() {
var s:Sound = new Sound(new URLRequest(“mySong.mp3”));
s.play();
_bytes = new ByteArray();
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}

private function onEnterFrame( event: Event ): void {

SoundMixer.computeSpectrum(_bytes, true, 0);
var value:Number;

graphics.clear();

var spacing:Number = (stage.stageWidth / 256);
var color:Number;

for(var i:int = 0; i < 256; i+=16) {
value = _bytes.readFloat();
value = (value * 256) << 0;
color = 0x00FF00|(value << 16);
graphics.lineStyle(1, color, 1);
graphics.beginFill(color);
graphics.drawRect(i*(spacing/16),100,8,-value/8);

}
}
}
}

Advertisements

One Response to “computeSpectrum”

  1. moos3 said

    how can you implement this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: