0

As a part of a larger aplication I am currently working on a decibel meters that takes the average sound level of a 10 second timespan.

To achieve this I made a CountDownTimer of 10 000 miliseconds that ticks every 100 miliseconds.

In each onTick event I update the textfield that shows the time left, and I also update the realtime decibel value.

My issue however is converting the maximum amplitude to decibels. I found the "power_db = 20 * log10(amp / amp_ref);" formula here on StackOverflow and I understand how it works, but I seem to always end up with a negative decibel value.

I understand that this is because of a wrong amp_ref value, but I am absolutely stumped on which one I should use. I found alot of different values on the web and none seem to do the trick.

Does anyone have any idea which reference amplitude I should use to get the correct decibel reading on my meter? The phone I am testing this on is a Google Nexus 5. For now it would be good enough if it only was a really accurate value on this phone if thats of any help.

The code I have in my onTick event is the following (I removed the formula for now since it seemed to be wrong anyways):

public void onTick(long ms) {

                meetBtn.setText(String.valueOf((ms/1000)+1));
                amplitude = mRecorder.getMaxAmplitude();

                decibelView.setText(String.valueOf(amplitude));
            }

If anyone has any tips or needs more information, please let me know!

Thanks in advance! :)

Cingen
  • 21
  • 2

1 Answers1

0

Negative decibels are fine, because it's a relative measure anyway. In fact it's a common practice to take the maximum possible amplitude as a reference point and as a result have decibels go from 0 down to negative space. Pro systems usually indicate positive decibels as an overload when clipping and distortions of sound may occur.

So for example if your amplitude range is 0 to 1 (an accepted float-PCM standard), then your amp_ref would be 1 and your decibel values will go from some negative value that depends on the bitness resolution of your source (e.g. -186dB for 32 bit, or -90dB for 16-bit source), up to 0dB. This is normal!

Edit: actually, your float-PCM amplitude range is -1 to 1, but decibel calculation "drops" the minus sign and gives the same result for both negative and positive amplitudes.

mojuba
  • 11,842
  • 9
  • 51
  • 72