Chapter 31 Example 5 actionscript.. forked:2favorite:0lines:40license : MIT License modified : 2010-02-05 06:18:37 Embed Tweet package { import flash.display.Sprite; import flash.events.Event; import flash.media.*; import flash.net.URLRequest; import flash.utils.ByteArray; [SWF(frameRate="60",backgroundColor="#808080")] public class ch31ex5 extends Sprite { protected var sound:Sound; protected var waveform:ByteArray; public function ch31ex5() { var songurl:String = "http://actionscriptbible.com/files/winter.mp3"; sound = new Sound(new URLRequest(songurl), new SoundLoaderContext(1000, true)); sound.play(); waveform = new ByteArray(); this.addEventListener(Event.ENTER_FRAME, onEnterFrame); } protected function onEnterFrame(event:Event):void { graphics.clear(); SoundMixer.computeSpectrum(waveform, false, 2); //draw the left channel in blue graphics.lineStyle(0, 0x0000ff); drawChannel(); //and the right in red graphics.lineStyle(0, 0xff0000); drawChannel(); } protected function drawChannel():void { var W:Number = stage.stageWidth; var H:Number = stage.stageHeight; var SAMPLES:Number = 256; var xstep:Number = W/SAMPLES; graphics.moveTo(0, H/2); //assumes that the ByteArray is already at the correct location for (var i:int = 0, x:Number = 0; i < SAMPLES; i++, x+=xstep) { var amplitude:Number = waveform.readFloat(); var y:Number = H/2 + (amplitude * H/2); //amplitude is from -1 to 1 graphics.lineTo(x, y); } } } } Code Fullscreen Preview Fullscreen as3bible sound visualization waveform SoundLoaderContext Sound ByteArray SoundMixer.computeSpectrum clear readFloat play URLRequest addEventListener Event.ENTER_FRAME Event String Sprite int Number sort new page view favorite forked pv118 forked from: Chapter 31 Exampl.. Aksor.Al forked:0 favorite:0lines:40 (diff:2) pv176 forked from: Chapter 31 Exampl.. say0 forked:0 favorite:0lines:40 (diff:10)