我尝试使用网络上的一些资源来构建录音机,并以分贝为单位。我可以录制,但测量后得到的只有0.0dB。为什么?我究竟做错了什么?请帮忙。
Java
private static double mEMA = 0.0;
static final private double EMA_FILTER = 0.6;
private void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(Mfilename);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e("record_app", "prepare() failed");
}
recorder.start();
}
private void stopRecording() {
recorder.stop();
recorder.release();
recorder = null;
}
public double getAmplitude() {
if (recorder != null)
return (recorder.getMaxAmplitude());
else
return 0;
}
public double getAmplitudeEMA() {
double amp = getAmplitude();
mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
return mEMA;
}
在按钮上单击
measure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(),Double.toString((getAmplitudeEMA())) + " dB",
Toast.LENGTH_SHORT).show();
}
});