android - 读取的AudioRecord返回奇怪的值

标签 android audio android-sensors android-audiorecord

我正在尝试为Android平台构建某种声级计。 (我使用的是HTC Wildfire)我为此目的使用了AudioRecord类,但是似乎
从其“读取”返回的值是不合理的。

这就是我创建AudioRecord对象的方式:

int minBufferSize = 
         AudioRecord.getMinBufferSize(sampleRateInHz,
                                      android.media.AudioFormat.CHANNEL_IN_MONO,
                                      android.media.AudioFormat.ENCODING_PCM_16BIT);

audioRecored = new AudioRecord( MediaRecorder.AudioSource.MIC,          
                                44100, 
                                android.media.AudioFormat.CHANNEL_IN_MONO,
                                android.media.AudioFormat.ENCODING_PCM_16BIT,
                                minBufferSize );

这是我尝试从中读取数据的方式:
    short[] audioData = new short[bufferSize];
    int offset =0;
    int shortRead = 0;
    int sampleToReadPerGet = 1000;//some value in order to avoid momentaraly nosies.

    //start tapping into the microphone
    audioRecored.startRecording();

   //start reading from the microphone to an internal buffer - chuck by chunk
   while (offset < sampleToReadPerGet)
   {
            shortRead = audioRecored.read(audioData, offset ,sampleToReadPerGet - offset);
            offset += shortRead;
   }

   //stop tapping into the microphone
   audioRecored.stop();

    //average the buffer
    int averageSoundLevel = 0;
    for (int i = 0 ; i < sampleToReadPerGet ; i++)
    {
        averageSoundLevel += audioData[i];          
    }
    averageSoundLevel /= sampleToReadPerGet;      

这些值是多少?他们是分贝吗?

编辑:
值从-200到3000。
shortRead的值为sampleToReadPerGet(1000)。

最佳答案

不确定原始输出或平均值是指什么“那些值”,但是原始输出是瞬时振幅水平。重要的是要意识到这些值没有特别地引用任何东西。也就是说,仅仅因为您正在阅读20,并不能告诉您20。

取这些值的平均值没有任何意义,因为这些值在零上下波动。做足够长的时间,您将得到零。

取平方的平均值,然后找到平均值的平方根可能是有意义的。这称为RMS。但是,如果没有固定的缓冲区大小可以平均,那么这充其量是危险的。

要测量dB,必须使用公式dB = 20 log_10(| A | / A_r),其中A是幅度,A_r是引用幅度-显然,您必须确定要引用的内容(可以校准HTC ,或根据最高水平或类似标准进行衡量)。

关于android - 读取的AudioRecord返回奇怪的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11064349/

相关文章:

java - Android 上的蓝牙延迟补偿

java - CalledFromWrongThreadException 在 Android 上执行 JUnit 测试

html - 2013年常见的html5音频格式?

android - 在状态 8 中调用 MediaPlayer 暂停

android - 用安卓手机在空中画画

java - 在导航中实现左侧滑动菜单

android - 长时间不活动后在 swapcursor 上获取空指针

android - 有什么方法可以替换或静音 android 中的相机快门声音?

java - 如何在 Android 内部保存流式传感器数据?