TargetDataLine getTargetDataLine(AudioFormat format, int bufferSize) { TargetDataLine line = null; DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); if (AudioSystem.isLineSupported(info)) { try { if (inputMixer == null) { line = (TargetDataLine) AudioSystem.getLine(info); } else { line = (TargetDataLine) inputMixer.getLine(info); } line.open(format, bufferSize * format.getFrameSize()); debug( "TargetDataLine buffer size is " + line.getBufferSize() + "\n" + "TargetDataLine format is " + line.getFormat().toString() + "\n" + "TargetDataLine info is " + line.getLineInfo().toString()); } catch (Exception e) { error("Error acquiring TargetDataLine: " + e.getMessage()); } } else { error("Unable to return a TargetDataLine: unsupported format - " + format.toString()); } return line; }
TargetDataLineMeter(TargetDataLine line) { super(new ByteArrayInputStream(new byte[0]), line.getFormat(), AudioSystem.NOT_SPECIFIED); this.line = line; }