2015-07-05 49 views
5

我沃金上分析聲音文件的音調一progarm。我遇到了一個非常好的API,稱爲「TarsosDSP」,它提供了各種音調分析。不過,我在設置時遇到了很多麻煩。有人能告訴我一些關於如何使用這個API(特別是PitchProcessor類)的快速指針嗎?一些代碼片段將非常值得讚賞,因爲我在聲音分析方面真的很新穎。TarsosDSP間距分析傻瓜

感謝

編輯:我發現了一些文件在http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Sound_Programming那裏有一些示例代碼演示如何設置PitchProcessor,...

int bufferReadResult = mRecorder.read(mBuffer, 0, mBufferSize); 
// (note: this is NOT android.media.AudioFormat) 
be.hogent.tarsos.dsp.AudioFormat mTarsosFormat = new be.hogent.tarsos.dsp.AudioFormat(SAMPLE_RATE, 16, 1, true, false); 
AudioEvent audioEvent = new AudioEvent(mTarsosFormat, bufferReadResult); 
audioEvent.setFloatBufferWithByteBuffer(mBuffer); 
pitchProcessor.process(audioEvent); 

...我完全迷失了方向,究竟是mBuffer和mBufferSize?我如何找到這些值?我在哪裏輸入我的音頻文件?

回答

7

音頻在TarsosDSP框架的基本流程如下:從音頻文件或一個麥克風始發傳入的音頻流被讀出和切碎成的例如幀1024個樣本。每一幀都通過一條管道進行修改或分析(例如音調分析)。

在TarsosDSP的AudioDispatcher負責砍在幀中的音頻。它還將音頻幀封裝到AudioEvent對象中。此AudioEvent對象通過AudioProcessors鏈發送。

所以在你的代碼引用mBuffer是音頻幀,mBufferSize是在樣本緩衝區的大小。您可以自己選擇緩衝區大小,但對於基音檢測,2048個樣本是合理的。

音調檢測,你可以做這樣的事情與TarsosDSP庫:

PitchDetectionHandler handler = new PitchDetectionHandler() { 
     @Override 
     public void handlePitch(PitchDetectionResult pitchDetectionResult, 
       AudioEvent audioEvent) { 
      System.out.println(audioEvent.getTimeStamp() + " " pitchDetectionResult.getPitch()); 
     } 
    }; 
    AudioDispatcher adp = AudioDispatcherFactory.fromDefaultMicrophone(2048, 0); 
    adp.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, 44100, 2048, handler)); 
    adp.run(); 

在這段代碼中首先處理程序創建了簡單的打印檢測到的音高。 AudioDispatcher連接到默認麥克風,緩衝區大小爲2048.檢測音高的音頻處理器已添加到AudioDispatcher。處理程序也在那裏使用。

最後一行開始的過程。

+0

非常感謝您的先生! – STELLARWIND

+0

謝謝@Joren我非常感謝你在Tarsos所做的工作。作爲別人,System.out.println()缺少一個「+」,我需要添加一個採樣率作爲.fromDefaultMicrophone()的第一個參數。 – Sam