Audio output level in a form that can be converted to decibels

I need to find a way to get the current audio output level, when the phone makes noise in the headphones, this value will be converted to decibel level. The Android API has no way to access a constant volume level other than the seemingly arbitrary volume setting level, but I see no way to convert it to a standard decibel level or volume measurement. I saw some ways to use a microphone for this, but this will not work very well with headsets.

Does anyone know a way to measure either the maximum possible decibel (or some standard) output level for comparison, or the possible direction of voltage to the headset?

Help is appreciated.

+3
android audio volume
source share
2 answers

Keep in mind that there are many different meanings of the word "deciBel". This is a means of representing a certain quantity (such as intensity / power / volume) relative to a control point. For audio signals inside the equipment or in the audio application, there is a peak level of 0 dB. When sound is emitted from the speaker, the perceived volume is measured as the Sound Pressure Level , often described as “dB (SPL)” (or weighted options such as dBA). When you see value tables, such as 100 dB rock concerts, then this is described by SPL. This measurement in itself is relative to the reference level.

So what will be available in the API is the audio data buffer, from which you can easily get the sound level in terms of the raw signal (which has a maximum of 0 dB). However, you cannot easily convert this to physical volume, because it will be hardware dependent. This will differ between one phone model and the next, and will depend on the headphones. The only way to do this is to calibrate the phone by measuring with the SPL indicator, but then it will give you a result that will only give reasonable results on this particular phone.

+5
source share

I do it like this:

SLmillibel gain_to_attenuation(float volume) { SLmillibel volume_mb; if(volume>=1.0f) volume_mb=SL_MILLIBEL_MAX; else if(volume<=0.02f) volume_mb=SL_MILLIBEL_MIN; else { volume_mb=M_LN2/log(1.0f/(1.0f-volume))*-1000.0f; if(volume_mb>0) volume_mb=SL_MILLIBEL_MIN; } return volume_mb; } 
0
source share

All Articles