2011-12-15 120 views
1

我目前正在錄音並存儲字節數組以供播放和隨後編碼爲mp3。AS3在錄音開始點擊聲音

不幸的是,雖然我在錄製的一開始就得到了一個點擊聲音。

我試圖幾個方法來嘗試消除這種如:

  1. 記錄所述第1.3秒mic.gain = 0;然後設置mic.gain = 50;

  2. 清除字節組後第1.3秒鐘,然後繼續寫的ByteArray(實際上刪除記錄的第1.3秒)。

無論這些方法已經停止點擊是添加。

有沒有人有一個想法,我可以如何防止點擊被添加?

這是我錄製/存儲代碼:

public var mic:Microphone = Microphone.getMicrophone(); 
public var micSilence:uint; 
private var soundBytes:ByteArray = new ByteArray(); 
private var soundBA:ByteArray = new ByteArray(); 

mic.gain = 50; 
mic.setSilenceLevel(1, 2000); 
mic.rate = 44; 
Security.showSettings("2"); 
mic.setLoopBack(false); 
mic.setUseEchoSuppression(false); 

private function startRecordingAfterCountdown():void {  
    mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);    
} 

private function micSampleDataHandler(event:SampleDataEvent):void {  
    while (event.data.bytesAvailable){ 
     var sample:Number = event.data.readFloat(); 
     soundBytes.writeFloat(sample); 
    } 
} 

private function stopRecord():void {   
    mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);  
    soundBytes.position = 0; 
    soundBA.clear(); 
    soundBA.writeBytes(soundBytes); 
    soundBA.position = 0; 
    soundBytes.clear(); 

    var newBA:ByteArray = new ByteArray(); 
    newBA.writeBytes(soundBA); 
    recordingsArray[0] = newBA;  
} 

回答

3

雖然我不能重現一下,我想可能通過在記錄的開始音量的急劇增加引起。因此可以通過平滑增加音量來消除影響。這樣的事情:

// the amount of volume increasing time in ms 
public static const VOLUME_INC_TIME_MS:uint = 200; 
// in bytes 
public static const VOLUME_INC_BYTES:uint = VOLUME_INC_TIME_MS * 44.1 * 4; 

private function micSampleDataHandler(event:SampleDataEvent):void 
{ 
    var bytesRecorded:uint = soundBytes.length; 
    while(event.data.bytesAvailable) 
    { 
     var sample:Number = event.data.readFloat(); 
     if(bytesRecorded < VOLUME_INC_BYTES) 
     { 
      // using linear dependence, but of course you can use a different one 
      var volume:Number = bytesRecorded/VOLUME_INC_BYTES; 
      soundBytes.writeFloat(sample * volume); 
      bytesRecorded += 4; 
     }else 
     { 
      soundBytes.writeFloat(sample); 
     } 
    } 
} 

希望這會有所幫助。

+0

再次令人驚歎!謝謝Semen :) – crooksy88 2011-12-15 13:19:35