Decibels in android

烈酒焚心 提交于 2019-12-19 04:38:02

问题


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());

回答1:


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.



来源:https://stackoverflow.com/questions/16072185/decibels-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!