|
用Flash9/as3跟踪音频波形
Actionscript 3.0提供的新功能,其中用到了ByteArray、SoundMixer。 代码如下:
function func(a:Number) { return num * Math.sin(a); } function drawFunction(func:Function, thickness:Number, color:Number) { graphics.lineStyle(thickness, color, 100); graphics.moveTo(30, stage.stageHeight / 2 - func((30 + t) / 20) * 20); for (var i = 30; i <= stage.stageWidth - 30; i++) { var fi = stage.stageHeight / 2 - func((i + t++) / 20) * 20; graphics.lineTo(i, fi); } } function spectrum(event:Event) { graphics.clear(); SoundMixer.computeSpectrum(ba, true, 0); num = ba.readFloat() * 10; drawFunction(func, 1, 0x0066cc); } var sound:Sound = new Sound(); var sound_channel:SoundChannel; var ba:ByteArray = new ByteArray(); var num:Number; var t:Number = 0; sound.load(new URLRequest("test.mp3")); sound_channel = sound.play(); this.addEventListener(Event.ENTER_FRAME, spectrum); 请用Flash 9/ActionScript 3.0发布测试 下载(download)
ps: 更牛效果请看http://theflashblog.com/?p=182 在线帮助文档:http://livedocs.macromedia.com/flex/2/langref/package-summary.html
责任编辑:uufeng 时间:2006年8月10日
|