2
給大家晚上好!用手機測量分貝
我有以下麻煩:我試着測量使用我的手機麥克風分貝(的聲音),但不知道爲什麼它不工作!任何建議??謝謝你的幫助!
程序是這樣的:
`package com.dani;
import java.io.IOException;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class Pruebita2 extends Activity {
TextView TextView;
StringBuilder builder=new StringBuilder();
MediaRecorder mRecorder;
double powerDb;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pruebita2);
TextView=new TextView(this);
setContentView(TextView);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
try {
mRecorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mRecorder.start();
}
public double getAmplitude() {
if (mRecorder != null)
return (mRecorder.getMaxAmplitude());
else
return 0;
}
powerDb = 20 * log10(getAmplitude()/referenceAmp);//obtain the DECIBELS
}`
[測量分貝]的可能重複(http://stackoverflow.com/questions/15690116/measuring-分貝)。請不要轉發。 –
我想從我的手機麥克風得到分貝,我發現該程序如果你知道另一個程序更好,我會很高興!! ahahahahha –
好的,對不起,我不知道我在這裏新的 –