Skip to main content
May 21, 2009
Question

Converting Sound to information

  • May 21, 2009
  • 1 reply
  • 537 views

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.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 21, 2009

you're doing that now.  what is it that you don't understand?

May 21, 2009

Basically, what would I have to do to extract the raw inforamtion before it's converted into a picture and print on screen in real time.

kglad
Community Expert
Community Expert
May 21, 2009

t is the numeric data.

did you copy that code so you don't understand what it's doing?