So, my main problem here is I don't yet know what the actual problem is. I have a two microphones, and when using either one, my program that detects the volume in db will only detect 90 max. I'm not sure if this is a limit on the microphone, or if it's the program, but it clearly shows that it's 90db and it won't go any higher, regardless of whether or not it is. If this proves helpful, the microphones I have are a cheap logitech webcam and a blue yeti microphone (not cheap).
In the event that it is the microphone, why exactly does this happen, and if not, well then here's the code I have for figuring out what the db level is:
AudioFormat audioFormat = getAudioFormat();
TargetDataLine targetDataLine;
try {
targetDataLine = (TargetDataLine) AudioSystem.getTargetDataLine(audioFormat);
targetDataLine.open();
targetDataLine.start();
byte [] buffer = new byte[2000];
while (true) {
int bytesRead = targetDataLine.read(buffer,0,buffer.length);
if (bytesRead >= 0) {
max = (int) (buffer[0] + (buffer[1] << 8));
for (int p=2;p<bytesRead-1;p+=2) {
int thisValue = (int)(buffer[p] + (buffer[p+1] << 8));
if (thisValue > max) max = thisValue;
}
}
}
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
currentDecibelLabel.setText(Integer.toString((int)(20 * Math.log10(max)))));
Any ideas? Thanks!!
EDIT: Just so you know, 'max' is a global
int
.