录音波形绘制代码

录音波形绘制代码:

// frame action
import flash.media.Microphone;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
import flash.display.Graphics;
var nWidth:Number = stage.stageWidth;
var nCenter:Number = stage.stageHeight / 2;
var nScale:Number = 100;
var myGraphics:Graphics = graphics;
var my_mic:Microphone = Microphone.getMicrophone();
my_mic.rate = 22;
my_mic.gain = 100;
my_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, drawSampleData);
function drawSampleData(eventObject:SampleDataEvent):void 
{
   var myData:ByteArray = eventObject.data;
   myGraphics.clear();
   myGraphics.lineStyle(0, 0x000000);
   myGraphics.moveTo(0, nCenter);
   var nPitch:Number = nWidth / myData.length;
   while (myData.bytesAvailable > 0) 
    {
   var nX:Number = myData.position * nPitch;
   var nY:Number = myData.readFloat() * nScale + nCenter;
   myGraphics.lineTo(nX, nY);
   }
}

录音波形绘制代码_第1张图片

来源地址:
http://www.adobe.com/devnet/flash/articles/flcs5_features_microphone_event.html

你可能感兴趣的:(录音波形绘制代码)