Converting Sound to information
Hi,
I'm working a project for school in which I'm using the sound spectrum. Only problem is, I only knw Action Script 2, which does not use it. I'm currently using this code to create sound waves and it works fine.
var url:String = "http://www.helpexamples.com/flash/sound/song3.mp3";
var request:URLRequest = new URLRequest(url);
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request); var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var ba:ByteArray = new ByteArray();
var gr:Sprite = new Sprite();
gr.x = 20;
gr.y = 200;
addChild(gr);
var time:Timer = new Timer(50);
time.addEventListener(TimerEvent.TIMER, timerHandler);
time.start();
function completeHandler(event:Event):void {
event.target.play();
}
function soundCompleteHandler(event:Event):void {
time.stop();
}
function timerHandler(event:TimerEvent):void {
SoundMixer.computeSpectrum(ba, false);
var i:int;
gr.graphics.clear();
gr.graphics.lineStyle(0, 0xFFEA00);
gr.graphics.beginFill(0xFF0000);
gr.graphics.moveTo(0, 0);
var w:int = 2;
for (i=0; i<512; i+=w) {
var t:Number = ba.readFloat();
var n:Number = (t * 100);
gr.graphics.drawRect(i, 0, w, -n);
}
}
Can someone help me just turn the sound into numbers(which are then usually used to draw waves). I know a little about graphics from java, and I feel like it will help lean better heow it works.