about meWedia Ajax
SoundSpectrum ... Bing ... Flash ... 0 /1476 ... 2 years 3 months ago
Today,after the Factory Practice.I was happy to have some time on studying ActionScript3.0.Believe it or not,AS3.0 has grown up to be some powerful script language.I felt so exciting to find it's so easy now to manipulate the sound objecy with binary data.The new SoundMixer.computeSpectrum() method reads audio data at runtime allowing you to creat audio-driven animations.It's so cool.

The following demo shows you how to extract data from sound object and then translat it to the visiual object.Hope you will enjoy it!
Note:This needs FlashPlayer9.0 Click here to get it http://labs.adobe.com/technologies/flashplayer9/
Nearly forget:This demo referes to the lee's Flash Blog.Click here to view it in lee's blog: http://theflashblog.com/?p=181

That's the code,it's really easy ,so I didn't give the notation!If you have any questions about this code,give your replay bellow!

Security.allowDomain("*.wubingStudy.com");
var sound:Sound = new Sound(new URLRequest("http://www.wubingStudy.com/flash/magic.mp3"),null);
var sc:SoundChannel = new SoundChannel();
var sb:ByteArray = new ByteArray();
var timer:Timer = new Timer(100,0);
var shape:Shape = new Shape();
var speedText:TextField = new TextField();
speedText.x = stage.stageWidth/2;
speedText.y = stage.stageHeight/2;
speedText.textColor = 0xffffff;
this.addChild(shape);
this.addChild(speedText);

var blurFilter:BlurFilter = new BlurFilter(4,4,1);

function SoundProgressHandler(e:ProgressEvent):void
{
speedText.text = String(Math.round((e.bytesLoaded/e.bytesTotal)*100))+"%";
}
function SoundCompeleteHandler(e:Event):void
{
sc = sound.play(0,10,null);
this.removeChild(speedText);
timer.start();
}

function TimerEventHandler(e:TimerEvent):void
{
SoundMixer.computeSpectrum(sb,true,0);
shape.graphics.clear();
for(var i:uint=0;i<256;i+=8)
{
var num:Number = sb.readFloat()*512;
if(num>1)
{
shape.graphics.lineStyle(num/32,0x55ff00|(num<<16));
shape.graphics.drawCircle(stage.stageWidth/2,stage.stageHeight/2,i);
}
}
}

sound.addEventlistener(ProgressEvent.PROGRESS,SoundProgressHandler);
sound.addEventlistener(Event.COMPLETE,SoundCompeleteHandler);
timer.addEventlistener(TimerEvent.TIMER,TimerEventHandler);
Name*
Email
Website
BoldItalicUnderlineJustify LeftJustify CenterJustify RightIndentOutdentBulled ListNumbered ListInsert LineCreate LinkUnlinkInsert Face
Submit