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

Hype Octaves

range for each octave taken from hype framework https://github.com/hype/HYPE_AS3/blob/master/src/hype/framework/sound/SoundAnalyzer.as
playSound function taken from gaina
http://wonderfl.net/user/gaina
at 
http://wonderfl.net/c/dllp
Get Adobe Flash player
by aobyrne 07 Jun 2012
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zfuF
 */

package  
{
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.media.Sound;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.system.fscommand;
    import flash.ui.Keyboard;
    import flash.utils.ByteArray;
    
    /**
     * ...
     * @author sandcastls
     */
    public class SoundTestOctavesWonderfl extends Sprite 
    {
        private var _octaveList:Array;
        private var shapes:Array;
        private var supposedMaximum:Number;
        
        public function SoundTestOctavesWonderfl() 
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, function (e:KeyboardEvent):void { if ("Q" == String.fromCharCode(e.keyCode) || e.keyCode == Keyboard.F6) fscommand("quit"); }, false, 0, true);
            
            //new Sound(new URLRequest('assets/realentada.mp3')).play();
            //new Sound(new URLRequest('assets/turkish.mp3')).play();
            _octaveList = new Array();
            _octaveList[0] = [1, 2];
            _octaveList[1] = [3, 4];
            _octaveList[2] = [5, 10];
            _octaveList[3] = [11, 20];
            _octaveList[4] = [21, 41];
            _octaveList[5] = [42, 82];
            _octaveList[6] = [83, 163];
            _octaveList[7] = [164, 256];
            var lastOctaveDelta:int = _octaveList[7][1] - _octaveList[7][0];
            //trace( "lastOctaveDelta : " + lastOctaveDelta );
            supposedMaximum = 1 / 1.42;            
            drawRectangles();
            //playSound("http://www.takasumi-nagai.com/soundfiles/01.mp3");
            playSound("http://www.takasumi-nagai.com/soundfiles/sound001.mp3");
            
        }
        private function playSound(sndUrl:String):void
        {
            var snd:Sound = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10,true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.addEventListener(Event.COMPLETE, onComp);
            snd.load(req, context);
        }        
        
        private function onComp(e:Event):void 
        {
            var sound:Sound = e.target as Sound;
            sound.play(0,10);
            //trace( "SoundTestOctaves.onComp > e : " + e );
            addEventListener(Event.ENTER_FRAME, loop);
        }
        private function loop(e:Event):void 
        {
            //trace( "SoundTestOctaves.loop > e : " + e );
            var byteArray:ByteArray = new ByteArray;
            SoundMixer.computeSpectrum(byteArray, true, 0);
            var sm:Number = supposedMaximum;
            for (var i:int = 0; i < 256; i++) 
            {
                var shape:Shape = shapes[i] as Shape;
                shape.alpha= 1-byteArray.readFloat() * sm;
            }
        }
        
        private function drawRectangles():void 
        {
            var count:int;
        
            var gap:Number = 2;
            var height:Number = 465;
            var ol:uint = _octaveList.length;
            var stepY:uint = 465 / ol;
            shapes = [];
            for (var i:int = 0; i < ol; i++) 
            {
                var delta:int =1+ _octaveList[i][1] - _octaveList[i][0];
                //trace( "delta : " + delta );
                var number:Number = 465 / delta;
                //trace( "number : " + number );
                for (var j:int = 0; j < delta; j++) 
                {
                    count++; 
                    var shape:Shape = addChild(new Shape) as Shape;
                    var shape2:Shape = addChild(new Shape) as Shape;
                    var gg:Graphics = shape.graphics;
                    var gg2:Graphics = shape2.graphics;
                    gg.lineStyle(0);
                    //gg2.beginFill(0xfff*Math.random());
                    gg2.beginFill(0x0);
                    gg.drawRect(0, 0, number, stepY);
                    gg2.drawRect(0, 0, number, stepY);
                    shape.x =shape2.x = j * number;
                    shape.y = shape2.y = i * stepY;
                    shapes[shapes.length] = shape2;
                }
                    
            }
            //trace( "count : " + count );
            //trace( "(count -256) : " + (count -256) );
        
        }
        
    }

}