punarinta / react-native-sound-level

A package to dynamically measure sound input level in React Native applications. Can be used to help user to adjust microphone sensitivity.
MIT License
79 stars 45 forks source link

The values returned by the App #1

Open UdayKandpal opened 5 years ago

UdayKandpal commented 5 years ago

Hi, I want to try this app for finding the decibel value of the the sound/pressure at the MIC. Your app description says -160 is the silence level. So, how to convert the values from 0 to 200 dB. Can we place a 20 dB sound near MIC and expect a value of 20 in the value or the rawValue. Basically I want to understand what value is returned in the value and rawValue of your app. On Ubuntu placing MIC near sound takes the value to at most 0 and rawValue to at most 32767. On MAC OS, the value and rawValue remain the same and got to about 6 (positive value) at most. So I wonder it can show data in decibels say for sounds of 50 dB or 90 dB. Do respond at the earliest.

punarinta commented 5 years ago

Hi @UdayKandpal! That was done purely for normalizing data, so that it could be used for vizualisation, otherwise (see rawValue) the range would depend on the operating system.

As I understand that -160db notation is originally for sensitivity of the whole audio system at the moment, not for actual sound level, so there are definitely things like microphone autoadjustment playing role, hence those possible sensitivity issues. Check that you disable this stuff everywhere.

Conversion from [-160;0] to [0;160] can be done by simply adding 160, I think this is correct. Stretching the range to 200dB feels wrong, because that scale is logarithmic.

rawValue comes directly from the operating system, so you may use it to get more precise values if you know how your mic/amplification works.

UdayKandpal commented 5 years ago

Hi @punarinta

As I analysed your code, I found that rawValue will be same as value on MacOs.

However, I think adding 160 might not work as value given by MacOS without any noise near microphone is -50 (that would be 110dB if we convert by adding 160), whereas it turns towards 0 or 5 (that is around 160-165 decibel which is wrong value) when song is played near MIC through earphone. On Android you have used 20 log(amplitude/32767) as formula for decibel. However we only get negative values as amplitude will be always smaller than equal to 32767 i.e. will only reach 0 on android at max.

This does not give us the value required in the decibel. Could you guide us through getting the actual decibel value.

punarinta commented 5 years ago

@UdayKandpal values can sometimes get over zero because some OS's allow extra amplification. See for example a screenshot of how mic level management looks like in my Ubuntu: untitled That small white pin is a 0dB level as I understand it.

Or a similar thing in the settings screenshot from 2018-12-10 12-07-15

The level you get in the library is a product of your input level and your amplification level. Unfortunately I don't know how operating systems produce the final result, but I believe if you fix the amplification on let's say 100% (0dB) level then it should work in a similar way everywhere.

ncstc1 commented 1 year ago

Regarding the current value on android, I think there is a typo: Math.log is used instead of Math.log10.

After the change, the values (and their variations) are more comparable to those retrieved in the same conditions on iOS (the comparison is tricky due to calibration or hardware differences but at least the range is comparable).

For example a quiet environment is around -45 (pseudo dBFS?).

What transformations do you apply to have more comparable values or use different units?

amitkajwani-simformsolutions commented 8 months ago

any update on this @ncstc1 ?

ncstc1 commented 8 months ago

I only made the patch I mentioned above (use log10 instead of log in RNSoundLevelModule.java).

Did you make more changes on your side?