Hey guys, I'm quite new to Java and wanted to access the Volume of the Mic-Sound for a
simple Audio-Visualizer. I got everything working except for my AudioInput class.
It doesn't throw exceptions or errors but the line.getlevel returns constantly -1.
If anyone has experience with that and could tell me what is wrong, it would be awesome.
My AudioInput class:
simple Audio-Visualizer. I got everything working except for my AudioInput class.
It doesn't throw exceptions or errors but the line.getlevel returns constantly -1.
If anyone has experience with that and could tell me what is wrong, it would be awesome.
My AudioInput class:
Java:
package audio;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
public class audioInput {
float sampleRate = 48000;
int sampleSizeinBits = 16;
int channels = 1;
boolean signed = true;
boolean bigE = true;
AudioFormat format;
DataLine.Info info;
DataLine line;
public audioInput(){
format = new AudioFormat(sampleRate, sampleSizeinBits, channels, signed, bigE);
info = new DataLine.Info(TargetDataLine.class, format);
try {
line = (TargetDataLine) AudioSystem.getLine(info);
} catch (LineUnavailableException e) {
e.printStackTrace();
}
try {
line.open();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
line.start();
}
public float getVol(){
return line.getLevel();
}
}