1

我想在声音管理器提供的画布数据上实时绘制waveformData,让它看起来像一条均衡器线,像 http://paperjs.org/tutorials/animation/creating-animations/#moving-multiple-items一样平滑移动。问题是一切都被重绘了,看起来不太顺利。任何想法如何改进它?

`

   paper.install(window);
   var soundOutput = [];

   $(document).ready(function(){
   soundManager.url = 'swf/';
   soundManager.flashVersion = 9;
   soundManager.useHTML5Audio = true;

   soundManager.onready(function() {
var song = soundManager.createSound({
       id: 'song',
       url: '4353.mp3',
       useWaveformData: true,
});
song.play();
var i = 0;
function data() {

  if (!(i % 4)) {
    for (n=0; n<20; n++) {
        soundOutput[n] = song.waveformData.left[n];
    }
  }
  i++;
  window.webkitRequestAnimationFrame(data);

}
data();
   });

canvas = document.getElementById("scene");
canvas.width = 632;
canvas.height = 660;
paper.setup('scene');
view.size = [500, 500];
var amount = 20;
var height = 60;

var path = new Path();
path.style = {
    strokeColor: new GrayColor(0.2),
    strokeWidth: 30,
    strokeCap: 'square'
};

for (var i = 0; i <= amount; i++) {
    path.add(new Point(i/amount * 500, 50));
}


   path.selected = true;
view.onFrame = function(event) {
    for (var i = 0; i <= amount; i++) {
        var segment = path.segments[i];

        segment.point.y = soundOutput[i] * 1000;
    }


}
  view.draw();

})`
4

1 回答 1

0

您可以尝试降低帧速率:

setTimeout(function(){
  webkitRequestAnimationFrame(data)
}, 1000 / 20); // 20fps.
于 2013-02-07T04:27:19.770 回答