private class measureSnoreAudio extends AsyncTask<String,String,String> { @OverrIDe protected String doInBackground(String... params) { Log.d(TAG,"Creating the buffer of size " + BUFFER_SIZE); byte[] buffer = new byte[BUFFER_SIZE]; Log.d(TAG,"Creating the AudioRecord"); recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,RECORDING_RATE,CHANNEL,FORMAT,BUFFER_SIZE * 10); Log.d(TAG,"AudioRecord recording..."); recorder.startRecording(); while (isRecordingSnore) { // read the data into the buffer int read = recorder.read(buffer,buffer.length); int amplitude = (buffer[0] & 0xff) << 8 | buffer[1]; // Determine amplitude double amplitudeDb = 20 * Math .log10(Math.abs(amplitude) / 32768); String dbString = String.valueOf(amplitudeDb); Log.d("Snore DB","dB " + dbString); //TextVIEw textAmplitude = (TextVIEw) findVIEwByID(R.ID.tvAmplitude); //textAmplitude.setText(dbString); } Log.d(TAG,"AudioRecord finished recording"); return null; }}解决方法
double amplitudeDb = 20 * Math.log10(Math.abs(amplitude) / 32768);
我想问题可能来自Math.abs(幅度)/ 32768,幅度是整数,所以Math.abs(幅度)也将返回整数,因为Math.abs(幅度)小于32768(也许我不正确,字节最大为2 ^ 7 – 1,这里幅度可以大于32768吗?).所以Math.abs(幅度)/ 32768等于0.Log10(0)是-Infinity,我在Eclipse中用Java项目测试过.
你可以改为
double amplitudeDb = 20 * Math.log10((double)Math.abs(amplitude) / 32768);总结
以上是内存溢出为你收集整理的android – 来自AudioRecord的Amplitude全部内容,希望文章能够帮你解决android – 来自AudioRecord的Amplitude所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)