-1

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();
    }
}

}

1 Answers1

0

The method getLevel() gives you the (linear) gain of the DataLine, which is used for playback, not some property of the audio file. As of now, there is no built-in method in JavaSE to determine such a thing. In order to measure what's in the file, consider studying ReplayGain or EBU R128. A free and open implementation of EBU R128 is libebur128, but it's not in Java.

Hendrik
  • 5,085
  • 24
  • 56