I am trying to know the gain / decibels and other possible parameters from wav audio file. But Clip.getLevel() method is always returning gain in -0.1 value.
public void prepareAudio() {
try {
Line.Info linfo = new Line.Info(Clip.class);
Line line = AudioSystem.getLine(linfo);
clip = (Clip) line;
clip.addLineListener(this);
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
clip.open(ais);
clip.start();
do {
Thread.sleep(300);
} while (clip.isActive());
clip.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void update(LineEvent event) {
LineEvent.Type type = event.getType();
if (type == LineEvent.Type.OPEN) {
System.out.println("OPEN");
} else if (type == LineEvent.Type.CLOSE) {
System.out.println("CLOSE");
} else if (type == LineEvent.Type.START) {
System.out.println("START");
while (clip.isActive()) {
System.out.println(clip.getLevel()); // get gain
}
} else if (type == LineEvent.Type.STOP) {
System.out.println("STOP");
clip.close();
}
}
}