AS3中准确的BPM事件监听器

knu*_*uck 2 apache-flex flash audio actionscript-3

我正在尝试将动画同步到特定BPM的音乐.我尝试过使用Timer但是在处理小间隔时(毫秒)不准确.我做了一些阅读,发现了一种使用小型静音音频文件和SOUND_COMPLETE事件作为Timer的替代方法.

我用这段代码用了167ms长的声音文件.

package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    public class BetterTimer extends EventDispatcher
    {
        private var silentSound:Sound;

        public function BetterTimer(silentSoundUrl:String):void {
            super();
            silentSound = new Sound( new URLRequest(silentSoundUrl) );
            silentSound.addEventListener(Event.COMPLETE, start);
        }
        public function start():void {
            this.timerFired( new Event("start") );
        }
        private function timerFired(e:Event):void {
            dispatchEvent( new Event("fire") );
            var channel:SoundChannel = silentSound.play();
            channel.addEventListener(Event.SOUND_COMPLETE, timerFired, false, 0, true);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这仍然没有留下来.Flash Player是否具有声音准确性?

Joa*_*ert 5

您还可以将新的Sound API与SampleDataEvent一起使用,并基本上使用Sound.extract()手动播放MP3.在这种情况下,您可以预先了解延迟,甚至可以在您的(延迟)事件发生时计算样本.

这就是我们在AudioTool中所做的工作,它运作良好.