Flash专栏: 基础教程 | 技巧运用 | MTV实例教程 | 游戏实例教程 | 实例教程 | AS教程(new)
photoshop专栏: 基础 | 进阶 | 技巧总汇 | 精彩实例 | 文字特效 | 滤镜魔术 | 实际应用
网页设计: Dreamweaver教程 | FireWorks教程 | CorelDraw设计 | Freehand/Illustrator教程 | 音乐转换教程
其他教程: 操作系统 | 程序设计 | 网站开发 | 图形图像 | 数据库 | 网络技术 | 安全相关 | 认证考试 | 硬件知识 | 服务器
Flash专栏>Flash基础教程>用Flash9/as3跟踪音频波形   返回上一页

  日期:2006-08-17 11 作者:xiangming 来源:闪吧
天气预报 IP地址 手机号码 邮编 翻译 在线代理 在线评书 好dj


用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日


 
高手云集 版权所有 1998-2006