用Flash9/as3跟踪音频波形

本文介绍了一段使用ActionScript 3.0实现的音乐频谱可视化代码,该代码利用了ByteArray和SoundMixer组件来读取音频文件并绘制频谱图形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值