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 graph v0.1

This is a very simple example of a few of things:

1. how to capture audio data from a microphone
2. how to use read the values
3. how to use a bitmap object to display the data
Get Adobe Flash player
by NME 16 May 2012
//Originally written by NME a.k.a Anthony R Pace
package { 
    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 h:int = stage.stageHeight,
        bmp:Bitmap = new Bitmap(new BitmapData(512,h,false,0x000000)), //the bitmap that will be used to represent the time domain
        mic:Microphone = Microphone.getMicrophone(),
        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 = (h/2);//amount to normailize for visual representation, or 'A'  for amplitude factor.  
        public function sdeh(e:SampleDataEvent):void{ //sample data event handler
            bah = e.data;
            bah.position = 0;
            bmp.bitmapData.lock();
            bmp.bitmapData = new BitmapData(512,500,false,0x000000);
            for (n = 0;n<512;++n){
               sn = bah.readFloat();
               bmp.bitmapData.setPixel(n,A-sn*A,0xffffff);
            }
            bmp.bitmapData.unlock();
        }
        public function BMPAudioGraph():void {
            stage.addChild(bmp);//make the bitmap visible on the display list
            mic.rate = 11;// sets N, the sample frequency to 11025
            mic.setSilenceLevel(0);//setting this to 0 makes it so you hear all activity
            mic.addEventListener(SampleDataEvent.SAMPLE_DATA,sdeh); // call the sdeh function if the mic hears audio
        }}}