我尝试使用网络上的一些资源来构建录音机并以分贝为单位进行测量。我能够记录,但在测量时,我得到的只是 0.0dB。为什么?我究竟做错了什么?请帮忙。
爪哇
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();
}
});