开发者

How to get the dB(or any kind of volume) level from a microphone in java?

开发者 https://www.devze.com 2023-02-28 22:41 出处:网络
i\'m really sorry if i\'m asking something already asked, but i looked everywhere and nothing came up.

i'm really sorry if i'm asking something already asked, but i looked everywhere and nothing came up.

i'm trying to do an on the fly read of the current volume of sound in the room using the java sound api. i noticed the controls i get from my microphone Mixer don't help with that and from what i've seen, people suggest r开发者_如何学Goeading a small chunk of sound from a TargetDataLine and checking volume with a Root Mean Square algorithm.

the actual question :) problem is, whenever i run rms on a sample (i'm using PCM_SIGNED for this, 44100Hz 16bit), i get values ranging between 20-30 when there's no background noise and up to 60 when i speak/yell/talk. (i tried having the line read from a buffer size of 100-44100 with smaller buffer sizes the rms is lower - but all over - quiet is around 10, and loud noise at around 30.)

thing is, when i play what i just recorded, you can hear everything perfectly, and no background noise.

tl;dr can anyone (please) tell me of a way to tell the volume from a byte array reading(of PCM SIGNED 44100Hz 16bit)?

thank you in advance for whoever answers!


See this reply for RMS.

0

精彩评论

暂无评论...
验证码 换一张
取 消