Repeating a short sound very fast with CreateJS

时间:2017-12-18 07:32:18

标签: createjs soundjs

Goal

I am trying to create a fast ticking sound in a Cordova app using Createjs.

The ticking sound speed changes based on user settings. At the moment the timing is erratic

Setup

I have an mp3 audio file of a single tick sound that is 50ms long.

A target speed of repetition could be as fast as 10 times per second.

Question

How can I get the sound to play evenly and consistently at that speed?

More Technical Detail

createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED;
createjs.Ticker.framerate = 30;

Cheers for any help

1 个答案:

答案 0 :(得分:0)

这应该非常简单。我设置了一个快速小提琴,每秒播放特定次数的声音。即使以60fps的速度播放,它看起来也非常可靠。

https://jsfiddle.net/lannymcnie/ghjejvq9/

如果自上次嘀嗒声后经过了一段时间,那么方法就是检查每个Ticker.tick。持续时间由1000/ticksPerSecond得出。

// Every tick
var d = new Date().getTime();
if (d > lastTick + 1000/ticksPerSecond) {
  createjs.Sound.play("tick");
  lastTick = d;
}