2012-02-06 61 views
0

我想用鍵盤快捷鍵讓現場鼓演奏。問題在於MP3在這種情況下不夠好(編碼器在聲音開始時增加了隨機靜音),而且閃光本身也使延遲(我嘗試使用已經緩衝的播放文件(specified_start_point_in_miliseconds))。所以我的解決方案是OGG(這種格式是無縫的)。 我使用Adobe Alchemy librarysimple frontend for it編譯的swc文件。一切工作正常,OGG文件正在播放,但它仍然有很多延遲 - 無論它的外部或嵌入,以及如果它的第一或第n次。我需要一個解決方案,如何讓聲音播放速度與按鍵相同。 這是我很簡單的例子代碼:Flash AS3 - OGG聲音延遲(Adobe Alchemy庫)

import flash.display.Sprite; 
import flash.events.*; 
import flash.utils.ByteArray; 
import flash.events.SampleDataEvent; 
import com.mauft.OggLibrary.OggStream; 
import com.mauft.OggLibrary.OggEmbed; 

public class ogg extends Sprite 
{ 

    [Embed(source="/drumssnare2.ogg",mimeType="application/octet-stream")] private var OGG_FILE:Class //Embed Ogg file as binary stream 

    public function ogg() 
    { 
    var gameinfo:Sprite=new Sprite(); 
    gameinfo.graphics.beginFill(0x000000,1); 
    gameinfo.graphics.drawRect(0,0,240,16); 
    gameinfo.graphics.endFill(); 
    gameinfo.addEventListener(MouseEvent.CLICK, playOGG); 
    addChild(gameinfo); 
    //var streamTest:OggStream=new OggStream("http://127.0.0.1/~7z/drumssnare2.ogg"); 

     var embedTest:OggEmbed=new OggEmbed((new OGG_FILE) as ByteArray) //Create new instance of OggEmbed 

     function playOGG():void 
     { 
     //var streamTest:OggStream=new OggStream("http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg") 

     //streamTest.play(0); 
     embedTest.play(0); 

     } 
    } 
} 

回答

1

我是有我與循環的Flash CS5.5項目的音頻文件同樣的問題。 我和我的音頻總監花了太多時間在as3中尋找循環的快速和「無間隙」解決方案。 他製作了一個.aif文件,沒有任何間隙,我將它導入到我的庫中,從我的Main類調用。 然後,我們改變了聲音屬性,似乎是這樣的:

http://s7.postimage.org/6me47lfzv/Screen_shot_2012_02_06_at_4_35_15_PM.png

在ActionScript我所說的.AIF文件是這樣的:

var aifSound:AifSound = new AifSound(); 
//AifSound is the name of the file in the ActionScript tab 

//creates a new Sound Channel 
var scAif:SoundChannel = new SoundChannel(); 
scAif = aifSound.play(0,999, 1); 

OK,它給了我一個循環無間隙,延遲或性能併發症。 嘗試一下併發布反饋!

ps .:對不起我的壞英語

謝謝你stackoverflow!

+0

稍微好一點,但仍然太多延遲。在這裏,我發給你[FLA,AS3很短的例子和原始聲音文件](http://speedy.sh/WrXaf/gapless.zip)。您可以單擊黑色區域或使用鍵盤上的任意鍵測試聲音。我最喜歡重點測試,嘗試播放一些簡單的節奏節拍。 – speedy 2012-02-06 19:59:38

+0

嘿男人,試試它在其他電腦因爲它在這裏播放沒有任何延遲!我在一個iMac核心2二重奏工作,並正常工作。 – 2012-02-06 20:33:52

+0

我在Core 2 Duo上工作,但PC。但是,無論如何,我需要它爲大多數用戶毫不拖延地工作(這也是一些較舊的電腦)。 – speedy 2012-02-06 20:45:52