一聚教程网:一个值得你收藏的教程网站

热门教程

AS3.0新功能:跟踪音频

时间:2022-07-02 17:07:05 编辑:袖梨 来源:一聚教程网

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);

热门栏目