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

sound wave graph !CAUTION! high volume sound - check your volume level

Check your computer's Volume control.
This test may hurt your ears!
defoult sound frecuency:    15Hz (I believe so...)
(sine wave)
defoult sampling frec.:    4096 (I dont know wtf is this)

Click buttons below the wave window to change wave form
osctype=0:sin: telephon        low volume
osctype=1:sawtooth: bug buzz !CAUTION! very high volume
osctype=2:square: chip buzz    !CAUTION! very high volume
osctype=3: triangular:        low volume
Get Adobe Flash player
by yukifuruyoru 22 Aug 2010
    Embed
/**
 * Copyright yukifuruyoru ( http://wonderfl.net/user/yukifuruyoru )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3mCR
 */

/*Check your computer's Volume control.
    This test may hurt your ears!
    defoult sound frecuency:    15Hz (I believe so...)
    (sine wave)
    defoult sampling frec.:    4096 (I dont know wtf is this)

    Click buttons below the wave window to change wave form
    osctype=0:sin: telephon        low volume
    osctype=1:sawtooth: bug buzz !CAUTION! very high volume
    osctype=2:square: chip buzz    !CAUTION! very high volume
    osctype=3: triangular:        low volume
*/

package {
    import flash.display.Sprite;
    import flash.media.Sound;
    import flash.events.SampleDataEvent;
    public class Main extends Sprite {
        public function Main():void {
            trace(256);
            var wg:Waveg=new Waveg(this);
            with(wg){
                    x=32;
                   y=82;
            }
    var mySound:Sound = new Sound();
    function sineWaveGenerator(e:SampleDataEvent):void {
    var n:Number;//n must be betw. 0~1
    for    ( var c:int=0; c<4096; c++ ) {
        n=wg.osc(c);
        e.data.writeFloat(n);
        e.data.writeFloat(n);
    }
}

        mySound.addEventListener(SampleDataEvent.SAMPLE_DATA,sineWaveGenerator);
        mySound.play();
        }
    }
}

import flash.display.Sprite;
import flash.events.MouseEvent; 
class Waveg extends Sprite{
    public var osc:Function;//oscilation type select
    
    private var board:Sprite;
    private var W:uint=400;        //suppose W=1sec for now
    private var H:uint=300;
    private var A:uint=H>>>2;    //Max. amplicity
    private var f:uint=440;        //frecuency of wave(Hz)
    private var RATE:uint=4096;    //sampling frecuency (Hz)
    private var PI:Number=Math.PI;
    private var g:Number;    //gain for time t.
    
    public function Waveg(tgt:Sprite):void{
        initWin();
        initBoard();
        initLevs();
        tgt.addChild(this);
        osctype=0;
    }
    public function initLevs():void{
        var levs:Sprite=new Sprite();
        levs.graphics.beginFill(0xcccccc);
        for(var i:uint=0;i<4;i++){
            levs.graphics.drawRoundRect(i*W/4,0,W/(4+2),60,20);
        }
        levs.addEventListener(MouseEvent.CLICK,onLev);
        function onLev(e:MouseEvent):void{
            var i:uint=e.target.mouseX*4/W;
            osctype=i;
        }
        levs.y=H+5;
        levs.x+=(W-levs.width)/2;
        addChild(levs);
    }
    public function set osctype(n:uint):void{
        switch(n){
            case 0:osc=sen;break;
            case 1:osc=saw;break;
            case 2:osc=squ;break;
            case 3:osc=tri;break;
        }
        wavegeneration();
    }
    
    public function squ(t:uint):Number{
        g=(Math.sin(f*(t/RATE*PI*2))>0)?1:-1;
        return g;
    }
    public function sen(t:uint):Number{
        g=Math.sin(f*(t/RATE*PI*2));
        return g;
    }
    public function saw(t:uint):Number{
        t=t%(RATE/f);
        g=t/RATE*f*2;
        g+=(g>1)?-2:0;
        return g;
    }
    public function tri(t:uint):Number{
        t=t%(RATE/f);
        g=t/RATE*f*4;
        g=(g>1)?2-g:g;
        g=(g<-1)?-2-g:g;
        return g;
    }
    public function wavegeneration():void{
        var a:Number=osc(0);
        board.graphics.clear();
        board.graphics.moveTo(0,a*A);
        board.graphics.lineStyle(0,0x00CC00);
        for(var i:uint=0;i<RATE+1;i++){//i(time)=1s/RATE
            a=osc(i);
            board.graphics.lineTo(i*W/RATE,a*A);
        }
    }
    private function initWin():void{
        with(graphics){
        beginFill(0x222222);
        drawRoundRect(0,0,W,H,20);
        endFill();
        lineStyle(0,0xcccccc);
        moveTo(0,H>>>1);
        lineTo(W,H>>>1);
        }
    }
    private function initBoard():void{
        board=new Sprite();
        board.y=H>>>1;
        board.scaleY=-1;
        addChild(board);
    }
}