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

basic bmp audio wave graph v0.2

Originally written by NME a.k.a Anthony R Pace

just bored, thought it might look neat as water, and decided to spend the minute required to change it.  Now that I see it, I don't actually like it as much as I thought I would... but w/e.
Get Adobe Flash player
by NME 16 May 2012
  • Forked from NME's basic bmp audio graph v0.1
  • Diff: 9
  • Related works: 4
  • Talk

    tests2090 at 13 Sep 2012 23:12
    put some dolphin or boat then it is ok or otherwise can you give me the access for it or source code of it
    tests2090 at 13 Sep 2012 23:12
    put some dolphin or boat then it is ok or otherwise can you give me the access for it or source code of it
    NME at 12 Oct 2012 10:12
    Not sure what you mean by give you source code? I published it under the MIT license, so the code is open. With regard to a boat and dolphins, I have actually thought about it.
    test2234478 at 17 Feb 2013 22:03
    Hi nme why can you make a dolphin jumbing with the help of microphone
    test2234478 at 17 Feb 2013 22:04
    Hi nme why can you make a dolphin jumbing with the help of microphone
    test2234478 at 02 Mar 2013 13:42
    no reply nme
    test2234478 at 02 Mar 2013 13:42
    no reply nme
    NME at 14 Mar 2013 01:09
    do you mean, why can't I? You have to think about imperfect looking waves, your maximum amplitude, and how that would look, if it touched the borders. I would need to either make the dolphin look like it's coming from the bottom of the screen, decrease the max amplitude to something decent, or detect the highest amplitude (just a simple top k) and be sure it won't mess with the placement of the dolphins exit and entry points during the jump. In fact the easiest thing to do, would be to have the dolphin jump from underneath the max amplitude, and off to a corner or off screen entirely. None of this is very difficult, so if I have time/ the inclination I might do it; yet, it's not on my todo list right now.
    NME at 14 Mar 2013 01:11
    btw... if you are going to do it, without waiting for me to do it for you, than you may want to think about the dolphin jumping over the wave, instead of from the water initially, as that might be easier for you to accomplish.

    Tags

    Embed
/**
 * Copyright NME ( http://wonderfl.net/user/NME )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pHdf
 */

// forked from NME's basic bmp audio graph v0.1
//Originally written by NME a.k.a Anthony R Pace
package {
    import flash.geom.Rectangle; 
    import flash.utils.ByteArray;
    import flash.events.SampleDataEvent;
    import flash.media.Microphone;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Sprite;
    public class BMPAudioGraph extends Sprite {
        public var  bmpHeight:int = stage.stageHeight,//The height of the graph
                    bmp:Bitmap = new Bitmap(new BitmapData(512,bmpHeight,false,0xE9FBFF)), //the bitmap that will be used to represent the time domain
                    mic:Microphone = Microphone.getMicrophone(), //the default microphone if available
                    n:int, // the sample number
                    sn:Number,  //sample value at n, or s[n] 
                    bah:ByteArray, //Byte Array  that Holds the sample data
                    A:Number = (bmpHeight/2),//'A'  for amplitude factor.  
                    sampleRect:Rectangle = new Rectangle(0,0,1,0);
        public function sdeh(e:SampleDataEvent):void{ //sample data event handler
            bah = e.data;
            bah.position = 0;
            bmp.bitmapData.lock();
            bmp.bitmapData.fillRect(bmp.bitmapData.rect,0xE9FBFF);
            for (n = 0;n<512;++n){
               sn = bah.readFloat();//reads 4 bytes = 32 bit floating point sample value
               sampleRect.x = n;
               sampleRect.y = A-sn*A;//in this case I am using the Amplitude as not only a factor, but also the offset for the zero line.
               sampleRect.height = bmpHeight - sampleRect.y;
               bmp.bitmapData.fillRect(sampleRect,0x3CD8FF);//d7f7ff
            }
            bmp.bitmapData.unlock();
        }
        public function BMPAudioGraph() {
            stage.addChild(bmp);//make the bitmap visible on the display list
            mic.rate = 11;// sets the sample frequency to 11025hz
            mic.setSilenceLevel(0);//setting this to 0 makes it so you hear all activity... you should notice noise in the line.
            mic.addEventListener(SampleDataEvent.SAMPLE_DATA,sdeh); // call the sdeh function if the mic hears audio
        }
    }
}