潜伏期打短的声音在Flash 9,ActionScript 3的 [英] Latency in playing short sounds in Flash 9, Actionscript 3

查看:170
本文介绍了潜伏期打短的声音在Flash 9,ActionScript 3的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个很短的音频剪辑(不到一秒钟长)对各种事件进行播放(按钮悬停,点击等)。然而,通常有动作和声音的实际播放之间的显著滞后。我已经尝试都嵌入在瑞士法郎的声音,并在一开始从外部加载它,但都导致相同的结果。同样,我试着与COM pressed和uncom pressed音频。

I've got a few very short audio clips (less than a second long) to be played on various events (button hover, click, etc). However, there is usually a significant lag between the action and the actual playing of the sound. I have tried both embedding the sound in the .swf, and loading it externally at the start, but both lead to the same results. Likewise, I've tried with compressed and uncompressed audio.

什么它的似乎的喜欢是音频缓冲区只是很多的时间比我需要他们,像或许闪存优化更趋向于一个小的牺牲打更长的声音,没有任何口吃在启动的声音更多的等待时间。难道这是它?有没有什么办法改变呢?因为什么我正在将永远需要播放声音超过一秒钟左右长,总是会在一开始完全加载,它不会伤害它在所有有非常短的缓冲区。

What it seems like is that the audio buffers are just a lot longer than I need them to be, like perhaps Flash is optimized more towards playing longer sounds without any stutter at the expense of a little more latency in starting sounds. Could this be it? Is there any way to change them? Since what I'm working on will never need to play sounds more than a second or so long and will always be loaded completely at the start, it wouldn't hurt it at all to have really short buffers.

这的原因可能是另一个可能的事情:如果我使用.wav文件使用LoadSound只有()的时候......我不能让它真正发挥声音。有没有错误,一切都返回,因为它应该,但没有实际播放声音,这就是为什么我有他们的MP3播放当前。也许使用.mp3音频(或任何COM pressed音频)时,那里只是将在对其进行解码的滞后呢?我之所以仍然对此表示怀疑,不过,是在.swf文件嵌入他们的时候为.wav文件(通过导入到库),他们仍然在播放同样的延迟。

One other possible thing that might be the cause: if I use .wav files when using loadSound()... I can't get it to actually play the sounds. There's no errors, and everything returns as it should, but no actual sound is played, which is why I have them as .mp3 currently. Perhaps when using .mp3 audio (or any compressed audio), there just will be lag in decoding it? The reason I still have doubts about this, though, is that when embedding them in the .swf as .wav files (by importing them into the library), they still have the same latency on playback.

只是一个全面的检查,我会包括code我有,减去不相关的零件和错误检查。首先,在运行时加载它们:

Just for a sanity check, I'll include the code I've got, minus irrelevant parts and error checking. First, loading them at runtime:

var soundArray:Array = new Array();
loadSound( "click", "sounds/buttondroop4.mp3" );
loadSound( "hover", "sounds/Dink-Public_D-146.mp3" );

function loadSound( name:String, url:String ):void
{
   var req:URLRequest = new URLRequest( url );
   soundArray[ name ] = new Sound( req );
   soundArray[ name ].addEventListener( Event.COMPLETE, soundLoaded );
}
function soundLoaded( event:Event ):void
{
   for( var name:String in soundArray )
   {
      if( event.target == soundArray[name] )
      {
         trace( "Loaded sound [" + name + "]" );
         return;
      }
   }
}
function playSound( name:String ):void
{
   for( var nameSrc:String in soundArray )
   {
      if( name == nameSrc )
      {
         var channel:SoundChannel = soundArray[ name ].play();
         return;
      }
   }
}

// Sometime later, well after soundLoaded() callback is triggered...
playSound( "click" );
playSound( "hover" );

和另一种方式,在库类嵌入其中,并从那里去:

And an alternate way, embedding them in the library as classes and going from there:

var sClick:soundClick = new soundClick();
var sHover:soundHover = new soundHover();
sClick.play();
sHover.play();

声音文件是微小,小于10KB一般。滞后已经足够明显,第一个投诉时,看着它的人​​有一个是按钮悬停的声音效果似乎推迟,所以它不只是我被挑剔。我觉得我必须只是做得不对;有太多的闪光的东西在那里,有没有接近这种滞后的任何地方活泼的声音效果。

The sound files are tiny, less than 10kb generally. The lag is apparent enough that one of the first complaints someone had when looking at it was that the sound effects on button hovers seemed delayed, so it wasn't just me being picky. I feel like I must just be doing something wrong; there's too many flash things out there that have snappy sound effects without anywhere near this kind of lag.

编辑:在回答关于声音文件本身的第一反应,我已经检查和声音文件的开头立即开始(甚至裁剪出来的一切,但声音的第一个毫秒,我仍然能听到在滴答噪音它使)的开始。

edit: In response to the first response about sound files themselves, I've already checked, and the sound starts immediately at the start of the file (even clipping out everything but the very first millisecond of sound, I can still hear the start of the 'tick' noise it makes).

推荐答案

这是一个小的事情,但:

It's a little thing but:

function playSound( name:String ):void
{
   for( var nameSrc:String in soundArray )
   {
      if( name == nameSrc )
      {
         var channel:SoundChannel = soundArray[ name ].play();
         return;
      }
   }
}

应该是:

function playSound(name:String):void
{
    if(soundArray[name])
    {
        soundArray[name].play();
    }
}

没有必要为一个循环查找,因为这是在哈希表的用途。此外,你不应该使用数组在所有的,由于数组是用整数索引的有序集合。你想用一个对象(或字典),在这种情况下,并将其命名为soundMap(因为它映射的声音名字听起来对象)。

There is no need for a loop look up since that is what the hash table is for. Also, you shouldn't use an Array at all for that since an Array is an ordered set which is indexed using integers. You want to use an Object (or Dictionary) in this case and name it soundMap (since it maps sound names to sound objects).

至于声音的延迟 - 应该没有。我已经在Flash中做了相当多的声音(包括一吨掉过渡和部署声音),它从来就不是一个问题。不过Flash播放器10有一个新的低这是由的Adobe工程师在那篇文章中的一个描述级别的声音API 。涉及该解决方案是一个有点大锤的,但也许你正在寻找毫秒的精度。

As for sound latency -- there should be none. I've done quite a bit of sound in Flash (including tons of one off rollover and rollout sounds) and it has never been an issue. However Flash Player 10 has a new low-level sound API which is described by one of the Adobe engineers in that article. A solution involving that is a bit of a sledge hammer but perhaps you are looking for millisecond accuracy.

的意见fenomas给人是明智的:检查是否有死腔的MP3文件在开始和结束,修剪它尽可能接近。此外 - 什么是从事件处理程序到你的发挥声明的路径?是否有任何可能的块呢?什么是MP3的格式? Flash作品最适合的特定编码(44.1 HHZ位和128位,我相信)。

The advice fenomas gives is wise: check the mp3 file for deadspace at the start and end and trim it as close as possible. Also - what is the path from the event handler to your play statement? Are there any possible blocks there? What is the format of the mp3? Flash works best with specific encodings (44.1 hHz and 128 bit I believe).

这篇关于潜伏期打短的声音在Flash 9,ActionScript 3的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆