Measuring a bullet speed android app by using the microphone

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jun 7, 2018 1:28:07 PM via Website

I get stumbled at the part when i need to measure the time between the first and second "bang" (first sound being the bullet fired and the second the sound made by hiting the target). Because after i get the time took the bullet to reach the target i can calculate the speed by the well known formula : speed = distance/time. Please, some help ! Thanks !

This is the part of code where i lost all hope:

private long startT, endT, diffT;

public void updateTv() {
int dB = (int) soundDb(0.1);
mStatusView.setText(Integer.toString((dB)) + " dB");

//double elapsedTime = mTimer.getElapsedTime();
//Log.d("soundrecorder", "Elapsed time is : " + elapsedTime);

try {
if(dB > 100 ) {

startT = System.currentTimeMillis();
//Thread.sleep(1);
}

if(dB > 100) {

endT = System.currentTimeMillis();
//Thread.sleep(1);

}

diffT = endT - startT;

} catch (Exception e) {
System.err.println("error ..");
}

Log.d("soundrecorder", "Difference is : " + diffT);
//diffT = 0;

}

public double getAmplitude() {
if (mRecorder != null) {
return (mRecorder.getMaxAmplitude());
} else return 0;
}

public double soundDb(double ampl) {
return 20 * Math.log10(getAmplitude() / ampl);
}

public void threadStart() {
if (runner == null) {
runner = new Thread() {
public void run() {
while (runner != null) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
System.out.println(e);
}
mHandler.post(updater);
}
}
};
runner.start();
Log.d("soundrecorder", "start runner()");
} else {
if (!interrupted()) {
runner.interrupt();
}
}
}

— modified on Jun 7, 2018 1:39:48 PM

Be the first to answer

Recommended articles