分贝机器人 [英] Decibels in android
问题描述
我已经创建了一个让getMaxAmpitude一个应用程序,然后将其转换为分贝,但我只得到了一系列30分贝的。
请问Android手机只能有一个范围30分贝,或者是它在我的code的一个问题?
公共类getMaxAmpitude扩展的AsyncTask<太虚,浮法,太虚> {
列DB =;
INT ampitude;
浮动分贝;
@覆盖
公共无效doInBackground(虚空...... PARAMS){
而(REC ==真){
尝试{
视频下载(250);
}赶上(InterruptedException异常E){
e.printStackTrace();
}
ampitude = recorder.getMaxAmplitude();
DB =(浮点)(20 * Math.log10(ampitude / 700.0));
publishProgress(DB);
}
返回null;
}
公共无效onProgressUpdate(浮...进度){
//database.addSoundData(dB);
分贝=(进展[0]的ToString());
分贝标度总是相对的东西的措施 - 在数字音频的情况下,什么是习惯上的最大值,一个样品能够保持。这要么是 1.0
浮动样本点再presentations和 32767
有符号16位采样。计算分贝值为负,提供0dB是剪辑。
如果没有什么precisely什么记录
是一个实例,我会以为这是Android的 MediaRecorder
知识 - 它采用16位有符号整数。
正确的公式在这种情况下,因此将是:
DB = 20.0 * LOG10(peakAmplitude / 32767.0)
您但是上面所使用的公式,仅仅是偏见的结果,因为它是eqivelant为:
DB = 20.0 * LOG10(peakAmplitude) - 20.0 * LOG10(700)
= 20.0 * LOG10(peakAmplitude) - 〜56.9
30分贝的动态范围的数字可能并不奇怪,如果你正在录制自带的话筒和自动增益控制已启用 - 因为这将是除非你已经采取了积极的步骤来禁用它。
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.
这篇关于分贝机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!