2013-02-09 27 views
0

我需要做一些混音工作。我發現的例子在Adobe的幫助:我需要更多關於sound.extract()的信息

var sourceSnd:Sound = new Sound(); 
var outputSnd:Sound = new Sound(); 
var urlReq:URLRequest = new URLRequest("test.mp3"); 

sourceSnd.load(urlReq); 
sourceSnd.addEventListener(Event.COMPLETE, loaded); 

function loaded(event:Event):void 
{ 
    outputSnd.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound); 
    outputSnd.play(); 
} 

function processSound(event:SampleDataEvent):void 
{ 
    var bytes:ByteArray = new ByteArray(); 
    sourceSnd.extract(bytes, 4096); 
    event.data.writeBytes(upOctave(bytes)); 
} 

function upOctave(bytes:ByteArray):ByteArray 
{ 
    var returnBytes:ByteArray = new ByteArray(); 
    bytes.position = 0; 
    while(bytes.bytesAvailable > 0) 
    { 
     returnBytes.writeFloat(bytes.readFloat()); 
     returnBytes.writeFloat(bytes.readFloat()); 
     if (bytes.bytesAvailable > 0) 
     { 
      bytes.position += 8; 
     } 
    } 
    return returnBytes; 
} 

它說:

target:ByteArray — A ByteArray object in which the extracted sound samples are placed. 

length:Number — The number of sound samples to extract. A sample contains both the left and right channels — that is, two 32-bit floating-point values. 

我建議

必須編寫leftchannel值和rightchannel價值。

bytes.position += 8 

減少樣本,使聲音播放更快。我試圖將該值修改爲4.速度減慢到2,並且我只有噪音,爲什麼?其他值,如16或更高,沒有聲音輸出。爲什麼?如何通過一個浮點值來製作各種音效?

我需要更多信息來了解我的工作,請幫助。

更新:我稍微改變upOctave()函數,速度現在可以調整。

 function upOctave(bytes:ByteArray):ByteArray 
     { 
      var returnBytes:ByteArray = new ByteArray(); 
      bytes.position = 0; 
      var position:int = 0; 
      var speed:Number = 0.75; 
      while(bytes.bytesAvailable > 0) 
      { 
       if (bytes.bytesAvailable > 0) 
       { 
        bytes.position = int(speed*position)*8; 
       } 
       position++; 
       if(bytes.bytesAvailable>0){ 
        returnBytes.writeFloat(bytes.readFloat()); 
        returnBytes.writeFloat(bytes.readFloat()); 
       } 
      } 
      return returnBytes; 
     } 

回答

0

總之,bytes.position += 8;不意味着玩。

每個浮點和兩個通道4個字節。移動,如下圖所示。

8字節數組是1組。換句話說,抽樣。

4byte 4byte 
[ L ][ R ] [ L ][ R ] [ L ][ R ] [ L ][ R ] ... 

     1    2    3    4 

L,R32浮動。連續數據在-1和1之間,如Sin函數。

創建一個波形,可以控制聲音。直波,鋸齒波,三角波,正弦波,噪聲波......最終聲音依賴於波形。

如果你想調整playrate讀了這篇文章:http://www.kelvinluck.com/2008/11/first-steps-with-flash-10-audio-programming/

+0

感謝,因爲我理解的結構,現在我可以改變速度,請參見上面的^^的代碼,你可以告訴名詞更多信息你提到關於波形? – user2003548 2013-02-09 08:39:31

相關問題