Android PCM Bytes

前端 未结 5 961
无人共我
无人共我 2020-12-28 21:30

I am using the AudioRecord class to analize raw pcm bytes as it comes in the mic.

So thats working nicely. Now i need convert the pcm bytes into decibel.

I h

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 22:13

    Disclaimer: I know little about Android.

    Your device is probably recording in mono at 44,100 samples per second (maybe less) using two bytes per sample. So your first step is to combine pairs of bytes in your original data into two-byte integers (I don't know how this is done in Android).

    You can then compute the decibel value (relative to the peak) of each sample by first taking the normalized absolute value of the sample and passing it to your Db function:

    float Db = 20 * log10(ABS(sampleVal) / 32768)
    

    A value near the peak (e.g. +32767 or -32768) will have a Db value near 0. A value of 3277 (0.1) will have a Db value of -20; a value of 327 (.01) will have a Db value of -40 etc.

提交回复
热议问题