use of be.tarsos.dsp.pitch.PitchDetectionHandler in project 490 by pauleibye.
the class FeatureExtractor method YINPitch.
/*
Generates YIN human voice pitch tracking feature
http://recherche.ircam.fr/equipes/pcm/cheveign/ps/2002_JASA_YIN_proof.pdf
@return: 2 numerical values separated by a comma returned as a string, returns YINPitch value and its weight
*/
public String YINPitch(AudioDispatcher audioDispatcher) throws IOException, UnsupportedAudioFileException {
String output = "";
PitchDetectionHandler handler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
// double rms = audioEvent.getRMS() * 100;
if (pitchDetectionResult.isPitched()) {
// System.out.println("pitch " + pitch + " probability " + probability + " rms " + rms);
YINprobability += pitchDetectionResult.getProbability();
YINcount++;
}
}
};
PitchProcessor pp = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.YIN, sampleRate, audioBufferSize, handler);
audioDispatcher.addAudioProcessor(pp);
audioDispatcher.run();
// output = output + Float.toString(YINprobability);
output = output + Integer.toString(YINcount) + "," + Float.toString(YINprobability / YINcount);
YINcount = 0;
YINprobability = 0;
// audioDispatcher.removeAudioProcessor(pp);
return output;
}
use of be.tarsos.dsp.pitch.PitchDetectionHandler in project PICKSARI by HyunJunYANG.
the class PitchDetect method detect.
// 음역대를 측정하는 함수
public void detect() {
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
// 0은 초기 1은 성공 2는 실패
pitchSuccess = 0;
Log.d(LOG_TAG, "start");
// PitchDetect Thread
PitchDetectionHandler pdh = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult result, AudioEvent e) {
final float pitchInHz = result.getPitch();
runOnUiThread(new Runnable() {
@SuppressLint("ResourceType")
@Override
public void run() {
// 음이 기준보다 높으면 이미지바꾸고 sleep
if (!thread.isInterrupted()) {
if (pitchInHz > hz[hzIndex]) {
Log.d(LOG_TAG, String.valueOf(hz[hzIndex]));
pitchText.setText(scale[scaleIndex]);
pitch = pitchInHz;
// 인덱스를 늘린다
hzIndex = hzIndex + 1;
scaleIndex = scaleIndex + 1;
pitchSuccess = 1;
// 타이머를 죽인다. 성공하면 타이머 리셋해야하기 때문
timer.cancel();
manPicture.setImageResource(R.drawable.man_3);
// PostDelay 그림을 바꾸기 위한 딜레이
try {
Log.d(LOG_TAG, "ThreadSleepStart");
// thread.sleep(1000);
handler.postDelayed(runnable, 1000);
// 타이머 리셋
detectTime();
// thread.interrupt();
// Log.d(LOG_TAG, "ThreadSleepInterrupted");
Log.d(LOG_TAG, "ThreadSleepRestart");
} catch (Exception e) {
e.printStackTrace();
}
} else {
// 음이 기준보다 낮으면
// Log.d(LOG_TAG, "ThreadSleep Pitch is low.");
pitchSuccess = 2;
}
}
}
});
}
};
// 선언
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
thread = new Thread(dispatcher, "Audio Dispatcher");
thread.start();
}
use of be.tarsos.dsp.pitch.PitchDetectionHandler in project PICKSARI by HyunJunYANG.
the class TarsosDSP method detect.
public boolean detect() {
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
Log.d("StartaudioDetect", "start");
PitchDetectionHandler pdh = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult result, AudioEvent e) {
final float pitchInHz = result.getPitch();
thread = new Thread(new Runnable() {
@Override
public void run() {
if (pitchInHz > pitch) {
Log.d("StartAudioDetect", "start2");
pitch = pitchInHz;
bool = true;
// sendMessage(pitch);
/*
text = (TextView) findViewById(R.id.textView1);
text.setText("" + pitchInHz);
pitchChange();
*/
} else {
bool = false;
}
}
});
}
};
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
thread = new Thread(dispatcher, "Audio Dispatcher");
thread.start();
return bool;
}
Aggregations