问题描述
我已创建一个获取getMaxampitude的应用程序,然后将其转换为分贝,但我只获得30dB的范围.
Android手机是否只有30dB的范围,或者是我的代码中的问题?
public class getMaxAmpitude extends AsyncTask<Void, Float, Void>{ String dB = ""; int ampitude; float db; @Override public Void doInBackground(Void... params) { while(rec == true){ try{ Thread.sleep(250); }catch(InterruptedException e){ e.printStackTrace(); } ampitude = recorder.getMaxAmplitude(); db =(float) (20 * Math.log10(ampitude/700.0)); publishProgress(db); } return null; } public void onProgressUpdate(Float... progress){ //database.addSoundData(dB); dB = (progress[0].toString());
推荐答案
分贝刻度始终是相对于某些东西的测量 - 以及数字音频的情况下,某些东西通常是样本能够保持的最大值.这是1.0用于样品的浮点表示和用于签名的16位样本的32767.计算的DB值为负,0dB是剪辑.
不知道什么是recorder是一个例子,我将假设它是Android的MediaRecorder - 它使用符号16位INTS.
在这种情况下正确的等式因此是:
db = 20.0 * log10(peakAmplitude/32767.0)
您在上面使用的等式,仅将结果偏置为eqivelant:
db = 20.0 * log10(peakAmplitude) - 20.0 * log10(700)
=20.0*log10(peakAmplitude) - ~56.9
如果您正在录制板载麦克风和启用自动增益控制,则为30dB的动态范围令人惊讶的是,除非您正在接受禁用它的活动步骤,否则
问题描述
I have created a application that get the getMaxAmpitude and then converts it to decibels but i only get a range of 30dB.
Does an android phone only have a range of 30dB or is it a problem in my code?
public class getMaxAmpitude extends AsyncTask<Void, Float, Void>{ String dB = ""; int ampitude; float db; @Override public Void doInBackground(Void... params) { while(rec == true){ try{ Thread.sleep(250); }catch(InterruptedException e){ e.printStackTrace(); } ampitude = recorder.getMaxAmplitude(); db =(float) (20 * Math.log10(ampitude/700.0)); publishProgress(db); } return null; } public void onProgressUpdate(Float... progress){ //database.addSoundData(dB); dB = (progress[0].toString());
推荐答案
The decibel scale is always a measure relative to something - and in the case of digital audio, that something is customarily the largest value that a sample is capable of holding. This is either 1.0 for floating point representations of samples and 32767 for signed 16-bit samples. Calculated dB values are negative, with 0dB being clip.
Without knowledge of what precisely what recorder is an instance of, I will assume it's Android's MediaRecorder - which uses signed 16-bit ints.
The correct equation in this case would therefore be:
db = 20.0 * log10(peakAmplitude/32767.0)
The equation you've used above however, merely biases the results as it's eqivelant to:
db = 20.0 * log10(peakAmplitude) - 20.0 * log10(700)
=20.0*log10(peakAmplitude) - ~56.9
The dynamic range figure of 30dB might not be surprising if you're recording the onboard microphone and automatic gain control is enabled - as it will be unless you've taken active steps to disable it.