我正在嘗試使用TarsosDSP庫檢測.wav文件中的音高,並且頻率結果始終小於一半。來自.wav文件的TarsosDSP Pitch Detection。並且結果頻率始終低於一半
這是我的代碼。
public class Main {
public static void main(String[] args){
try{
float sampleRate = 44100;
int audioBufferSize = 2048;
int bufferOverlap = 0;
//Create an AudioInputStream from my .wav file
URL soundURL = Main.class.getResource("/DetectPicthFromWav/329.wav");
AudioInputStream stream = AudioSystem.getAudioInputStream(soundURL);
//Convert into TarsosDSP API
JVMAudioInputStream audioStream = new JVMAudioInputStream(stream);
AudioDispatcher dispatcher = new AudioDispatcher(audioStream, audioBufferSize, bufferOverlap);
MyPitchDetector myPitchDetector = new MyPitchDetector();
dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, sampleRate, audioBufferSize, myPitchDetector));
dispatcher.run();
}
catch(FileNotFoundException fne){fne.printStackTrace();}
catch(UnsupportedAudioFileException uafe){uafe.printStackTrace();}
catch(IOException ie){ie.printStackTrace();}
}
}
class MyPitchDetector implements PitchDetectionHandler{
//Here the result of pitch is always less than half.
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult,
AudioEvent audioEvent) {
if(pitchDetectionResult.getPitch() != -1){
double timeStamp = audioEvent.getTimeStamp();
float pitch = pitchDetectionResult.getPitch();
float probability = pitchDetectionResult.getProbability();
double rms = audioEvent.getRMS() * 100;
String message = String.format("Pitch detected at %.2fs: %.2fHz (%.2f probability, RMS: %.5f)\n", timeStamp,pitch,probability,rms);
System.out.println(message);
}
}
}
329.wav文件從http://onlinetonegenerator.com/網站生成329Hz。 我不知道爲什麼結果音高始終是164.5Hz。我的代碼有問題嗎?
這是一個八度的誤差,這種實現尹基音檢測導致此問題,我從來沒有一次看到更深的尹代碼,但是從原來的紙一些步驟被遺忘了,我做了一個跟蹤Tarsos的AMDF代碼,你可以使用'PitchEstimationAlgorithm.AMDF'來測試他 – ederwander