In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: soundtest023

sound by AlainMikuni
Get Adobe Flash player
by gaina 06 Mar 2011
/**
 * Copyright gaina ( http://wonderfl.net/user/gaina )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rb2A
 */

// forked from gaina's soundtest023
package  
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.GlowFilter;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    
    public class Main extends Sprite
    {
        private var snd:Sound;
        private var point_array:Array;
        
        function Main() 
        {
            point_array = points();
            playSound("http://www.takasumi-nagai.com/soundfiles/sound004.mp3");
        }
        
        private function playSound(sndUrl:String):void
        {
            snd = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10,true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.load(req, context);
            snd.addEventListener(Event.COMPLETE, SoundLoaded);
        }
        
        private function SoundLoaded(e:Event):void 
        {
            var sndChannel:SoundChannel=new SoundChannel();
            sndChannel = snd.play(0, 5);
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(event:Event):void {
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes, false, 0);
            Drawing(bytes, 512);
        }
                
        private function Drawing(_bytes:ByteArray = null, num:int = 512, count:int = 2):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0xFFFFFF);
            
            var d:Number = 0;
            var n:uint;
            var i:uint;
            for (n = 0; n < count; n++) {
                for (i = 0; i < num / count; i++) {
                    var p:PointPlus = point_array[n][i] as PointPlus;
                    var data:Number = _bytes.readFloat() * 1.5;
                    if (n == 0) {
                        p.vx = p.x * data ;
                        p.vy = p.y * data ;
                    }else {
                        p.vx = p.x * data * -1 ;
                        p.vy = p.y * data;
                    }
                    if (i == 0) {
                        graphics.moveTo(p.x, p.y);
                        
                    }else {
                        graphics.curveTo(point_array[n][i-1].x, point_array[n][i-1].y, p.x + p.vx, p.y + p.vy);
                    }
                    d += data;
                }
            }
            if(d < 0) d = d * -1;
            var _color:uint = Math.round(d * 100000);
            _color = _color % 0xFFFFFF;
            this.filters = [new GlowFilter(_color, 1, d, d)];
            graphics.endFill();
        }
        
        private function points():Array
        {
            var container_array:Array = [];
            var i:int;
            var j:int;
            for (i = 0; i < 2; i++) {
                var _array:Array = [];
                for (j = 0; j < 256; j++) {
                    var p:PointPlus = new PointPlus();
                    p.x = stage.stageWidth / 2;
                    p.y = j * stage.stageHeight / 256;
                    _array.push(p);
                }
                container_array.push(_array);
            }
            return container_array;
        }
        
    }

}

class PointPlus
{
    public var x:int;
    public var y:int;
    public var vx:int;
    public var vy:int;
    
    public function PointPlus() {}
}