How to set volume in decibels using my android mobile application?

三世轮回 提交于 2019-12-06 15:35:05

For digital signal dB is typically expressed relative to the full scale amplitude.

1.0 == 0dB
0.5 == -6dB
0.25 == -12dB
...
0.0  == -inf dB

and so on.

To convert the amplitude to dB: dB = 20*log10(ampl)

To convert from dB to amplitude: ampl = 10 ^ (dB/20)

The simplest way to then achieve your goal is to store your values left and right in dB, initializing them both to zero. Your posted code can stay exactly the same except you wouldn't allow the values to be incremented above zero. Then convert the values to linear as you are calling setVolume. e.g. mp.setVolume(Math.pow(10,left/20), Math.pow(10,right/20))

You can't set an absolute decibel rating programatically. Such a concept doesn't actually exist with audio. That would require knowing the physical configuration the speakers, room acoustings, how close to the user's ear, and measuring the samples from the sound file.

MediaPlayer.setVolume sets attenuation - not loudness or volume.

The volume specified by MediaPlayer.setVolume is relative to the hardware volume setting. You can't make the media source "louder" than it really is without adjusting the device volume. And with the MediaPlayer by itself, you don't really know how "loud" the user is hearing anything.

At the highest setting: player.setvolume(1.0, 1.0) - This will set the volume on the output stream to match the global volume on the device. This is the default.

And as you might have guessed - player.setvolume(0.0, 0.0) - is absolute silence.

If you want to set global volume, you can use AudioManager.setStreamVolume

Considering that the device and Android volume buttons work perfectly well without the developer having to handle the button presses, I'm not sure why you would want to override default behavior.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!