I am using this code to record the current sound. I need now some processing to detect the beat from music. I want a LED go on/off according the incoming music. I think BeatDetect is an useful library for my project, however I cannot find a good example. Can anyone give me an easy example to use? Or a reference?
public void start() {
initializeMediaRecorder();
handler.postDelayed(new Runnable() {
@Override
public void run() {
notifySample(getAmplitude());
handler.postDelayed(this, 150);
}
}, 150);
}
public void stop() {
handler.removeCallbacksAndMessages(null);
if (mediaRecorder != null) {
mediaRecorder.stop();
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder = null;
}
}
private double getAmplitude() {
if (mediaRecorder != null) {
return mediaRecorder.getMaxAmplitude();
} else {
return 0;
}
}
private void initializeMediaRecorder(){
try {
if(mediaRecorder == null) {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile("/dev/null");
mediaRecorder.prepare();
mediaRecorder.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}