Check volume level with AudioRecorder

brelto85

Active Member
Licensed User
Longtime User
Hi,

I'm testing my application in some devices, and i' ve notice that the follow code, does not work for all:

B4X:
...
wLevelAudio = mAudioRecorder.AudioMaxAmplitude / 2700
If wLevelAudio > 2.5 Then    
        mVolumeOk = False
Else
   mVolumeOk = True
End If    
...

In my device (HTC ONE S) the threshold of 2.5 is acceptable, while on other devices that i tested (eg. HTC wildfire, Galaxy Nexus), the threshold seems to be too low while testing at the same time with my.

my goal is to give a warning if the volume of environment is too high

thanks
Alberto
 

stevel05

Expert
Licensed User
Longtime User
Yes, each device can be different. you'll probably need some sort of calibration routine to make it useful across more devices.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could perhaps play a sound from the device whilst monitoring the volume and provide a method, maybe visual feedback and a slider, to alter the divisor until a target is reached.
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
...or i think in percentage...

If i have the value of "AudioMaxAmplitude" (which varies for each phone), i can calculate the percentage of the value of the environment
 
Last edited:
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
Why for get the level audio, is necessary to divide to 2700?

wLevelAudio = mAudioRecorder.AudioMaxAmplitude / 2700

mAudioRecorder has also the AudioSourceMax property (double). For my phone is 7.0

If i scream into the microphone, the level audio is greater than 12

How to calculate the percentage of the level audio?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I'm not sure that the Maximum value of AudioMaxAmplitude" will vary by phone, just the way it is reported. So the same volume could produce different values on different phones depending on the hardware. It's something you'll need to test.
 
Upvote 0

brelto85

Active Member
Licensed User
Longtime User
ok, but suppose that the AudioMaxAmplitude returns 10 and the AudioSourceMax is 100, the percentage is 10%

If in another phone, the AudioMaxAmplitude returns 100 and the AudioSourceMax is 1000, the percentage is the same (10%)

the problem is that in my test, the AudioSourceMax is smaller than AudioMaxAmplitude
 
Upvote 0
Top